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.clds.tosca.ToscaYamlToJsonConvertor;
43 import org.onap.clamp.clds.util.JsonUtils;
44 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
45 import org.onap.clamp.loop.Loop;
46 import org.onap.clamp.policy.Policy;
49 @Table(name = "micro_service_policies")
50 @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
51 public class MicroServicePolicy implements Serializable, Policy {
55 private static final long serialVersionUID = 6271238288583332616L;
59 @Column(nullable = false, name = "name", unique = true)
64 @Column(columnDefinition = "json", name = "properties")
65 private JsonObject properties;
68 @Column(name = "shared", nullable = false)
69 private Boolean shared;
71 @Column(columnDefinition = "MEDIUMTEXT", name = "policy_tosca", nullable = false)
72 private String policyTosca;
76 @Column(columnDefinition = "json", name = "json_representation", nullable = false)
77 private JsonObject jsonRepresentation;
79 @ManyToMany(mappedBy = "microServicePolicies")
80 private Set<Loop> usedByLoops = new HashSet<>();
82 public MicroServicePolicy() {
86 public MicroServicePolicy(String name, String policyTosca, Boolean shared, Set<Loop> usedByLoops) {
88 this.policyTosca = policyTosca;
90 this.jsonRepresentation = JsonUtils.GSON_JPA_MODEL
91 .fromJson(new ToscaYamlToJsonConvertor(null).parseToscaYaml(policyTosca), JsonObject.class);
92 this.usedByLoops = usedByLoops;
95 public MicroServicePolicy(String name, String policyTosca, Boolean shared, JsonObject jsonRepresentation,
96 Set<Loop> usedByLoops) {
98 this.policyTosca = policyTosca;
100 this.usedByLoops = usedByLoops;
101 this.jsonRepresentation = jsonRepresentation;
105 public String getName() {
109 public JsonObject getProperties() {
113 public void setProperties(JsonObject properties) {
114 this.properties = properties;
117 public Boolean getShared() {
121 public void setShared(Boolean shared) {
122 this.shared = shared;
125 public String getPolicyTosca() {
129 public void setPolicyTosca(String policyTosca) {
130 this.policyTosca = policyTosca;
134 public JsonObject getJsonRepresentation() {
135 return jsonRepresentation;
138 public void setJsonRepresentation(JsonObject jsonRepresentation) {
139 this.jsonRepresentation = jsonRepresentation;
142 public Set<Loop> getUsedByLoops() {
146 public void setUsedByLoops(Set<Loop> usedBy) {
147 this.usedByLoops = usedBy;
151 public int hashCode() {
152 final int prime = 31;
154 result = prime * result + ((name == null) ? 0 : name.hashCode());
159 public boolean equals(Object obj) {
164 if (getClass() != obj.getClass())
166 MicroServicePolicy other = (MicroServicePolicy) obj;
168 if (other.name != null)
170 } else if (!name.equals(other.name))