Fix collaboration equal issue.

This commit is contained in:
Paulo Gustavo Veiga 2012-11-14 20:17:55 -03:00
parent 2861a7b5f9
commit 16e59a0879
7 changed files with 40 additions and 22 deletions

View File

@ -19,37 +19,36 @@
package com.wisemapping.model;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Set;
import java.util.HashSet;
import java.util.Set;
public class Collaborator implements Serializable {
public class Collaborator implements Serializable {
private long id;
private String email;
private Calendar creationDate;
private Set<Collaboration> collaborations = new HashSet<Collaboration>();
public Collaborator() {}
public Collaborator() {
}
public Collaborator(Set<Collaboration> collaborations) {
public Collaborator(Set<Collaboration> collaborations) {
this.collaborations = collaborations;
}
public void setCollaborations(Set<Collaboration> collaborations)
{
public void setCollaborations(Set<Collaboration> collaborations) {
this.collaborations = collaborations;
}
public void addCollaboration(@NotNull Collaboration collaboration)
{
collaborations.add(collaboration);
public void addCollaboration(@NotNull Collaboration collaboration) {
collaborations.add(collaboration);
}
public Set<Collaboration> getCollaborations()
{
public Set<Collaboration> getCollaborations() {
return collaborations;
}
@ -96,4 +95,17 @@ public class Collaborator implements Serializable {
result = 31 * result + (email != null ? email.hashCode() : 0);
return result;
}
public boolean equalCollab(@Nullable Collaborator that) {
if (this == that) return true;
if (that == null) return false;
if (id != that.id) return false;
if (email != null ? !email.equals(that.email) : that.email != null) return false;
return true;
}
}

View File

@ -28,7 +28,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@ -111,7 +110,14 @@ public class Mindmap {
@Nullable
public Collaboration findCollaboration(@NotNull Collaborator collaborator) {
return this.findCollaboration(collaborator.getEmail());
Collaboration result = null;
for (Collaboration collaboration : collaborations) {
if (collaboration.getCollaborator().equalCollab(collaborator)) {
result = collaboration;
break;
}
}
return result;
}
@Nullable

View File

@ -183,7 +183,7 @@ public class MindmapController extends BaseController {
}
final LockInfo lockInfo = lockManager.getLockInfo(mindmap);
if (lockInfo.getUser().equals(user)) {
if (lockInfo.getUser().equalCollab(user)) {
final boolean outdated = mindmap.getLastModificationTime().getTimeInMillis() > timestamp;
if (lockInfo.getSession() == session) {
// Timestamp might not be returned to the client. This try to cover this case, ignoring the client timestamp check.

View File

@ -23,7 +23,6 @@ import com.wisemapping.model.User;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.jetbrains.annotations.NotNull;
import javax.xml.bind.annotation.XmlAccessType;
@ -125,7 +124,7 @@ public class RestUser {
}
RestUser restUser = (RestUser) o;
return this.getDelegated().equals(restUser.getDelegated());
return this.getDelegated().equalCollab(restUser.getDelegated());
}
@Override

View File

@ -41,7 +41,7 @@ public abstract class BaseSecurityAdvice {
isAllowed = isAllowed(user, ((Integer) argument));
} else if (argument instanceof Collaborator) {
// Read operation find on the user are allowed ...
isAllowed = user.equals(argument);
isAllowed = user.equalCollab((Collaborator) argument);
} else {
throw new IllegalArgumentException("Argument " + argument);
}

View File

@ -101,7 +101,7 @@ class LockManagerImpl implements LockManager {
public boolean isLockedBy(@NotNull Mindmap mindmap, @NotNull User collaborator) {
boolean result = false;
final LockInfo lockInfo = this.getLockInfo(mindmap);
if (lockInfo != null && lockInfo.getUser().equals(collaborator)) {
if (lockInfo != null && lockInfo.getUser().equalCollab(collaborator)) {
result = true;
}
return result;

View File

@ -114,7 +114,8 @@ public class MindmapServiceImpl
final Mindmap mindMap = collaboration.getMindMap();
final Set<Collaboration> collaborations = mindMap.getCollaborations();
if (mindMap.getCreator().getEmail().equals(collaboration.getCollaborator().getEmail())) {
final User creator = mindMap.getCreator();
if (creator.equalCollab(collaboration.getCollaborator())) {
throw new CollaborationException("User is the creator and must have ownership permissions.Creator Email:" + mindMap.getCreator().getEmail() + ",Collaborator:" + collaboration.getCollaborator().getEmail());
}
@ -125,7 +126,7 @@ public class MindmapServiceImpl
@Override
public void removeMindmap(@NotNull Mindmap mindmap, @NotNull User user) throws WiseMappingException {
if (mindmap.getCreator().equals(user)) {
if (mindmap.getCreator().equalCollab(user)) {
mindmapManager.removeMindmap(mindmap);
} else {
final Collaboration collaboration = mindmap.findCollaboration(user);
@ -264,7 +265,7 @@ public class MindmapServiceImpl
@Override
public void updateCollaboration(@NotNull Collaborator collaborator, @NotNull Collaboration collaboration) throws WiseMappingException {
if (collaborator.equals(collaboration.getCollaborator())) {
if (collaborator.equalCollab(collaboration.getCollaborator())) {
throw new WiseMappingException("No enough permissions for this operation.");
}
mindmapManager.updateCollaboration(collaboration);
@ -276,7 +277,7 @@ public class MindmapServiceImpl
return this.lockManager;
}
private Collaboration getCollaborationBy(String email, Set<Collaboration> collaborations) {
private Collaboration getCollaborationBy(@NotNull final String email, @NotNull final Set<Collaboration> collaborations) {
Collaboration collaboration = null;
for (Collaboration user : collaborations) {