Modify the template model
[clamp.git] / src / main / java / org / onap / clamp / policy / Policy.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 Nokia Intellectual Property. All rights
6  *                             reserved.
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.policy;
25
26 import com.google.gson.JsonObject;
27 import com.google.gson.annotations.Expose;
28
29 import java.io.UnsupportedEncodingException;
30
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;
36
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;
43
44 @MappedSuperclass
45 @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
46 public abstract class Policy extends AuditEntity {
47
48     @Expose
49     @Type(type = "json")
50     @Column(columnDefinition = "json", name = "json_representation", nullable = false)
51     private JsonObject jsonRepresentation;
52
53     @Expose
54     @Type(type = "json")
55     @Column(columnDefinition = "json", name = "configurations_json")
56     private JsonObject configurationsJson;
57
58     @Expose
59     @ManyToOne(fetch = FetchType.EAGER)
60     @JoinColumn(name = "loop_element_model_id")
61     private LoopElementModel loopElementModel;
62
63     @Expose
64     @Column(name = "pdp_group")
65     private String pdpGroup;
66
67     public abstract String createPolicyPayload() throws UnsupportedEncodingException;
68
69     /**
70      * Name getter.
71      * 
72      * @return the name
73      */
74     public abstract String getName();
75
76     /**
77      * Name setter.
78      * 
79      */
80     public abstract void setName(String name);
81
82     /**
83      * jsonRepresentation getter.
84      * 
85      * @return the jsonRepresentation
86      */
87     public JsonObject getJsonRepresentation() {
88         return jsonRepresentation;
89     }
90
91     /**
92      * jsonRepresentation setter.
93      * 
94      * @param jsonRepresentation The jsonRepresentation to set
95      */
96     public void setJsonRepresentation(JsonObject jsonRepresentation) {
97         this.jsonRepresentation = jsonRepresentation;
98     }
99
100     /**
101      * configurationsJson getter.
102      * 
103      * @return The configurationsJson
104      */
105     public JsonObject getConfigurationsJson() {
106         return configurationsJson;
107     }
108
109     /**
110      * configurationsJson setter.
111      * 
112      * @param configurationsJson the configurationsJson to set
113      */
114     public void setConfigurationsJson(JsonObject configurationsJson) {
115         this.configurationsJson = configurationsJson;
116     }
117
118     /**
119      * loopElementModel getter.
120      * 
121      * @return the loopElementModel
122      */
123     public LoopElementModel getLoopElementModel() {
124         return loopElementModel;
125     }
126
127     /**
128      * loopElementModel setter.
129      * 
130      * @param loopElementModel the loopElementModel to set
131      */
132     public void setLoopElementModel(LoopElementModel loopElementModel) {
133         this.loopElementModel = loopElementModel;
134     }
135
136     /**
137      * pdpGroup getter.
138      * 
139      * @return the pdpGroup
140      */
141     public String getPdpGroup() {
142         return pdpGroup;
143     }
144
145     /**
146      * pdpGroup setter.
147      * 
148      * @param pdpGroup the pdpGroup to set
149      */
150     public void setPdpGroup(String pdpGroup) {
151         this.pdpGroup = pdpGroup;
152     }
153
154     /**
155      * Generate the policy name.
156      *
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
163      */
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(" ", "");
170     }
171
172 }