85af3022055d77ddb2d592af8eab9fcbcd615a72
[sdc.git] /
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.notification.dao.types;
18
19 import com.datastax.driver.mapping.annotations.ClusteringColumn;
20 import com.datastax.driver.mapping.annotations.Column;
21 import com.datastax.driver.mapping.annotations.PartitionKey;
22 import com.datastax.driver.mapping.annotations.Table;
23
24 import java.util.Objects;
25 import java.util.UUID;
26
27 @Table(keyspace = "dox", name = "notifications")
28 public class NotificationEntity {
29
30   public static final String ENTITY_TYPE = "Event Notification";
31
32   @PartitionKey
33   @Column(name = "owner_id")
34   private String ownerId;
35
36   @Column(name = "read")
37   private boolean read;
38
39   @ClusteringColumn
40   @Column(name = "event_id")
41   private UUID eventId;
42
43   @Column(name = "event_type")
44   private String eventType;
45
46   @Column(name = "event_attributes")
47   private String eventAttributes;
48
49   @Column(name = "originator_id")
50   private String originatorId;
51
52   /**
53    * Every entity class must have a default constructor according to
54    * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
55    * Definition of mapped classes</a>.
56    */
57   public NotificationEntity() {
58     // Don't delete! Default constructor is required by DataStax driver
59   }
60
61   public NotificationEntity(String ownerId) {
62     this.ownerId = ownerId;
63   }
64
65   /**
66    * Instantiates a new Notification entity.
67    *
68    * @param ownerId      the owner id
69    * @param eventId      the event id
70    * @param eventType    the event type
71    * @param originatorId the originator id
72    */
73   public NotificationEntity(String ownerId, UUID eventId, String eventType, String originatorId, boolean read,
74                             String eventAttributes) {
75     this.ownerId = ownerId;
76     this.read = read;
77     this.eventId = eventId;
78     this.eventType = eventType;
79     this.originatorId = originatorId;
80     this.eventAttributes = eventAttributes;
81   }
82
83   public NotificationEntity(String ownerId, UUID eventId, String eventType, String originatorId) {
84                 this(ownerId, eventId, eventType, originatorId, false, null);
85   }
86
87   public NotificationEntity(String ownerId, UUID eventId) {
88                 this(ownerId, eventId, null, null);
89   }
90
91   public String getOwnerId() {
92     return ownerId;
93   }
94
95   public void setOwnerId(String ownerId) {
96     this.ownerId = ownerId;
97   }
98
99   public boolean isRead() {
100     return read;
101   }
102
103   public void setRead(boolean read) {
104     this.read = read;
105   }
106
107   public UUID getEventId() {
108     return eventId;
109   }
110
111   public void setEventId(UUID eventId) {
112     this.eventId = eventId;
113   }
114
115   public String getEventType() {
116     return eventType;
117   }
118
119   public void setEventType(String eventType) {
120     this.eventType = eventType;
121   }
122
123   public String getEventAttributes() {
124     return eventAttributes;
125   }
126
127   public void setEventAttributes(String eventAttributes) {
128     this.eventAttributes = eventAttributes;
129   }
130
131   public String getOriginatorId() {
132     return originatorId;
133   }
134
135   public void setOriginatorId(String originatorId) {
136     this.originatorId = originatorId;
137   }
138
139
140   @Override
141   public boolean equals(Object o) {
142     if (this == o) return true;
143     if (o == null || getClass() != o.getClass()) return false;
144     NotificationEntity that = (NotificationEntity) o;
145     return read == that.read &&
146             Objects.equals(ownerId, that.ownerId) &&
147             Objects.equals(eventId, that.eventId) &&
148             Objects.equals(eventType, that.eventType) &&
149             Objects.equals(eventAttributes, that.eventAttributes) &&
150             Objects.equals(originatorId, that.originatorId);
151   }
152
153   @Override
154   public int hashCode() {
155     return Objects.hash(ownerId, read, eventId, eventType, eventAttributes, originatorId);
156   }
157
158   @Override
159   public String toString() {
160     return "NotificationEntity {"
161         + "ownerId='" + ownerId + '\''
162         + ", state='" + (read ? "Read" : "Noread") + '\''
163         + ", originatorId='" + originatorId + '\''
164         + ", eventId='" + eventId + '\''
165         + ", eventType='" + eventType + '\''
166         + ", eventAttributes='" + eventAttributes + '\''
167         + '}';
168   }
169 }