diff --git a/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java b/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java index 7446b6f5..630776f9 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java @@ -26,6 +26,7 @@ import org.jetbrains.annotations.Nullable; import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; +import java.util.Objects; @Entity @Table(name = "COLLABORATION") @@ -127,16 +128,14 @@ public class Collaboration implements Serializable { Collaboration that = (Collaboration) o; if (id != that.id) return false; - if (collaborator != null ? !collaborator.equals(that.collaborator) : that.collaborator != null) return false; - if (mindMap != null ? !mindMap.equals(that.mindMap) : that.mindMap != null) return false; + if (!Objects.equals(collaborator, that.collaborator)) return false; + if (!Objects.equals(mindMap, that.mindMap)) return false; return role == that.role; } @Override public int hashCode() { - int result = id ^ (id >>> 32); - result = 31 * result + (role != null ? role.hashCode() : 0); - result = 31 * result + (mindMap != null ? mindMap.hashCode() : 0); - return result; + //https://thorben-janssen.com/ultimate-guide-to-implementing-equals-and-hashcode-with-hibernate/ + return 13; } } diff --git a/wise-webapp/src/main/java/com/wisemapping/model/Label.java b/wise-webapp/src/main/java/com/wisemapping/model/Label.java index 95e80415..6126560d 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/Label.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/Label.java @@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable; import javax.persistence.*; import java.io.Serializable; +import java.util.Objects; @Entity @Table(name = "LABEL") @@ -34,17 +35,22 @@ public class Label implements Serializable { @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; - @NotNull private String title; - @NotNull private String color; - @Nullable private String iconName; + @NotNull + private String title; + @NotNull + private String color; + @Nullable + private String iconName; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="creator_id",nullable = true,unique = true) - @NotNull private User creator; + @JoinColumn(name = "creator_id", nullable = true, unique = true) + @NotNull + private User creator; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="parent_label_id",nullable = true) - @Nullable private Label parent; + @JoinColumn(name = "parent_label_id", nullable = true) + @Nullable + private Label parent; public void setParent(@Nullable Label parent) { this.parent = parent; @@ -104,17 +110,15 @@ public class Label implements Serializable { if (this == o) return true; if (!(o instanceof Label)) return false; - Label label = (Label) o; - + final Label label = (Label) o; return id == label.id && creator.getId() == label.creator.getId() - && !(parent != null ? !parent.equals(label.parent) : label.parent != null); + && Objects.equals(parent, label.parent); } @Override public int hashCode() { - long result = id; - result = 31 * result + title.hashCode(); - result = 31 * result + (creator!=null?creator.hashCode():0); + long result = title.hashCode(); + result = 31 * result + (creator != null ? creator.hashCode() : 0); result = 31 * result + (parent != null ? parent.hashCode() : 0); return (int) result; } 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 d3cdf366..0b2052ff 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/Mindmap.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/Mindmap.java @@ -146,7 +146,9 @@ public class Mindmap implements Serializable { } public void removedCollaboration(@NotNull Collaboration collaboration) { - collaborations.remove(collaboration); + // https://stackoverflow.com/questions/25125210/hibernate-persistentset-remove-operation-not-working + this.collaborations.remove(collaboration); + collaboration.setMindMap(null); } public void removedCollaboration(@NotNull Set collaborations) { diff --git a/wise-webapp/src/main/java/com/wisemapping/security/aop/ViewBaseSecurityAdvise.java b/wise-webapp/src/main/java/com/wisemapping/security/aop/ViewBaseSecurityAdvise.java index c9807d61..52c59944 100755 --- a/wise-webapp/src/main/java/com/wisemapping/security/aop/ViewBaseSecurityAdvise.java +++ b/wise-webapp/src/main/java/com/wisemapping/security/aop/ViewBaseSecurityAdvise.java @@ -38,7 +38,6 @@ public class ViewBaseSecurityAdvise @Override protected boolean isAllowed(@Nullable User user, Mindmap map) { - System.out.println("VIEWWWWWWWWWWWWW"); return getMindmapService().hasPermissions(user, map, CollaborationRole.VIEWER); } 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 8207a662..7a4a763f 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java @@ -143,15 +143,13 @@ public class MindmapServiceImpl public void removeCollaboration(@NotNull Mindmap mindmap, @NotNull Collaboration collaboration) throws CollaborationException { // remove collaborator association final Mindmap mindMap = collaboration.getMindMap(); - final Set collaborations = mindMap.getCollaborations(); - final User creator = mindMap.getCreator(); if (creator.identityEquality(collaboration.getCollaborator())) { throw new CollaborationException("User is the creator and must have ownership permissions.Creator Email:" + mindMap.getCreator().getEmail() + ",Collaborator:" + collaboration.getCollaborator().getEmail()); } // When you delete an object from hibernate you have to delete it from *all* collections it exists in... - collaborations.remove(collaboration); + mindMap.removedCollaboration(collaboration); mindmapManager.removeCollaboration(collaboration); } @@ -249,7 +247,7 @@ public class MindmapServiceImpl @Override public void revertChange(@NotNull Mindmap mindmap, int historyId) - throws WiseMappingException, IOException { + throws WiseMappingException { final MindMapHistory history = mindmapManager.getHistory(historyId); mindmap.setZippedXml(history.getZippedXml()); updateMindmap(mindmap, true);