View Javadoc
1   package de.dlr.shepard.neo4Core.entities;
2   
3   import de.dlr.shepard.util.Constants;
4   import de.dlr.shepard.util.HasId;
5   import de.dlr.shepard.util.RequestMethod;
6   import java.util.Date;
7   import java.util.Objects;
8   import lombok.Data;
9   import lombok.NoArgsConstructor;
10  import lombok.ToString;
11  import org.neo4j.ogm.annotation.GeneratedValue;
12  import org.neo4j.ogm.annotation.Id;
13  import org.neo4j.ogm.annotation.Index;
14  import org.neo4j.ogm.annotation.NodeEntity;
15  import org.neo4j.ogm.annotation.Relationship;
16  import org.neo4j.ogm.annotation.typeconversion.DateLong;
17  
18  @NodeEntity
19  @Data
20  @NoArgsConstructor
21  public class Subscription implements HasId {
22  
23    @Id
24    @GeneratedValue
25    private Long id;
26  
27    private String name;
28  
29    private String callbackURL;
30  
31    private String subscribedURL;
32  
33    @Index
34    private RequestMethod requestMethod;
35  
36    @ToString.Exclude
37    @Relationship(type = Constants.SUBSCRIBED_BY)
38    private User createdBy;
39  
40    @DateLong
41    private Date createdAt;
42  
43    /**
44     * For testing purposes only
45     *
46     * @param id identifies the entity
47     */
48    public Subscription(long id) {
49      this.id = id;
50    }
51  
52    @Override
53    public String getUniqueId() {
54      return id.toString();
55    }
56  
57    @Override
58    public int hashCode() {
59      final int prime = 31;
60      int result = 1;
61      result = prime * result + Objects.hash(callbackURL, createdAt, id, name, createdBy, requestMethod, subscribedURL);
62      result = prime * result + HasId.hashcodeHelper(createdBy);
63      return result;
64    }
65  
66    @Override
67    public boolean equals(Object obj) {
68      if (this == obj) return true;
69      if (!(obj instanceof Subscription)) return false;
70      Subscription other = (Subscription) obj;
71      return (
72        Objects.equals(callbackURL, other.callbackURL) &&
73        Objects.equals(createdAt, other.createdAt) &&
74        Objects.equals(id, other.id) &&
75        Objects.equals(name, other.name) &&
76        HasId.equalsHelper(createdBy, other.createdBy) &&
77        requestMethod == other.requestMethod &&
78        Objects.equals(subscribedURL, other.subscribedURL)
79      );
80    }
81  }