567675044e13105aec73ef4fd35614510b5d9261
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / beans / ToscaCsar.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 import java.util.List;
26
27 import javax.persistence.CascadeType;
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.Id;
31 import javax.persistence.OneToMany;
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.EqualsBuilder;
38 import org.apache.commons.lang3.builder.HashCodeBuilder;
39 import org.apache.commons.lang3.builder.ToStringBuilder;
40
41 import com.fasterxml.jackson.annotation.JsonIgnore;
42 import com.openpojo.business.annotation.BusinessKey;
43
44 import uk.co.blackpepper.bowman.annotation.LinkedResource;
45
46 @Entity
47 @Table(name = "tosca_csar")
48 public class ToscaCsar implements Serializable {
49
50         private static final long serialVersionUID = 768026109321305392L;
51
52         @BusinessKey
53         @Id
54         @Column(name = "ARTIFACT_UUID")
55         private String artifactUUID;
56
57         @Column(name = "NAME")
58         private String name;
59
60         @Column(name = "ARTIFACT_CHECKSUM")
61         private String artifactChecksum;
62
63         @Column(name = "URL")
64         private String url;
65
66         @Column(name = "DESCRIPTION")
67         private String description;
68
69         @Column(name = "CREATION_TIMESTAMP", updatable = false)
70         @Temporal(TemporalType.TIMESTAMP)
71         private Date created;
72
73         @BusinessKey
74         @Column(name = "Version")
75         private String version;
76
77         @OneToMany(cascade = CascadeType.ALL, mappedBy = "csar")
78         @JsonIgnore
79         private List<Service> services;
80
81         @Override
82         public String toString() {
83                 return new ToStringBuilder(this).append("artifactUUID", artifactUUID).append("name", name)
84                                 .append("artifactChecksum", artifactChecksum).append("url", url).append("description", description)
85                                 .append("created", created).append("version", version).append("services", services).toString();
86         }
87
88         @PrePersist
89         protected void onCreate() {
90                 this.created = new Date();
91         }
92
93         @Override
94         public boolean equals(final Object other) {
95                 if (!(other instanceof ToscaCsar)) {
96                         return false;
97                 }
98                 ToscaCsar castOther = (ToscaCsar) other;
99                 return new EqualsBuilder().append(artifactUUID, castOther.artifactUUID).append(version, castOther.version)
100                                 .isEquals();
101         }
102
103         @Override
104         public int hashCode() {
105                 return new HashCodeBuilder().append(artifactUUID).append(version).toHashCode();
106         }
107
108         public ToscaCsar() {
109         }
110
111         public String getArtifactUUID() {
112                 return artifactUUID;
113         }
114
115         public void setArtifactUUID(String artifactUUID) {
116                 this.artifactUUID = artifactUUID;
117         }
118
119         public String getName() {
120                 return name;
121         }
122
123         public void setName(String name) {
124                 this.name = name;
125         }
126
127         public String getVersion() {
128                 return version;
129         }
130
131         public void setVersion(String version) {
132                 this.version = version;
133         }
134
135         public String getArtifactChecksum() {
136                 return artifactChecksum;
137         }
138
139         public void setArtifactChecksum(String artifactChecksum) {
140                 this.artifactChecksum = artifactChecksum;
141         }
142
143         public String getUrl() {
144                 return url;
145         }
146
147         public void setUrl(String url) {
148                 this.url = url;
149         }
150
151         public String getDescription() {
152                 return description;
153         }
154
155         public void setDescription(String description) {
156                 this.description = description;
157         }
158
159         public Date getCreated() {
160                 return created;
161         }
162
163         @LinkedResource
164         public List<Service> getServices() {
165                 return services;
166         }
167
168         public void setServices(List<Service> services) {
169                 this.services = services;
170         }
171 }