X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fpolicy%2FPolicy.java;h=abb16d73f26df26a2e543251f6a6abeeeb1dc420;hb=c405a83ec84c2bc1c090f06f9ac6207469e09cbb;hp=ebeb84fd6827b02a20ebfdad4363f859de85498b;hpb=5c6d23852ea949335eb7f85d787eb24ac6dbab2a;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 ebeb84fd..abb16d73 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.UnsupportedEncodingException; import java.util.Map; import javax.persistence.Column; @@ -44,6 +43,7 @@ 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.ToscaConverterWithDictionarySupport; import org.onap.clamp.dao.model.jsontype.StringJsonUserType; import org.onap.clamp.loop.common.AuditEntity; import org.onap.clamp.loop.template.LoopElementModel; @@ -97,13 +97,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. * @@ -129,17 +122,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; @@ -176,6 +167,13 @@ 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 + */ + public abstract void updateJsonRepresentation(ToscaConverterWithDictionarySupport toscaConverter); + /** * policyModel getter. * @@ -283,5 +281,4 @@ public abstract class Policy extends AuditEntity { .append(blueprintFilename.replaceAll(".yaml", "")); return buffer.toString().replace('.', '_').replaceAll(" ", ""); } - }