2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia 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;
26 import com.google.gson.JsonObject;
27 import com.google.gson.annotations.Expose;
29 import java.io.UnsupportedEncodingException;
31 import javax.persistence.Column;
32 import javax.persistence.FetchType;
33 import javax.persistence.JoinColumn;
34 import javax.persistence.ManyToOne;
35 import javax.persistence.MappedSuperclass;
37 import org.hibernate.annotations.Type;
38 import org.hibernate.annotations.TypeDef;
39 import org.hibernate.annotations.TypeDefs;
40 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
41 import org.onap.clamp.loop.common.AuditEntity;
42 import org.onap.clamp.loop.template.LoopElementModel;
45 @TypeDefs({@TypeDef(name = "json", typeClass = StringJsonUserType.class)})
46 public abstract class Policy extends AuditEntity {
50 @Column(columnDefinition = "json", name = "json_representation", nullable = false)
51 private JsonObject jsonRepresentation;
55 @Column(columnDefinition = "json", name = "configurations_json")
56 private JsonObject configurationsJson;
59 * This attribute can be null when the user add a policy on the loop instance, not the template.
60 * When null, It therefore indicates that this policy is not by default in the loop template.
63 @ManyToOne(fetch = FetchType.EAGER)
64 @JoinColumn(name = "loop_element_model_id")
65 private LoopElementModel loopElementModel;
68 @Column(name = "pdp_group")
69 private String pdpGroup;
72 @Column(name = "pdp_sub_group")
73 private String pdpSubgroup;
75 public abstract String createPolicyPayload() throws UnsupportedEncodingException;
82 public abstract String getName();
87 public abstract void setName(String name);
90 * jsonRepresentation getter.
92 * @return the jsonRepresentation
94 public JsonObject getJsonRepresentation() {
95 return jsonRepresentation;
99 * jsonRepresentation setter.
101 * @param jsonRepresentation The jsonRepresentation to set
103 public void setJsonRepresentation(JsonObject jsonRepresentation) {
104 this.jsonRepresentation = jsonRepresentation;
108 * configurationsJson getter.
110 * @return The configurationsJson
112 public JsonObject getConfigurationsJson() {
113 return configurationsJson;
117 * configurationsJson setter.
119 * @param configurationsJson the configurationsJson to set
121 public void setConfigurationsJson(JsonObject configurationsJson) {
122 this.configurationsJson = configurationsJson;
126 * loopElementModel getter.
128 * @return the loopElementModel
130 public LoopElementModel getLoopElementModel() {
131 return loopElementModel;
135 * loopElementModel setter.
137 * @param loopElementModel the loopElementModel to set
139 public void setLoopElementModel(LoopElementModel loopElementModel) {
140 this.loopElementModel = loopElementModel;
146 * @return the pdpGroup
148 public String getPdpGroup() {
155 * @param pdpGroup the pdpGroup to set
157 public void setPdpGroup(String pdpGroup) {
158 this.pdpGroup = pdpGroup;
162 * pdpSubgroup getter.
164 * @return the pdpSubgroup
166 public String getPdpSubgroup() {
171 * pdpSubgroup setter.
173 * @param pdpSubgroup the pdpSubgroup to set
175 public void setPdpSubgroup(String pdpSubgroup) {
176 this.pdpSubgroup = pdpSubgroup;
180 * Generate the policy name.
182 * @param policyType The policy type
183 * @param serviceName The service name
184 * @param serviceVersion The service version
185 * @param resourceName The resource name
186 * @param blueprintFilename The blueprint file name
187 * @return The generated policy name
189 public static String generatePolicyName(String policyType, String serviceName, String serviceVersion,
190 String resourceName, String blueprintFilename) {
191 StringBuilder buffer = new StringBuilder(policyType).append("_").append(serviceName).append("_v")
192 .append(serviceVersion).append("_").append(resourceName).append("_")
193 .append(blueprintFilename.replaceAll(".yaml", ""));
194 return buffer.toString().replace('.', '_').replaceAll(" ", "");