Merge "Extract modules names and relations"
[clamp.git] / src / main / java / org / onap / clamp / policy / microservice / MicroServicePolicy.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.policy.microservice;
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.Column;
34 import javax.persistence.Entity;
35 import javax.persistence.Id;
36 import javax.persistence.ManyToMany;
37 import javax.persistence.Table;
38
39 import org.hibernate.annotations.Type;
40 import org.hibernate.annotations.TypeDef;
41 import org.hibernate.annotations.TypeDefs;
42 import org.onap.clamp.loop.Loop;
43 import org.onap.clamp.policy.Policy;
44 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
45
46 @Entity
47 @Table(name = "micro_service_policies")
48 @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
49 public class MicroServicePolicy implements Serializable, Policy {
50     /**
51      *
52      */
53     private static final long serialVersionUID = 6271238288583332616L;
54
55     @Expose
56     @Id
57     @Column(nullable = false, name = "name", unique = true)
58     private String name;
59
60     @Expose
61     @Type(type = "json")
62     @Column(columnDefinition = "json", name = "properties")
63     private JsonObject properties;
64
65     @Expose
66     @Column(name = "shared", nullable = false)
67     private Boolean shared;
68
69     @Expose
70     @Column(name = "policy_tosca", nullable = false)
71     private String policyTosca;
72
73     @Expose
74     @Type(type = "json")
75     @Column(columnDefinition = "json", name = "json_representation", nullable = false)
76     private JsonObject jsonRepresentation;
77
78     @ManyToMany(mappedBy = "microServicePolicies")
79     private Set<Loop> usedByLoops = new HashSet<>();
80
81     public MicroServicePolicy() {
82         //serialization
83     }
84
85     public MicroServicePolicy(String name, String policyTosca, Boolean shared, JsonObject jsonRepresentation,
86         Set<Loop> usedByLoops) {
87         this.name = name;
88         this.policyTosca = policyTosca;
89         this.shared = shared;
90         this.jsonRepresentation = jsonRepresentation;
91         this.usedByLoops = usedByLoops;
92     }
93
94     public String getName() {
95         return name;
96     }
97
98     public JsonObject getProperties() {
99         return properties;
100     }
101
102     public void setProperties(JsonObject properties) {
103         this.properties = properties;
104     }
105
106     public Boolean getShared() {
107         return shared;
108     }
109
110     public void setShared(Boolean shared) {
111         this.shared = shared;
112     }
113
114     public String getPolicyTosca() {
115         return policyTosca;
116     }
117
118     public void setPolicyTosca(String policyTosca) {
119         this.policyTosca = policyTosca;
120     }
121
122     public JsonObject getJsonRepresentation() {
123         return jsonRepresentation;
124     }
125
126     public void setJsonRepresentation(JsonObject jsonRepresentation) {
127         this.jsonRepresentation = jsonRepresentation;
128     }
129
130     public Set<Loop> getUsedByLoops() {
131         return usedByLoops;
132     }
133
134     public void setUsedByLoops(Set<Loop> usedBy) {
135         this.usedByLoops = usedBy;
136     }
137
138     @Override
139     public int hashCode() {
140         final int prime = 31;
141         int result = 1;
142         result = prime * result + ((name == null) ? 0 : name.hashCode());
143         return result;
144     }
145
146     @Override
147     public boolean equals(Object obj) {
148         if (this == obj)
149             return true;
150         if (obj == null)
151             return false;
152         if (getClass() != obj.getClass())
153             return false;
154         MicroServicePolicy other = (MicroServicePolicy) obj;
155         if (name == null) {
156             if (other.name != null)
157                 return false;
158         } else if (!name.equals(other.name))
159             return false;
160         return true;
161     }
162
163 }