X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fpolicy%2FPolicy.java;h=d84f2c8a07a053ca93228b6cad2b5422d3bf8c36;hb=f01d3e8377fa4e5a9c1b129fe446575d132f91c2;hp=d52e418e3ca7373858ada0050a8a3aa0984602b3;hpb=3af9347e47302e3f6754cba8ea2b63772980a5d9;p=clamp.git diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java index d52e418e..d84f2c8a 100644 --- a/src/main/java/org/onap/clamp/policy/Policy.java +++ b/src/main/java/org/onap/clamp/policy/Policy.java @@ -30,7 +30,6 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; -import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.Map; import javax.persistence.Column; @@ -44,11 +43,10 @@ import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDefs; import org.json.JSONObject; -import org.onap.clamp.clds.tosca.update.TemplateManagement; -import org.onap.clamp.clds.tosca.update.UnknownComponentException; -import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport; import org.onap.clamp.dao.model.jsontype.StringJsonUserType; import org.onap.clamp.loop.common.AuditEntity; +import org.onap.clamp.loop.service.Service; import org.onap.clamp.loop.template.LoopElementModel; import org.onap.clamp.loop.template.PolicyModel; import org.yaml.snakeyaml.Yaml; @@ -100,13 +98,6 @@ public abstract class Policy extends AuditEntity { return new Gson().fromJson(jsonObject.toString(), JsonObject.class); } - private String getModelPropertyNameFromTosca(JsonObject object, String policyModelType) { - return object.getAsJsonObject("policy_types").getAsJsonObject(policyModelType) - .getAsJsonObject( - "properties") - .keySet().toArray(new String[1])[0]; - } - /** * This method create the policy payload that must be sent to PEF. * @@ -132,17 +123,15 @@ public abstract class Policy extends AuditEntity { JsonObject policyDetails = new JsonObject(); thisPolicy.add(this.getName(), policyDetails); policyDetails.addProperty("type", this.getPolicyModel().getPolicyModelType()); + policyDetails.addProperty("type_version", this.getPolicyModel().getVersion()); policyDetails.addProperty("version", this.getPolicyModel().getVersion()); JsonObject policyMetadata = new JsonObject(); policyDetails.add("metadata", policyMetadata); policyMetadata.addProperty("policy-id", this.getName()); - JsonObject policyProperties = new JsonObject(); - policyDetails.add("properties", policyProperties); - policyProperties - .add(this.getModelPropertyNameFromTosca(toscaJson, this.getPolicyModel().getPolicyModelType()), - this.getConfigurationsJson()); + policyDetails.add("properties", this.getConfigurationsJson()); + String policyPayload = new GsonBuilder().setPrettyPrinting().create().toJson(policyPayloadResult); logger.info("Policy payload: " + policyPayload); return policyPayload; @@ -179,6 +168,15 @@ public abstract class Policy extends AuditEntity { this.jsonRepresentation = jsonRepresentation; } + /** + * Regenerate the Policy Json Representation. + * + * @param toscaConverter The tosca converter required to regenerate the json schema + * @param serviceModel The service model associated + */ + public abstract void updateJsonRepresentation(ToscaConverterWithDictionarySupport toscaConverter, + Service serviceModel); + /** * policyModel getter. * @@ -286,23 +284,4 @@ public abstract class Policy extends AuditEntity { .append(blueprintFilename.replaceAll(".yaml", "")); return buffer.toString().replace('.', '_').replaceAll(" ", ""); } - - /** - * This method can be used to generate the json Schema used by the UI. - * - * @param policyToscaModel The tosca model as String that must be converted - * @param policyModelType The tosca model type (the policy_type entry in the tosca) that will used to create the - * json schema - * @return THe Json Schema as JsonObject - * @throws IOException In case of failure when opening the templates.json file - * @throws UnknownComponentException If the policyModelType is not found in the tosca model - */ - public static JsonObject generateJsonRepresentationFromToscaModel(String policyToscaModel, - String policyModelType) - throws IOException, UnknownComponentException { - return new TemplateManagement(policyToscaModel,ResourceFileUtil.getResourceAsString( - "clds/tosca_update/defaultToscaTypes.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")) - .launchTranslation(policyModelType); - } }