From 15e03c690fc75f3c2879b9734d6fc36bd71cced4 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 15 Sep 2012 11:35:53 -0300 Subject: [PATCH] - Filter collaborators from export. --- .../com/wisemapping/dao/MindmapManager.java | 2 +- .../wisemapping/dao/MindmapManagerImpl.java | 5 +- .../java/com/wisemapping/model/Mindmap.java | 17 +++++-- .../rest/model/RestCollaborator.java | 51 +++++++++++++++++++ .../wisemapping/rest/model/RestMindmap.java | 38 +++++++------- .../rest/model/RestMindmapInfo.java | 16 ++---- .../wisemapping/service/MindmapService.java | 3 +- .../service/MindmapServiceImpl.java | 5 +- .../java/com/wisemapping/util/TimeUtils.java | 25 +++++++++ 9 files changed, 118 insertions(+), 44 deletions(-) create mode 100644 wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaborator.java create mode 100644 wise-webapp/src/main/java/com/wisemapping/util/TimeUtils.java diff --git a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java index 1175a997..9ceeee48 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java @@ -38,7 +38,7 @@ public interface MindmapManager { List getAllMindmaps(); - @Nullable + @NotNull Mindmap getMindmapById(int mindmapId); Mindmap getMindmapByTitle(final String name, final User user); diff --git a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java index c29e2df3..f23a7038 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java @@ -164,8 +164,9 @@ public class MindmapManagerImpl } @Override - public Mindmap getMindmapById(int mindmapId) { - return getHibernateTemplate().get(Mindmap.class, mindmapId); + @NotNull + public Mindmap getMindmapById(int id) { + return getHibernateTemplate().get(Mindmap.class, id); } @Override diff --git a/wise-webapp/src/main/java/com/wisemapping/model/Mindmap.java b/wise-webapp/src/main/java/com/wisemapping/model/Mindmap.java index 74b387bc..2dd41384 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/Mindmap.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/Mindmap.java @@ -228,15 +228,24 @@ public class Mindmap { @NotNull 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) { throw new IllegalStateException("Collaborator can not be null"); } final Collaboration collaboration = this.findCollaboration(collaborator); - if (collaboration == null) { - throw new AccessDeniedSecurityException("Collaborator " + collaborator.getEmail() + " could not access " + this.getId()); + CollaborationProperties result = null; + 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) { @@ -264,7 +273,7 @@ public class Mindmap { return result; } - public boolean hasPermissions(@NotNull Collaborator collaborator, @NotNull CollaborationRole role) { + public boolean hasPermissions(@Nullable Collaborator collaborator, @NotNull CollaborationRole role) { boolean result = false; if (collaborator != null) { final Collaboration collaboration = this.findCollaboration(collaborator); diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaborator.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaborator.java new file mode 100644 index 00000000..687e7262 --- /dev/null +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaborator.java @@ -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) { + + } + +} diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java index 1e35368a..8df2c781 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java @@ -3,6 +3,7 @@ package com.wisemapping.rest.model; import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.model.*; +import com.wisemapping.util.TimeUtils; import org.codehaus.jackson.annotate.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -28,15 +29,9 @@ public class RestMindmap { private Collaborator collaborator; @JsonIgnore private Mindmap mindmap; - @JsonIgnore - static private SimpleDateFormat sdf; + @Nullable private String properties; - static { - sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); - sdf.setTimeZone(TimeZone.getTimeZone("UTC")); - } - public RestMindmap() throws WiseMappingException { this(new Mindmap(), null); @@ -46,8 +41,10 @@ public class RestMindmap { this.mindmap = mindmap; this.collaborator = collaborator; if (collaborator != null) { - final CollaborationProperties collaborationProperties = mindmap.findCollaborationProperties(collaborator); - this.properties = collaborationProperties.getMindmapProperties(); + final CollaborationProperties collaborationProperties = mindmap.findCollaborationProperties(collaborator, false); + if (collaborationProperties != null) { + this.properties = collaborationProperties.getMindmapProperties(); + } } } @@ -56,7 +53,7 @@ public class RestMindmap { final Calendar creationTime = mindmap.getCreationTime(); String result = null; if (creationTime != null) { - result = this.toISO8601(creationTime.getTime()); + result = TimeUtils.toISO8601(creationTime.getTime()); } return result; } @@ -81,15 +78,21 @@ public class RestMindmap { return mindmap.getCreator().getEmail(); } - public Collaborator getLastModifierUser() { - return mindmap.getLastEditor(); + public RestCollaborator getLastModifierUser() { + 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() { final Calendar date = mindmap.getLastModificationTime(); String result = null; if (date != null) { - result = toISO8601(date.getTime()); + result = TimeUtils.toISO8601(date.getTime()); } return result; } @@ -153,6 +156,7 @@ public class RestMindmap { public void setLastModifierUser(String lastModifierUser) { } + @Nullable public String getProperties() { return properties; } @@ -175,12 +179,4 @@ public class RestMindmap { public Mindmap getDelegated() { return this.mindmap; } - - private String toISO8601(@Nullable Date date) { - String result = ""; - if (date != null) { - result = sdf.format(date) + "Z"; - } - return result; - } } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java index 4cb14b80..ed5e003c 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java @@ -6,6 +6,7 @@ import com.wisemapping.model.Collaborator; import com.wisemapping.model.Mindmap; import com.wisemapping.model.User; import com.wisemapping.security.Utils; +import com.wisemapping.util.TimeUtils; import org.codehaus.jackson.annotate.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,13 +33,6 @@ public class RestMindmapInfo { @JsonIgnore private Mindmap mindmap; 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() { this(new Mindmap(), null); @@ -51,7 +45,7 @@ public class RestMindmapInfo { } public String getCreationTime() { - return this.toISO8601(mindmap.getCreationTime().getTime()); + return TimeUtils.toISO8601(mindmap.getCreationTime().getTime()); } public String getDescription() { @@ -94,7 +88,7 @@ public class RestMindmapInfo { public String getLastModificationTime() { final Calendar calendar = mindmap.getLastModificationTime(); - return this.toISO8601(calendar.getTime()); + return TimeUtils.toISO8601(calendar.getTime()); } public boolean isPublic() { @@ -138,8 +132,4 @@ public class RestMindmapInfo { public Mindmap getDelegated() { return this.mindmap; } - - private String toISO8601(@NotNull Date date) { - return sdf.format(date) + "Z"; - } } diff --git a/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java b/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java index ddf93648..76c8cbb7 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java @@ -29,7 +29,8 @@ public interface MindmapService { static final String TAG_SEPARATOR = " "; - Mindmap findMindmapById(int mindmapId); + @NotNull + Mindmap findMindmapById(int id); Mindmap getMindmapByTitle(String title, User user); diff --git a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java index 6cbf81b9..f27a7f07 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java @@ -79,8 +79,9 @@ public class MindmapServiceImpl } @Override - public Mindmap findMindmapById(int mindmapId) { - return mindmapManager.getMindmapById(mindmapId); + @NotNull + public Mindmap findMindmapById(int id) { + return mindmapManager.getMindmapById(id); } @Override diff --git a/wise-webapp/src/main/java/com/wisemapping/util/TimeUtils.java b/wise-webapp/src/main/java/com/wisemapping/util/TimeUtils.java new file mode 100644 index 00000000..44cb2ce1 --- /dev/null +++ b/wise-webapp/src/main/java/com/wisemapping/util/TimeUtils.java @@ -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; + } + +}