mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-24 06:57:56 +01:00
Fix deleted object would be re-saved by cascade (remove deleted object from associations): [com.wisemapping.model.Collaboration#1651889]
This commit is contained in:
parent
4ee62035b8
commit
6cd0f635d5
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<Collaboration> collaborations) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<Collaboration> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user