- Filter collaborators from export.

This commit is contained in:
Paulo Gustavo Veiga 2012-09-15 11:35:53 -03:00
parent e0a67fe1d7
commit 15e03c690f
9 changed files with 118 additions and 44 deletions

View File

@ -38,7 +38,7 @@ public interface MindmapManager {
List<Mindmap> getAllMindmaps(); List<Mindmap> getAllMindmaps();
@Nullable @NotNull
Mindmap getMindmapById(int mindmapId); Mindmap getMindmapById(int mindmapId);
Mindmap getMindmapByTitle(final String name, final User user); Mindmap getMindmapByTitle(final String name, final User user);

View File

@ -164,8 +164,9 @@ public class MindmapManagerImpl
} }
@Override @Override
public Mindmap getMindmapById(int mindmapId) { @NotNull
return getHibernateTemplate().get(Mindmap.class, mindmapId); public Mindmap getMindmapById(int id) {
return getHibernateTemplate().get(Mindmap.class, id);
} }
@Override @Override

View File

@ -228,15 +228,24 @@ public class Mindmap {
@NotNull @NotNull
public CollaborationProperties findCollaborationProperties(@NotNull Collaborator collaborator) throws WiseMappingException { public CollaborationProperties findCollaborationProperties(@NotNull Collaborator collaborator) throws WiseMappingException {
return this.findCollaborationProperties(collaborator, true);
}
@Nullable
public CollaborationProperties findCollaborationProperties(@NotNull Collaborator collaborator, boolean forceCheck) throws WiseMappingException {
if (collaborator == null) { if (collaborator == null) {
throw new IllegalStateException("Collaborator can not be null"); throw new IllegalStateException("Collaborator can not be null");
} }
final Collaboration collaboration = this.findCollaboration(collaborator); final Collaboration collaboration = this.findCollaboration(collaborator);
if (collaboration == null) { CollaborationProperties result = null;
throw new AccessDeniedSecurityException("Collaborator " + collaborator.getEmail() + " could not access " + this.getId()); if (collaboration != null) {
result = collaboration.getCollaborationProperties();
} else {
if (forceCheck)
throw new AccessDeniedSecurityException("Collaborator " + collaborator.getEmail() + " could not access " + this.getId());
} }
return collaboration.getCollaborationProperties(); return result;
} }
public boolean isStarred(@NotNull Collaborator collaborator) { public boolean isStarred(@NotNull Collaborator collaborator) {
@ -264,7 +273,7 @@ public class Mindmap {
return result; return result;
} }
public boolean hasPermissions(@NotNull Collaborator collaborator, @NotNull CollaborationRole role) { public boolean hasPermissions(@Nullable Collaborator collaborator, @NotNull CollaborationRole role) {
boolean result = false; boolean result = false;
if (collaborator != null) { if (collaborator != null) {
final Collaboration collaboration = this.findCollaboration(collaborator); final Collaboration collaboration = this.findCollaboration(collaborator);

View File

@ -0,0 +1,51 @@
package com.wisemapping.rest.model;
import com.wisemapping.model.Collaborator;
import com.wisemapping.model.User;
import com.wisemapping.util.TimeUtils;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Calendar;
import java.util.Date;
@XmlRootElement(name = "collaborator")
@XmlAccessorType(XmlAccessType.PROPERTY)
@JsonAutoDetect(
fieldVisibility = JsonAutoDetect.Visibility.NONE,
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY)
public class RestCollaborator {
@JsonIgnore
private Collaborator collaborator;
public RestCollaborator(@NotNull Collaborator collaborator) {
this.collaborator = collaborator;
}
public String getCreationDate() {
return TimeUtils.toISO8601(collaborator.getCreationDate().getTime());
}
public void setCreationDate(Calendar creationDate) {
}
public String getEmail() {
return collaborator.getEmail();
}
public void setEmail(String email) {
}
}

View File

@ -3,6 +3,7 @@ package com.wisemapping.rest.model;
import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.*; import com.wisemapping.model.*;
import com.wisemapping.util.TimeUtils;
import org.codehaus.jackson.annotate.*; import org.codehaus.jackson.annotate.*;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -28,15 +29,9 @@ public class RestMindmap {
private Collaborator collaborator; private Collaborator collaborator;
@JsonIgnore @JsonIgnore
private Mindmap mindmap; private Mindmap mindmap;
@JsonIgnore @Nullable
static private SimpleDateFormat sdf;
private String properties; private String properties;
static {
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
}
public RestMindmap() throws WiseMappingException { public RestMindmap() throws WiseMappingException {
this(new Mindmap(), null); this(new Mindmap(), null);
@ -46,8 +41,10 @@ public class RestMindmap {
this.mindmap = mindmap; this.mindmap = mindmap;
this.collaborator = collaborator; this.collaborator = collaborator;
if (collaborator != null) { if (collaborator != null) {
final CollaborationProperties collaborationProperties = mindmap.findCollaborationProperties(collaborator); final CollaborationProperties collaborationProperties = mindmap.findCollaborationProperties(collaborator, false);
this.properties = collaborationProperties.getMindmapProperties(); if (collaborationProperties != null) {
this.properties = collaborationProperties.getMindmapProperties();
}
} }
} }
@ -56,7 +53,7 @@ public class RestMindmap {
final Calendar creationTime = mindmap.getCreationTime(); final Calendar creationTime = mindmap.getCreationTime();
String result = null; String result = null;
if (creationTime != null) { if (creationTime != null) {
result = this.toISO8601(creationTime.getTime()); result = TimeUtils.toISO8601(creationTime.getTime());
} }
return result; return result;
} }
@ -81,15 +78,21 @@ public class RestMindmap {
return mindmap.getCreator().getEmail(); return mindmap.getCreator().getEmail();
} }
public Collaborator getLastModifierUser() { public RestCollaborator getLastModifierUser() {
return mindmap.getLastEditor(); final User lastEditor = mindmap.getLastEditor();
RestCollaborator result = null;
if (lastEditor != null && mindmap.hasPermissions(collaborator, CollaborationRole.EDITOR)) {
result = new RestCollaborator(lastEditor);
}
return result;
} }
public String getLastModificationTime() { public String getLastModificationTime() {
final Calendar date = mindmap.getLastModificationTime(); final Calendar date = mindmap.getLastModificationTime();
String result = null; String result = null;
if (date != null) { if (date != null) {
result = toISO8601(date.getTime()); result = TimeUtils.toISO8601(date.getTime());
} }
return result; return result;
} }
@ -153,6 +156,7 @@ public class RestMindmap {
public void setLastModifierUser(String lastModifierUser) { public void setLastModifierUser(String lastModifierUser) {
} }
@Nullable
public String getProperties() { public String getProperties() {
return properties; return properties;
} }
@ -175,12 +179,4 @@ public class RestMindmap {
public Mindmap getDelegated() { public Mindmap getDelegated() {
return this.mindmap; return this.mindmap;
} }
private String toISO8601(@Nullable Date date) {
String result = "";
if (date != null) {
result = sdf.format(date) + "Z";
}
return result;
}
} }

View File

@ -6,6 +6,7 @@ import com.wisemapping.model.Collaborator;
import com.wisemapping.model.Mindmap; import com.wisemapping.model.Mindmap;
import com.wisemapping.model.User; import com.wisemapping.model.User;
import com.wisemapping.security.Utils; import com.wisemapping.security.Utils;
import com.wisemapping.util.TimeUtils;
import org.codehaus.jackson.annotate.*; import org.codehaus.jackson.annotate.*;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -32,13 +33,6 @@ public class RestMindmapInfo {
@JsonIgnore @JsonIgnore
private Mindmap mindmap; private Mindmap mindmap;
private Collaborator collaborator; private Collaborator collaborator;
@JsonIgnore
static private SimpleDateFormat sdf;
static {
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
}
public RestMindmapInfo() { public RestMindmapInfo() {
this(new Mindmap(), null); this(new Mindmap(), null);
@ -51,7 +45,7 @@ public class RestMindmapInfo {
} }
public String getCreationTime() { public String getCreationTime() {
return this.toISO8601(mindmap.getCreationTime().getTime()); return TimeUtils.toISO8601(mindmap.getCreationTime().getTime());
} }
public String getDescription() { public String getDescription() {
@ -94,7 +88,7 @@ public class RestMindmapInfo {
public String getLastModificationTime() { public String getLastModificationTime() {
final Calendar calendar = mindmap.getLastModificationTime(); final Calendar calendar = mindmap.getLastModificationTime();
return this.toISO8601(calendar.getTime()); return TimeUtils.toISO8601(calendar.getTime());
} }
public boolean isPublic() { public boolean isPublic() {
@ -138,8 +132,4 @@ public class RestMindmapInfo {
public Mindmap getDelegated() { public Mindmap getDelegated() {
return this.mindmap; return this.mindmap;
} }
private String toISO8601(@NotNull Date date) {
return sdf.format(date) + "Z";
}
} }

View File

@ -29,7 +29,8 @@ public interface MindmapService {
static final String TAG_SEPARATOR = " "; static final String TAG_SEPARATOR = " ";
Mindmap findMindmapById(int mindmapId); @NotNull
Mindmap findMindmapById(int id);
Mindmap getMindmapByTitle(String title, User user); Mindmap getMindmapByTitle(String title, User user);

View File

@ -79,8 +79,9 @@ public class MindmapServiceImpl
} }
@Override @Override
public Mindmap findMindmapById(int mindmapId) { @NotNull
return mindmapManager.getMindmapById(mindmapId); public Mindmap findMindmapById(int id) {
return mindmapManager.getMindmapById(id);
} }
@Override @Override

View File

@ -0,0 +1,25 @@
package com.wisemapping.util;
import org.jetbrains.annotations.Nullable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
final public class TimeUtils
{
private static SimpleDateFormat sdf;
static {
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
}
public static String toISO8601(@Nullable Date date) {
String result = "";
if (date != null) {
result = sdf.format(date) + "Z";
}
return result;
}
}