1 package de.dlr.shepard.neo4Core.entities;
2
3 import de.dlr.shepard.labJournal.entities.LabJournalEntry;
4 import de.dlr.shepard.util.Constants;
5 import de.dlr.shepard.util.HasId;
6 import java.util.ArrayList;
7 import java.util.List;
8 import lombok.Data;
9 import lombok.NoArgsConstructor;
10 import lombok.ToString;
11 import org.neo4j.ogm.annotation.NodeEntity;
12 import org.neo4j.ogm.annotation.Relationship;
13 import org.neo4j.ogm.annotation.Relationship.Direction;
14
15 @NodeEntity
16 @Data
17 @ToString(callSuper = true, onlyExplicitlyIncluded = true)
18 @NoArgsConstructor
19 public class DataObject extends AbstractDataObject {
20
21 @Relationship(type = Constants.HAS_DATAOBJECT, direction = Direction.INCOMING)
22 private Collection collection;
23
24 @Relationship(type = Constants.HAS_REFERENCE)
25 private List<BasicReference> references = new ArrayList<>();
26
27 @Relationship(type = Constants.HAS_SUCCESSOR)
28 private List<DataObject> successors = new ArrayList<>();
29
30 @Relationship(type = Constants.HAS_SUCCESSOR, direction = Direction.INCOMING)
31 private List<DataObject> predecessors = new ArrayList<>();
32
33 @Relationship(type = Constants.HAS_CHILD)
34 private List<DataObject> children = new ArrayList<>();
35
36 @Relationship(type = Constants.HAS_CHILD, direction = Direction.INCOMING)
37 private DataObject parent;
38
39 @Relationship(type = Constants.POINTS_TO, direction = Direction.INCOMING)
40 private List<DataObjectReference> incoming = new ArrayList<>();
41
42 @Relationship(type = Constants.HAS_LABJOURNAL_ENTRY)
43 private List<LabJournalEntry> labJournalEntries = new ArrayList<>();
44
45
46
47
48
49
50 public DataObject(long id) {
51 super(id);
52 }
53
54 public void addReference(BasicReference reference) {
55 references.add(reference);
56 }
57
58 public void addSuccessor(DataObject successor) {
59 successors.add(successor);
60 }
61
62 public void addPredecessor(DataObject predecessor) {
63 predecessors.add(predecessor);
64 }
65
66 public void addChild(DataObject child) {
67 children.add(child);
68 }
69
70 public void addIncoming(DataObjectReference dataObjectReference) {
71 incoming.add(dataObjectReference);
72 }
73
74 @Override
75 public int hashCode() {
76 final int prime = 31;
77 int result = super.hashCode();
78 result = prime * result + HasId.hashcodeHelper(collection);
79 result = prime * result + HasId.hashcodeHelper(references);
80 result = prime * result + HasId.hashcodeHelper(successors);
81 result = prime * result + HasId.hashcodeHelper(predecessors);
82 result = prime * result + HasId.hashcodeHelper(children);
83 result = prime * result + HasId.hashcodeHelper(parent);
84 result = prime * result + HasId.hashcodeHelper(incoming);
85 result = prime * result + HasId.hashcodeHelper(labJournalEntries);
86 return result;
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) return true;
92 if (!super.equals(obj)) return false;
93 if (!(obj instanceof DataObject)) return false;
94 DataObject other = (DataObject) obj;
95 return (
96 HasId.equalsHelper(collection, other.collection) &&
97 HasId.equalsHelper(references, other.references) &&
98 HasId.equalsHelper(predecessors, other.predecessors) &&
99 HasId.equalsHelper(successors, other.successors) &&
100 HasId.equalsHelper(parent, other.parent) &&
101 HasId.equalsHelper(children, other.children) &&
102 HasId.equalsHelper(incoming, other.incoming) &&
103 HasId.equalsHelper(labJournalEntries, other.labJournalEntries)
104 );
105 }
106 }