c5946c9db2fd6a8aff3e0b29cb5aaeb817f00a5e
[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.annotations.Expose;
27 import com.vladmihalcea.hibernate.type.json.JsonStringType;
28
29 import java.io.Serializable;
30 import java.util.HashSet;
31 import java.util.Map;
32 import java.util.Set;
33
34 import javax.persistence.CascadeType;
35 import javax.persistence.Column;
36 import javax.persistence.Entity;
37 import javax.persistence.EnumType;
38 import javax.persistence.Enumerated;
39 import javax.persistence.FetchType;
40 import javax.persistence.Id;
41 import javax.persistence.JoinColumn;
42 import javax.persistence.JoinTable;
43 import javax.persistence.ManyToMany;
44 import javax.persistence.OneToMany;
45 import javax.persistence.Table;
46
47 import org.hibernate.annotations.Type;
48 import org.hibernate.annotations.TypeDef;
49
50 @Entity
51 @Table(name = "loops")
52 //@JsonAdapter(JsonLoopAdapter.class)
53 @TypeDef(name = "json", typeClass = JsonStringType.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 = "svg_representation")
76     private String svgRepresentation;
77
78     @Expose
79     @Type(type = "json")
80     @Column(columnDefinition = "json", name = "global_properties_json")
81     private Map<String, Object> globalPropertiesJson;
82
83     @Expose
84     @Column(nullable = false, name = "blueprint_yaml")
85     private String blueprint;
86
87     @Expose
88     @Column(nullable = false, name = "last_computed_state")
89     @Enumerated(EnumType.STRING)
90     private LoopState lastComputedState;
91
92     @Expose
93     @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
94     private Set<OperationalPolicy> operationalPolicies = new HashSet<>();
95
96     @Expose
97     @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
98     @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"), inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
99     private Set<MicroServicePolicy> microServicePolicies = new HashSet<>();
100
101     @Expose
102     @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
103     private Set<LoopLog> loopLogs = new HashSet<>();
104
105     public String getName() {
106         return name;
107     }
108
109     public void setName(String name) {
110         this.name = name;
111     }
112
113     public String getDcaeDeploymentId() {
114         return dcaeDeploymentId;
115     }
116
117     public void setDcaeDeploymentId(String dcaeDeploymentId) {
118         this.dcaeDeploymentId = dcaeDeploymentId;
119     }
120
121     public String getDcaeDeploymentStatusUrl() {
122         return dcaeDeploymentStatusUrl;
123     }
124
125     public void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
126         this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
127     }
128
129     public String getSvgRepresentation() {
130         return svgRepresentation;
131     }
132
133     public void setSvgRepresentation(String svgRepresentation) {
134         this.svgRepresentation = svgRepresentation;
135     }
136
137     public String getBlueprint() {
138         return blueprint;
139     }
140
141     public void setBlueprint(String blueprint) {
142         this.blueprint = blueprint;
143     }
144
145     public LoopState getLastComputedState() {
146         return lastComputedState;
147     }
148
149     public void setLastComputedState(LoopState lastComputedState) {
150         this.lastComputedState = lastComputedState;
151     }
152
153     public Set<OperationalPolicy> getOperationalPolicies() {
154         return operationalPolicies;
155     }
156
157     public void setOperationalPolicies(Set<OperationalPolicy> operationalPolicies) {
158         this.operationalPolicies = operationalPolicies;
159     }
160
161     public Set<MicroServicePolicy> getMicroServicePolicies() {
162         return microServicePolicies;
163     }
164
165     public void setMicroServicePolicies(Set<MicroServicePolicy> microServicePolicies) {
166         this.microServicePolicies = microServicePolicies;
167     }
168
169     public Map<String, Object> getGlobalPropertiesJson() {
170         return globalPropertiesJson;
171     }
172
173     public void setGlobalPropertiesJson(Map<String, Object> globalPropertiesJson) {
174         this.globalPropertiesJson = globalPropertiesJson;
175     }
176
177     public Set<LoopLog> getLoopLogs() {
178         return loopLogs;
179     }
180
181     public void setLoopLogs(Set<LoopLog> loopLogs) {
182         this.loopLogs = loopLogs;
183     }
184
185     public void addOperationalPolicy(OperationalPolicy opPolicy) {
186         opPolicy.setLoop(this);
187         operationalPolicies.add(opPolicy);
188     }
189
190     public void addMicroServicePolicy(MicroServicePolicy microServicePolicy) {
191         microServicePolicies.add(microServicePolicy);
192         microServicePolicy.getUsedByLoops().add(this);
193     }
194
195     public void addLog(LoopLog log) {
196         loopLogs.add(log);
197         log.setLoop(this);
198     }
199
200     @Override
201     public int hashCode() {
202         final int prime = 31;
203         int result = 1;
204         result = prime * result + ((name == null) ? 0 : name.hashCode());
205         return result;
206     }
207
208     @Override
209     public boolean equals(Object obj) {
210         if (this == obj)
211             return true;
212         if (obj == null)
213             return false;
214         if (getClass() != obj.getClass())
215             return false;
216         Loop other = (Loop) obj;
217         if (name == null) {
218             if (other.name != null)
219                 return false;
220         } else if (!name.equals(other.name))
221             return false;
222         return true;
223     }
224
225 }