View Javadoc
1   package de.dlr.shepard.context.semantic.entities;
2   
3   import de.dlr.shepard.common.util.Constants;
4   import de.dlr.shepard.common.util.HasId;
5   import java.util.Objects;
6   import lombok.Data;
7   import lombok.NoArgsConstructor;
8   import lombok.ToString;
9   import org.neo4j.ogm.annotation.GeneratedValue;
10  import org.neo4j.ogm.annotation.Id;
11  import org.neo4j.ogm.annotation.NodeEntity;
12  import org.neo4j.ogm.annotation.Relationship;
13  
14  @NodeEntity
15  @Data
16  @NoArgsConstructor
17  public class SemanticAnnotation implements HasId {
18  
19    @Id
20    @GeneratedValue
21    private Long id;
22  
23    @Deprecated
24    public String getName() {
25      return String.format("%s::%s", this.getPropertyName(), this.getValueName());
26    }
27  
28    private String propertyName;
29  
30    private String propertyIRI;
31  
32    private String valueName;
33  
34    private String valueIRI;
35  
36    @ToString.Exclude
37    @Relationship(type = Constants.PROPERTY_REPOSITORY)
38    private SemanticRepository propertyRepository;
39  
40    @ToString.Exclude
41    @Relationship(type = Constants.VALUE_REPOSITORY)
42    private SemanticRepository valueRepository;
43  
44    /**
45     * For testing purposes only
46     *
47     * @param id identifies the entity
48     */
49    public SemanticAnnotation(long id) {
50      this.id = id;
51    }
52  
53    @Override
54    public int hashCode() {
55      final int prime = 31;
56      var result = Objects.hash(id, propertyName, valueName, propertyIRI, valueIRI);
57      result = prime * result + HasId.hashcodeHelper(propertyRepository);
58      result = prime * result + HasId.hashcodeHelper(valueRepository);
59      return result;
60    }
61  
62    @Override
63    public boolean equals(Object obj) {
64      if (this == obj) return true;
65      if (obj == null) return false;
66      if (!(obj instanceof SemanticAnnotation)) return false;
67      SemanticAnnotation other = (SemanticAnnotation) obj;
68      return (
69        Objects.equals(id, other.id) &&
70        Objects.equals(propertyName, other.propertyName) &&
71        Objects.equals(valueName, other.valueName) &&
72        Objects.equals(propertyIRI, other.propertyIRI) &&
73        Objects.equals(valueIRI, other.valueIRI) &&
74        HasId.equalsHelper(propertyRepository, other.propertyRepository) &&
75        HasId.equalsHelper(valueRepository, other.valueRepository)
76      );
77    }
78  
79    @Override
80    public String getUniqueId() {
81      return id.toString();
82    }
83  }