- 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();
@Nullable
@NotNull
Mindmap getMindmapById(int mindmapId);
Mindmap getMindmapByTitle(final String name, final User user);

View File

@ -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

View File

@ -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) {
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);

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.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,17 +41,19 @@ public class RestMindmap {
this.mindmap = mindmap;
this.collaborator = collaborator;
if (collaborator != null) {
final CollaborationProperties collaborationProperties = mindmap.findCollaborationProperties(collaborator);
final CollaborationProperties collaborationProperties = mindmap.findCollaborationProperties(collaborator, false);
if (collaborationProperties != null) {
this.properties = collaborationProperties.getMindmapProperties();
}
}
}
public String getCreationTime() {
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;
}
}

View File

@ -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";
}
}

View File

@ -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);

View File

@ -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

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;
}
}