78175cc52d97801fd6bc68bcaa35cab1060a3190
[clamp.git] / src / main / java / org / onap / clamp / dao / model / Loop.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.dao.model;
25
26 import com.google.gson.JsonObject;
27 import com.google.gson.annotations.Expose;
28
29 import java.io.Serializable;
30 import java.util.HashSet;
31 import java.util.Set;
32
33 import javax.persistence.CascadeType;
34 import javax.persistence.Column;
35 import javax.persistence.Entity;
36 import javax.persistence.EnumType;
37 import javax.persistence.Enumerated;
38 import javax.persistence.FetchType;
39 import javax.persistence.Id;
40 import javax.persistence.JoinColumn;
41 import javax.persistence.JoinTable;
42 import javax.persistence.ManyToMany;
43 import javax.persistence.OneToMany;
44 import javax.persistence.Table;
45
46 import org.hibernate.annotations.Type;
47 import org.hibernate.annotations.TypeDef;
48 import org.hibernate.annotations.TypeDefs;
49 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
50
51 @Entity
52 @Table(name = "loops")
53 @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
54 public class Loop implements Serializable {
55
56     /**
57      *
58      */
59     private static final long serialVersionUID = -286522707701388642L;
60
61     @Id
62     @Expose
63     @Column(nullable = false, name = "name", unique = true)
64     private String name;
65
66     @Expose
67     @Column(name = "dcae_deployment_id")
68     private String dcaeDeploymentId;
69
70     @Expose
71     @Column(name = "dcae_deployment_status_url")
72     private String dcaeDeploymentStatusUrl;
73
74     @Expose
75     @Column(name = "dcae_blueprint_id")
76     private String dcaeBlueprintId;
77
78     @Expose
79     @Column(name = "svg_representation")
80     private String svgRepresentation;
81
82     @Expose
83     @Type(type = "json")
84     @Column(columnDefinition = "json", name = "global_properties_json")
85     private JsonObject globalPropertiesJson;
86
87     @Expose
88     @Column(nullable = false, name = "blueprint_yaml")
89     private String blueprint;
90
91     @Expose
92     @Column(nullable = false, name = "last_computed_state")
93     @Enumerated(EnumType.STRING)
94     private LoopState lastComputedState;
95
96     @Expose
97     @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
98     private Set<OperationalPolicy> operationalPolicies = new HashSet<>();
99
100     @Expose
101     @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
102     @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"), inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
103     private Set<MicroServicePolicy> microServicePolicies = new HashSet<>();
104
105     @Expose
106     @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
107     private Set<LoopLog> loopLogs = new HashSet<>();
108
109     public String getName() {
110         return name;
111     }
112
113     public void setName(String name) {
114         this.name = name;
115     }
116
117     public String getDcaeDeploymentId() {
118         return dcaeDeploymentId;
119     }
120
121     public void setDcaeDeploymentId(String dcaeDeploymentId) {
122         this.dcaeDeploymentId = dcaeDeploymentId;
123     }
124
125     public String getDcaeDeploymentStatusUrl() {
126         return dcaeDeploymentStatusUrl;
127     }
128
129     public void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
130         this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
131     }
132
133     public String getSvgRepresentation() {
134         return svgRepresentation;
135     }
136
137     public void setSvgRepresentation(String svgRepresentation) {
138         this.svgRepresentation = svgRepresentation;
139     }
140
141     public String getBlueprint() {
142         return blueprint;
143     }
144
145     public void setBlueprint(String blueprint) {
146         this.blueprint = blueprint;
147     }
148
149     public LoopState getLastComputedState() {
150         return lastComputedState;
151     }
152
153     public void setLastComputedState(LoopState lastComputedState) {
154         this.lastComputedState = lastComputedState;
155     }
156
157     public Set<OperationalPolicy> getOperationalPolicies() {
158         return operationalPolicies;
159     }
160
161     public void setOperationalPolicies(Set<OperationalPolicy> operationalPolicies) {
162         this.operationalPolicies = operationalPolicies;
163     }
164
165     public Set<MicroServicePolicy> getMicroServicePolicies() {
166         return microServicePolicies;
167     }
168
169     public void setMicroServicePolicies(Set<MicroServicePolicy> microServicePolicies) {
170         this.microServicePolicies = microServicePolicies;
171     }
172
173     public JsonObject getGlobalPropertiesJson() {
174         return globalPropertiesJson;
175     }
176
177     public void setGlobalPropertiesJson(JsonObject globalPropertiesJson) {
178         this.globalPropertiesJson = globalPropertiesJson;
179     }
180
181     public Set<LoopLog> getLoopLogs() {
182         return loopLogs;
183     }
184
185     public void setLoopLogs(Set<LoopLog> loopLogs) {
186         this.loopLogs = loopLogs;
187     }
188
189     public void addOperationalPolicy(OperationalPolicy opPolicy) {
190         opPolicy.setLoop(this);
191         operationalPolicies.add(opPolicy);
192     }
193
194     public void addMicroServicePolicy(MicroServicePolicy microServicePolicy) {
195         microServicePolicies.add(microServicePolicy);
196         microServicePolicy.getUsedByLoops().add(this);
197     }
198
199     public void addLog(LoopLog log) {
200         loopLogs.add(log);
201         log.setLoop(this);
202     }
203
204     public String getDcaeBlueprintId() {
205         return dcaeBlueprintId;
206     }
207
208     public void setDcaeBlueprintId(String dcaeBlueprintId) {
209         this.dcaeBlueprintId = dcaeBlueprintId;
210     }
211
212     @Override
213     public int hashCode() {
214         final int prime = 31;
215         int result = 1;
216         result = prime * result + ((name == null) ? 0 : name.hashCode());
217         return result;
218     }
219
220     @Override
221     public boolean equals(Object obj) {
222         if (this == obj)
223             return true;
224         if (obj == null)
225             return false;
226         if (getClass() != obj.getClass())
227             return false;
228         Loop other = (Loop) obj;
229         if (name == null) {
230             if (other.name != null)
231                 return false;
232         } else if (!name.equals(other.name))
233             return false;
234         return true;
235     }
236
237 }