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 {
53 * The serial version ID.
55 private static final long serialVersionUID = 6271238288583332616L;
59 @Column(nullable = false, name = "name", unique = true)
63 @Column(nullable = false, name = "model_type")
64 private String modelType;
67 @Column(nullable = false, name = "blueprint_name")
68 private String blueprintName;
72 @Column(columnDefinition = "json", name = "properties")
73 private JsonObject properties;
76 @Column(name = "shared", nullable = false)
77 private Boolean shared;
79 @Column(columnDefinition = "MEDIUMTEXT", name = "policy_tosca", nullable = false)
80 private String policyTosca;
84 @Column(columnDefinition = "json", name = "json_representation", nullable = false)
85 private JsonObject jsonRepresentation;
87 @ManyToMany(mappedBy = "microServicePolicies")
88 private Set<Loop> usedByLoops = new HashSet<>();
90 public MicroServicePolicy() {
96 * @param name The name of the MicroService
97 * @param type The model type of the MicroService
98 * @param blueprintName The name in the blueprint
99 * @param policyTosca The policy Tosca of the MicroService
100 * @param shared The flag indicate whether the MicroService is shared
101 * @param usedByLoops The list of loops that uses this MicroService
103 public MicroServicePolicy(String name, String modelType, String policyTosca, Boolean shared, Set<Loop> usedByLoops, String blueprintName) {
105 this.modelType = modelType;
106 this.policyTosca = policyTosca;
107 this.shared = shared;
108 this.jsonRepresentation = JsonUtils.GSON_JPA_MODEL
109 .fromJson(new ToscaYamlToJsonConvertor(null).parseToscaYaml(policyTosca), JsonObject.class);
110 this.usedByLoops = usedByLoops;
111 this.blueprintName = blueprintName;
116 * @param name The name of the MicroService
117 * @param type The model type of the MicroService
118 * @param blueprintName The name in the blueprint
119 * @param policyTosca The policy Tosca of the MicroService
120 * @param shared The flag indicate whether the MicroService is shared
121 * @param jsonRepresentation The UI representation in json format
122 * @param usedByLoops The list of loops that uses this MicroService
124 public MicroServicePolicy(String name, String modelType, String policyTosca, Boolean shared, JsonObject jsonRepresentation,
125 Set<Loop> usedByLoops, String blueprintName) {
127 this.modelType = modelType;
128 this.policyTosca = policyTosca;
129 this.shared = shared;
130 this.usedByLoops = usedByLoops;
131 this.jsonRepresentation = jsonRepresentation;
132 this.blueprintName = blueprintName;
136 public String getName() {
140 public String getModelType() {
144 public String getBlueprintName() {
145 return blueprintName;
148 public JsonObject getProperties() {
152 public void setProperties(JsonObject properties) {
153 this.properties = properties;
156 public Boolean getShared() {
160 public void setShared(Boolean shared) {
161 this.shared = shared;
164 public String getPolicyTosca() {
168 public void setPolicyTosca(String policyTosca) {
169 this.policyTosca = policyTosca;
173 public JsonObject getJsonRepresentation() {
174 return jsonRepresentation;
177 public void setJsonRepresentation(JsonObject jsonRepresentation) {
178 this.jsonRepresentation = jsonRepresentation;
181 public Set<Loop> getUsedByLoops() {
185 public void setUsedByLoops(Set<Loop> usedBy) {
186 this.usedByLoops = usedBy;
190 public int hashCode() {
191 final int prime = 31;
193 result = prime * result + ((name == null) ? 0 : name.hashCode());
198 public boolean equals(Object obj) {
205 if (getClass() != obj.getClass()) {
208 MicroServicePolicy other = (MicroServicePolicy) obj;
210 if (other.name != null) {
213 } else if (!name.equals(other.name)) {