Merge "Extract modules names and relations"
[clamp.git] / src / main / java / org / onap / clamp / policy / operational / OperationalPolicy.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.operational;
25
26 import com.google.gson.JsonObject;
27 import com.google.gson.annotations.Expose;
28 import java.io.Serializable;
29
30 import javax.persistence.Column;
31 import javax.persistence.Convert;
32 import javax.persistence.Entity;
33 import javax.persistence.FetchType;
34 import javax.persistence.Id;
35 import javax.persistence.JoinColumn;
36 import javax.persistence.ManyToOne;
37 import javax.persistence.Table;
38 import org.hibernate.annotations.Type;
39 import org.hibernate.annotations.TypeDef;
40 import org.hibernate.annotations.TypeDefs;
41 import org.onap.clamp.loop.Loop;
42 import org.onap.clamp.policy.Policy;
43 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
44
45 @Entity
46 @Table(name = "operational_policies")
47 @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
48 public class OperationalPolicy implements Serializable, Policy {
49     /**
50      *
51      */
52     private static final long serialVersionUID = 6117076450841538255L;
53
54     @Id
55     @Expose
56     @Column(nullable = false, name = "name", unique = true)
57     private String name;
58
59     @Expose
60     @Type(type = "json")
61     @Column(columnDefinition = "json", name = "configurations_json")
62     private JsonObject configurationsJson;
63
64     @ManyToOne(fetch = FetchType.LAZY)
65     @JoinColumn(name = "loop_id", nullable = false)
66     private Loop loop;
67
68     public OperationalPolicy() {
69         //Serialization
70     }
71
72     public OperationalPolicy(String name, Loop loop, JsonObject configurationsJson) {
73         this.name = name;
74         this.loop = loop;
75         this.configurationsJson = configurationsJson;
76     }
77
78     public String getName() {
79         return name;
80     }
81
82     public void setLoop(Loop loopName) {
83         this.loop = loopName;
84     }
85
86     public Loop getLoop(){
87         return loop;
88     }
89
90     @Override
91     public JsonObject getJsonRepresentation() {
92         return configurationsJson;
93     }
94
95     public JsonObject getConfigurationsJson() {
96         return configurationsJson;
97     }
98
99     public void setConfigurationsJson(JsonObject configurationsJson) {
100         this.configurationsJson = configurationsJson;
101     }
102
103     @Override
104     public int hashCode() {
105         final int prime = 31;
106         int result = 1;
107         result = prime * result + ((name == null) ? 0 : name.hashCode());
108         return result;
109     }
110
111     @Override
112     public boolean equals(Object obj) {
113         if (this == obj)
114             return true;
115         if (obj == null)
116             return false;
117         if (getClass() != obj.getClass())
118             return false;
119         OperationalPolicy other = (OperationalPolicy) obj;
120         if (name == null) {
121             if (other.name != null)
122                 return false;
123         } else if (!name.equals(other.name))
124             return false;
125         return true;
126     }
127
128 }