25f5802413c17879683bdbcae27ed6c3662e7e10
[so.git] / mso-api-handlers / mso-requests-db / src / main / java / org / onap / so / db / request / beans / WatchdogServiceModVerIdLookup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.db.request.beans;
22
23 import java.io.Serializable;
24 import java.util.Date;
25 import java.util.Objects;
26 import java.util.Optional;
27
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.Id;
31 import javax.persistence.IdClass;
32 import javax.persistence.PrePersist;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36
37 import org.apache.commons.lang3.builder.ToStringBuilder;
38
39 @IdClass(WatchdogServiceModVerIdLookupId.class)
40 @Entity
41 @Table(name = "watchdog_service_mod_ver_id_lookup")
42 public class WatchdogServiceModVerIdLookup implements Serializable {
43
44         /**
45          * Serialization id.
46          */
47         private static final long serialVersionUID = 7783869906430250355L;
48         
49         @Id
50         @Column(name = "DISTRIBUTION_ID", length=45)
51         private String distributionId;
52         @Id
53         @Column(name = "SERVICE_MODEL_VERSION_ID", length=45)
54         private String serviceModelVersionId;
55         @Column(name = "DISTRIBUTION_NOTIFICATION")
56         private String distributionNotification;
57         @Column(name = "CONSUMER_ID", length=200)
58         private String consumerId;      
59         @Column(name = "CREATE_TIME", updatable=false)
60         @Temporal(TemporalType.TIMESTAMP)
61         private Date createTime;
62         
63         public WatchdogServiceModVerIdLookup() {
64                 
65         }
66         /**
67          * 
68          * @param distributionId - Distribution ID
69          * @param serviceModelVersionId -- service UUID 
70          * @param distributionNotification -- Notification content from ASDC
71          * @param consumerId -- Consumer ID associated with subscription.
72          */
73         public WatchdogServiceModVerIdLookup(String distributionId, String serviceModelVersionId,
74                         Optional<String> distributionNotification, String consumerId) {
75                 this.distributionId = distributionId;
76                 this.serviceModelVersionId = serviceModelVersionId;
77                 this.distributionNotification= distributionNotification.orElse(null);
78                 this.consumerId = consumerId;           
79         }
80
81         public String getDistributionId() {
82                 return distributionId;
83         }
84         
85         public void setDistributionId(String distributionId) {
86                 this.distributionId = distributionId;
87         }
88         
89         public String getServiceModelVersionId() {
90                 return serviceModelVersionId;
91         }
92
93         public void setServiceModelVersionId(String serviceModelVersionId) {
94                 this.serviceModelVersionId = serviceModelVersionId;
95         }
96         
97         public Date getCreateTime() {
98                 return createTime;
99         }
100
101         @PrePersist
102         protected void onCreate() {
103                 this.createTime = new Date();
104         }
105         @Override
106         public boolean equals(final Object other) {
107                 if (this == other) {
108                         return true;
109                 }
110                 if (!(other instanceof WatchdogServiceModVerIdLookup)) {
111                         return false;
112                 }
113                 WatchdogServiceModVerIdLookup castOther = (WatchdogServiceModVerIdLookup) other;
114                 return Objects.equals(getDistributionId(), castOther.getDistributionId())
115                                 && Objects.equals(getServiceModelVersionId(), castOther.getServiceModelVersionId());
116         }
117         @Override
118         public int hashCode() {
119                 return Objects.hash(getDistributionId(), getServiceModelVersionId());
120         }
121         @Override
122         public String toString() {
123                 return new ToStringBuilder(this)
124                                 .append("distributionId", getDistributionId())
125                                 .append("serviceModelVersionId", getServiceModelVersionId())
126                                 .append("createTime", getCreateTime())
127                                 .append("distributionNotification", getDistributionNotification())
128                                 .append("consumerId", getConsumerId())
129                                 .toString();
130         }
131         public String getDistributionNotification() {
132                 return distributionNotification;
133         }
134         public void setDistributionNotification(String distributionNotification) {
135                 this.distributionNotification = distributionNotification;
136         }
137         public String getConsumerId() {
138                 return consumerId;
139         }
140         public void setConsumerId(String consumerId) {
141                 this.consumerId = consumerId;
142         }
143 }