2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.policy.microservice;
26 import com.google.gson.JsonObject;
27 import com.google.gson.annotations.Expose;
29 import java.io.Serializable;
30 import java.util.HashSet;
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;
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 import org.onap.clamp.loop.Loop;
44 import org.onap.clamp.policy.Policy;
47 @Table(name = "micro_service_policies")
48 @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
49 public class MicroServicePolicy implements Serializable, Policy {
53 private static final long serialVersionUID = 6271238288583332616L;
57 @Column(nullable = false, name = "name", unique = true)
62 @Column(columnDefinition = "json", name = "properties")
63 private JsonObject properties;
66 @Column(name = "shared", nullable = false)
67 private Boolean shared;
69 @Column(name = "policy_tosca", nullable = false)
70 private String policyTosca;
74 @Column(columnDefinition = "json", name = "json_representation", nullable = false)
75 private JsonObject jsonRepresentation;
77 @ManyToMany(mappedBy = "microServicePolicies")
78 private Set<Loop> usedByLoops = new HashSet<>();
80 public MicroServicePolicy() {
84 public MicroServicePolicy(String name, String policyTosca, Boolean shared, JsonObject jsonRepresentation,
85 Set<Loop> usedByLoops) {
87 this.policyTosca = policyTosca;
89 this.jsonRepresentation = jsonRepresentation;
90 this.usedByLoops = usedByLoops;
94 public String getName() {
98 public JsonObject getProperties() {
102 public void setProperties(JsonObject properties) {
103 this.properties = properties;
106 public Boolean getShared() {
110 public void setShared(Boolean shared) {
111 this.shared = shared;
114 public String getPolicyTosca() {
118 public void setPolicyTosca(String policyTosca) {
119 this.policyTosca = policyTosca;
123 public JsonObject getJsonRepresentation() {
124 return jsonRepresentation;
127 public void setJsonRepresentation(JsonObject jsonRepresentation) {
128 this.jsonRepresentation = jsonRepresentation;
131 public Set<Loop> getUsedByLoops() {
135 public void setUsedByLoops(Set<Loop> usedBy) {
136 this.usedByLoops = usedBy;
140 public int hashCode() {
141 final int prime = 31;
143 result = prime * result + ((name == null) ? 0 : name.hashCode());
148 public boolean equals(Object obj) {
153 if (getClass() != obj.getClass())
155 MicroServicePolicy other = (MicroServicePolicy) obj;
157 if (other.name != null)
159 } else if (!name.equals(other.name))