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