X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FCreateClosedLoopPMController.java;h=058542590a9ca547c6293a035f2a72a0f51664a5;hp=4862efd06766c6f25b6e5070b78d884925e5cf30;hb=1e61676b77dd09659027b8984f050df7e8538526;hpb=b831c6a3df8e1dc9017ae5e8ad002dc3b1002aab diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java index 4862efd06..058542590 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java @@ -52,33 +52,35 @@ public class CreateClosedLoopPMController { protected PolicyRestAdapter policyAdapter = null; + /** + * prePopulateClosedLoopPMPolicyData. + * + * @param policyAdapter PolicyRestAdapter + * @param entity PolicyEntity + */ public void prePopulateClosedLoopPMPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { - if (policyAdapter.getPolicyData() instanceof PolicyType) { - Object policyData = policyAdapter.getPolicyData(); - PolicyType policy = (PolicyType) policyData; + if (! (policyAdapter.getPolicyData() instanceof PolicyType)) { + return; + } + Object policyData = policyAdapter.getPolicyData(); + PolicyType policy = (PolicyType) policyData; - // Set oldPolicyFileName to PolicyAdapter - policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); + // Set oldPolicyFileName to PolicyAdapter + policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); - // Set policyNameValue and description to PolicyAdapter - setPolicyAdapterNameValueAndDescription(policyAdapter, policy); + // Set policyNameValue and description to PolicyAdapter + setPolicyAdapterNameValueAndDescription(policyAdapter, policy); - // Set PolicyAdapter JsonBodyData - setClosedLoopJSONFile(policyAdapter, entity); + // Set PolicyAdapter JsonBodyData + setClosedLoopJsonFile(policyAdapter, entity); - // Get the target data under policy. - TargetType target = policy.getTarget(); - if (target == null) { - return; - } - // Under target we have AnyOFType - List anyOfList = target.getAnyOf(); - if (anyOfList == null) { - return; - } - // Set PolicyAdapter OnapNameField, riskType, riskLevel, guard, ttlDate, ServiceType from match attributes - setPolicyAdapterMatchAttributes(policyAdapter, anyOfList); + // Get the target data under policy. + TargetType target = policy.getTarget(); + if (target == null) { + return; } + // Set PolicyAdapter OnapNameField, riskType, riskLevel, guard, ttlDate, ServiceType from match attributes + setPolicyAdapterMatchAttributes(policyAdapter, target.getAnyOf()); } private void setPolicyAdapterNameValueAndDescription(PolicyRestAdapter policyAdapter, PolicyType policy) { @@ -95,11 +97,10 @@ public class CreateClosedLoopPMController { policyAdapter.setPolicyDescription(description); } - private void setClosedLoopJSONFile(PolicyRestAdapter policyAdapter, PolicyEntity entity) { - ObjectMapper mapper = new ObjectMapper(); + private void setClosedLoopJsonFile(PolicyRestAdapter policyAdapter, PolicyEntity entity) { try { ClosedLoopPMBody closedLoopBody = - mapper.readValue(entity.getConfigurationData().getConfigBody(), ClosedLoopPMBody.class); + new ObjectMapper().readValue(entity.getConfigurationData().getConfigBody(), ClosedLoopPMBody.class); policyAdapter.setJsonBodyData(closedLoopBody); } catch (IOException e) { LOGGER.error("Exception Occured" + e); @@ -121,19 +122,8 @@ public class CreateClosedLoopPMController { AttributeDesignatorType designator = match.getAttributeDesignator(); String attributeId = designator.getAttributeId(); // First match in the target is OnapName, so set that value. - if ("ONAPName".equals(attributeId)) { - policyAdapter.setOnapName(value); - } else if ("RiskType".equals(attributeId)) { - policyAdapter.setRiskType(value); - } else if ("RiskLevel".equals(attributeId)) { - policyAdapter.setRiskLevel(value); - } else if ("guard".equals(attributeId)) { - policyAdapter.setGuard(value); - } else if ("TTLDate".equals(attributeId) && !value.contains("NA")) { - PolicyController controller = new PolicyController(); - String newDate = controller.convertDate(value); - policyAdapter.setTtlDate(newDate); - } else if ("ServiceType".equals(attributeId)) { + policyAdapter.setupUsingAttribute(attributeId, value); + if ("ServiceType".equals(attributeId)) { LinkedHashMap serviceTypePolicyName1 = new LinkedHashMap<>(); serviceTypePolicyName1.put(KEY_SERVICE_TYPE_POLICY_NAME, value); policyAdapter.setServiceTypePolicyName(serviceTypePolicyName1);