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