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