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;
71 public abstract String createPolicyPayload() throws UnsupportedEncodingException;
78 public abstract String getName();
83 public abstract void setName(String name);
86 * jsonRepresentation getter.
88 * @return the jsonRepresentation
90 public JsonObject getJsonRepresentation() {
91 return jsonRepresentation;
95 * jsonRepresentation setter.
97 * @param jsonRepresentation The jsonRepresentation to set
99 public void setJsonRepresentation(JsonObject jsonRepresentation) {
100 this.jsonRepresentation = jsonRepresentation;
104 * configurationsJson getter.
106 * @return The configurationsJson
108 public JsonObject getConfigurationsJson() {
109 return configurationsJson;
113 * configurationsJson setter.
115 * @param configurationsJson the configurationsJson to set
117 public void setConfigurationsJson(JsonObject configurationsJson) {
118 this.configurationsJson = configurationsJson;
122 * loopElementModel getter.
124 * @return the loopElementModel
126 public LoopElementModel getLoopElementModel() {
127 return loopElementModel;
131 * loopElementModel setter.
133 * @param loopElementModel the loopElementModel to set
135 public void setLoopElementModel(LoopElementModel loopElementModel) {
136 this.loopElementModel = loopElementModel;
142 * @return the pdpGroup
144 public String getPdpGroup() {
151 * @param pdpGroup the pdpGroup to set
153 public void setPdpGroup(String pdpGroup) {
154 this.pdpGroup = pdpGroup;
158 * Generate the policy name.
160 * @param policyType The policy type
161 * @param serviceName The service name
162 * @param serviceVersion The service version
163 * @param resourceName The resource name
164 * @param blueprintFilename The blueprint file name
165 * @return The generated policy name
167 public static String generatePolicyName(String policyType, String serviceName, String serviceVersion,
168 String resourceName, String blueprintFilename) {
169 StringBuilder buffer = new StringBuilder(policyType).append("_").append(serviceName).append("_v")
170 .append(serviceVersion).append("_").append(resourceName).append("_")
171 .append(blueprintFilename.replaceAll(".yaml", ""));
172 return buffer.toString().replace('.', '_').replaceAll(" ", "");