1 package de.dlr.shepard.neo4Core.entities;
2
3 import de.dlr.shepard.util.Constants;
4 import de.dlr.shepard.util.HasId;
5 import java.util.ArrayList;
6 import java.util.List;
7 import lombok.Data;
8 import lombok.NoArgsConstructor;
9 import lombok.ToString;
10 import org.neo4j.ogm.annotation.NodeEntity;
11 import org.neo4j.ogm.annotation.Relationship;
12 import org.neo4j.ogm.annotation.Relationship.Direction;
13
14 @NodeEntity
15 @Data
16 @ToString(callSuper = true, onlyExplicitlyIncluded = true)
17 @NoArgsConstructor
18 public class Collection extends AbstractDataObject {
19
20 @Relationship(type = Constants.HAS_DATAOBJECT)
21 private List<DataObject> dataObjects = new ArrayList<>();
22
23 @Relationship(type = Constants.POINTS_TO, direction = Direction.INCOMING)
24 private List<CollectionReference> incoming = new ArrayList<>();
25
26 @Relationship(type = Constants.HAS_PERMISSIONS)
27 private Permissions permissions;
28
29 @Relationship(type = Constants.HAS_VERSION)
30 private Version version;
31
32
33
34
35
36
37 public Collection(long id) {
38 super(id);
39 }
40
41
42 public Collection(Collection collection) {
43 this.setAnnotations(collection.getAnnotations());
44 this.setAttributes(collection.getAttributes());
45 this.setCreatedAt(collection.getCreatedAt());
46 this.setCreatedBy(collection.getCreatedBy());
47 this.setDataObjects(collection.getDataObjects());
48 this.setDescription(collection.getDescription());
49 this.setIncoming(collection.getIncoming());
50 this.setName(collection.getName());
51 this.setPermissions(collection.getPermissions());
52 this.setShepardId(collection.getShepardId());
53 }
54
55
56
57
58
59
60 public void addDataObject(DataObject dataObject) {
61 dataObjects.add(dataObject);
62 }
63
64 @Override
65 public int hashCode() {
66 final int prime = 31;
67 int result = super.hashCode();
68 result = prime * result + HasId.hashcodeHelper(dataObjects);
69 result = prime * result + HasId.hashcodeHelper(incoming);
70 result = prime * result + HasId.hashcodeHelper(permissions);
71 result = prime * result + HasId.hashcodeHelper(version);
72 return result;
73 }
74
75 @Override
76 public boolean equals(Object obj) {
77 if (this == obj) return true;
78 if (!super.equals(obj)) return false;
79 if (!(obj instanceof Collection)) return false;
80 Collection other = (Collection) obj;
81 return (
82 HasId.equalsHelper(dataObjects, other.dataObjects) &&
83 HasId.equalsHelper(incoming, other.incoming) &&
84 HasId.equalsHelper(permissions, other.permissions) &&
85 HasId.equalsHelper(version, other.version)
86 );
87 }
88 }