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 @ManyToOne(fetch = FetchType.EAGER)
60 @JoinColumn(name = "loop_element_model_id")
61 private LoopElementModel loopElementModel;
64 @Column(name = "pdp_group")
65 private String pdpGroup;
67 public abstract String createPolicyPayload() throws UnsupportedEncodingException;
74 public abstract String getName();
80 public abstract void setName(String name);
83 * jsonRepresentation getter.
85 * @return the jsonRepresentation
87 public JsonObject getJsonRepresentation() {
88 return jsonRepresentation;
92 * jsonRepresentation setter.
94 * @param jsonRepresentation The jsonRepresentation to set
96 public void setJsonRepresentation(JsonObject jsonRepresentation) {
97 this.jsonRepresentation = jsonRepresentation;
101 * configurationsJson getter.
103 * @return The configurationsJson
105 public JsonObject getConfigurationsJson() {
106 return configurationsJson;
110 * configurationsJson setter.
112 * @param configurationsJson the configurationsJson to set
114 public void setConfigurationsJson(JsonObject configurationsJson) {
115 this.configurationsJson = configurationsJson;
119 * loopElementModel getter.
121 * @return the loopElementModel
123 public LoopElementModel getLoopElementModel() {
124 return loopElementModel;
128 * loopElementModel setter.
130 * @param loopElementModel the loopElementModel to set
132 public void setLoopElementModel(LoopElementModel loopElementModel) {
133 this.loopElementModel = loopElementModel;
139 * @return the pdpGroup
141 public String getPdpGroup() {
148 * @param pdpGroup the pdpGroup to set
150 public void setPdpGroup(String pdpGroup) {
151 this.pdpGroup = pdpGroup;
155 * Generate the policy name.
157 * @param policyType The policy type
158 * @param serviceName The service name
159 * @param serviceVersion The service version
160 * @param resourceName The resource name
161 * @param blueprintFilename The blueprint file name
162 * @return The generated policy name
164 public static String generatePolicyName(String policyType, String serviceName, String serviceVersion,
165 String resourceName, String blueprintFilename) {
166 StringBuilder buffer = new StringBuilder(policyType).append("_").append(serviceName).append("_v")
167 .append(serviceVersion).append("_").append(resourceName).append("_")
168 .append(blueprintFilename.replaceAll(".yaml", ""));
169 return buffer.toString().replace('.', '_').replaceAll(" ", "");