ba2c442c776ce97ed7418a8f805aa6faae438fcb
[clamp.git] / src / main / java / org / onap / clamp / dao / model / 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.dao.model;
25
26 import com.google.gson.JsonObject;
27 import com.google.gson.annotations.Expose;
28
29 import java.io.Serializable;
30
31 import javax.persistence.Column;
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
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 = "operational_policies")
46 @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
47 public class OperationalPolicy implements Serializable {
48     /**
49      *
50      */
51     private static final long serialVersionUID = 6117076450841538255L;
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 = "configurations_json")
61     private JsonObject configurationsJson;
62
63     @ManyToOne(fetch = FetchType.LAZY)
64     @JoinColumn(name = "loop_id", nullable = false)
65     private Loop loop;
66
67     public Loop getLoop() {
68         return loop;
69     }
70
71     public void setLoop(Loop loop) {
72         this.loop = loop;
73     }
74
75     public String getName() {
76         return name;
77     }
78
79     public void setName(String name) {
80         this.name = name;
81     }
82
83     public JsonObject getConfigurationsJson() {
84         return configurationsJson;
85     }
86
87     public void setConfigurationsJson(JsonObject configurationsJson) {
88         this.configurationsJson = configurationsJson;
89     }
90
91     @Override
92     public int hashCode() {
93         final int prime = 31;
94         int result = 1;
95         result = prime * result + ((name == null) ? 0 : name.hashCode());
96         return result;
97     }
98
99     @Override
100     public boolean equals(Object obj) {
101         if (this == obj)
102             return true;
103         if (obj == null)
104             return false;
105         if (getClass() != obj.getClass())
106             return false;
107         OperationalPolicy other = (OperationalPolicy) obj;
108         if (name == null) {
109             if (other.name != null)
110                 return false;
111         } else if (!name.equals(other.name))
112             return false;
113         return true;
114     }
115
116 }