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