79b27e7deb96923bd2d2ae50507d31b4ebbe5a65
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / beans / ServiceRecipe.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.catalog.beans;
22
23 import java.io.Serializable;
24 import java.util.Date;
25
26 import javax.persistence.CascadeType;
27 import javax.persistence.Column;
28 import javax.persistence.Entity;
29 import javax.persistence.FetchType;
30 import javax.persistence.Id;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.ManyToOne;
33 import javax.persistence.PrePersist;
34 import javax.persistence.Table;
35 import javax.persistence.Temporal;
36 import javax.persistence.TemporalType;
37
38 import org.apache.commons.lang3.builder.EqualsBuilder;
39 import org.apache.commons.lang3.builder.HashCodeBuilder;
40 import org.apache.commons.lang3.builder.ToStringBuilder;
41
42 import com.openpojo.business.annotation.BusinessKey;
43
44 @Entity
45 @Table(name = "service_recipe")
46 public class ServiceRecipe implements Serializable, Recipe {
47         
48         private static final long serialVersionUID = 768026109321305392L;
49
50         @Id
51         @Column(name = "id")
52         private Integer id;
53
54         @BusinessKey
55         @Column(name = "SERVICE_MODEL_UUID")
56         private String serviceModelUUID;
57
58         @BusinessKey
59         @Column(name = "ACTION")
60         private String action;
61
62         @Column(name = "description")
63         private String description;
64
65         @BusinessKey
66         @Column(name = "ORCHESTRATION_URI")
67         private String orchestrationUri;
68
69         @Column(name = "SERVICE_PARAM_XSD")
70         private String paramXsd;
71
72         @Column(name = "RECIPE_TIMEOUT")
73         private Integer recipeTimeout;
74
75         @Column(name = "SERVICE_TIMEOUT_INTERIM")
76         private Integer serviceTimeoutInterim;
77
78         @Column(name = "CREATION_TIMESTAMP", updatable = false)
79         @Temporal(TemporalType.TIMESTAMP)
80         private Date created;
81         
82         @BusinessKey
83         @ManyToOne(cascade = CascadeType.ALL)
84         @JoinColumn(name = "SERVICE_MODEL_UUID", referencedColumnName = "MODEL_UUID",insertable = false, updatable = false)
85         private Service service;
86
87         @PrePersist
88         protected void onCreate() {
89                 this.created = new Date();
90         }
91
92         @Override
93         public String toString() {
94                 return new ToStringBuilder(this).append("id", id).append("serviceModelUUID", serviceModelUUID)
95                                 .append("action", action).append("description", description)
96                                 .append("orchestrationUri", orchestrationUri).append("serviceParamXSD", paramXsd)
97                                 .append("recipeTimeout", recipeTimeout).append("serviceTimeoutInterim", serviceTimeoutInterim)
98                                 .append("created", created).toString();
99         }
100
101         @Override
102         public boolean equals(final Object other) {
103                 if (!(other instanceof ServiceRecipe)) {
104                         return false;
105                 }
106                 ServiceRecipe castOther = (ServiceRecipe) other;
107                 return new EqualsBuilder().append(serviceModelUUID, castOther.serviceModelUUID).append(action, castOther.action)
108                                 .append(orchestrationUri, castOther.orchestrationUri).isEquals();
109         }
110
111         @Override
112         public int hashCode() {
113                 return new HashCodeBuilder().append(serviceModelUUID).append(action).append(orchestrationUri).toHashCode();
114         }
115
116         // This 'default' CTR is now needed for backward compatibility since a new
117         // CTR was added below
118         public ServiceRecipe() {
119                 super();
120         }
121
122         public Integer getId() {
123                 return id;
124         }
125
126         public void setId(Integer id) {
127                 this.id = id;
128         }
129
130         public void setCreated(Date created) {
131                 this.created = created;
132         }
133
134         public String getServiceModelUUID() {
135                 return serviceModelUUID;
136         }
137
138         public void setServiceModelUUID(String serviceModelUUID) {
139                 this.serviceModelUUID = serviceModelUUID;
140         }
141
142         public String getAction() {
143                 return action;
144         }
145
146         public void setAction(String action) {
147                 this.action = action;
148         }
149
150         public String getDescription() {
151                 return description;
152         }
153
154         public void setDescription(String description) {
155                 this.description = description;
156         }
157
158         public String getOrchestrationUri() {
159                 return orchestrationUri;
160         }
161
162         public void setOrchestrationUri(String orchestrationUri) {
163                 this.orchestrationUri = orchestrationUri;
164         }
165
166         public String getParamXsd() {
167                 return paramXsd;
168         }
169
170         public void setParamXsd(String paramXsd) {
171                 this.paramXsd = paramXsd;
172         }
173
174         public Integer getRecipeTimeout() {
175                 return recipeTimeout;
176         }
177
178         public void setRecipeTimeout(Integer recipeTimeout) {
179                 this.recipeTimeout = recipeTimeout;
180         }
181
182         public Integer getServiceTimeoutInterim() {
183                 return serviceTimeoutInterim;
184         }
185
186         public void setServiceTimeoutInterim(Integer serviceTimeoutInterim) {
187                 this.serviceTimeoutInterim = serviceTimeoutInterim;
188         }
189         
190         public Service getService() {
191                 return service;
192         }
193
194         public void setService(Service service) {
195                 this.service = service;
196         }
197
198         public Date getCreated() {
199                 return created;
200         }
201 }