X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcomponents%2FMicroServiceConfigPolicy.java;h=b0e48a7f4c75693cf68a1abca63ebf1943e655f0;hb=24c6b1682bb59691f8d5e631b1074355b7d82a54;hp=0297f30c068a86db188289ae8ed4cac05520e928;hpb=073cc188efe9abb4c010cf674e34e2cf46ef1c52;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java index 0297f30c0..b0e48a7f4 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java @@ -21,6 +21,7 @@ package org.onap.policy.pap.xacml.rest.components; import java.io.File; +import java.io.IOException; import java.io.PrintWriter; import java.net.URI; import java.net.URISyntaxException; @@ -42,6 +43,7 @@ import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl; import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.jpa.MicroServiceModels; +import com.att.research.xacml.api.pap.PAPException; import com.att.research.xacml.std.IdentifierImpl; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -66,7 +68,15 @@ public class MicroServiceConfigPolicy extends Policy { private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceConfigPolicy.class); private static Map mapAttribute = new HashMap<>(); - private static Map matchMap = new HashMap<>(); + private static Map mapMatch = new HashMap<>(); + + private static synchronized Map getMatchMap () { + return mapMatch; + } + + private static synchronized void setMatchMap(Map mm) { + mapMatch = mm; + } public MicroServiceConfigPolicy() { super(); @@ -92,7 +102,7 @@ public class MicroServiceConfigPolicy extends Policy { @Override - public Map savePolicies() throws Exception { + public Map savePolicies() throws PAPException { Map successMap = new HashMap<>(); if(isPolicyExists()){ @@ -117,7 +127,7 @@ public class MicroServiceConfigPolicy extends Policy { //This is the method for preparing the policy for saving. We have broken it out //separately because the fully configured policy is used for multiple things @Override - public boolean prepareToSave() throws Exception{ + public boolean prepareToSave() throws PAPException{ if(isPreparedToSave()){ //we have already done this @@ -164,24 +174,28 @@ public class MicroServiceConfigPolicy extends Policy { //setup values for pulling out matching attributes ObjectMapper mapper = new ObjectMapper(); - JsonNode rootNode = mapper.readTree(policyAdapter.getJsonBody()); String matching = null; - - if (policyAdapter.getTtlDate()==null){ - policyAdapter.setTtlDate("NA"); - } - if (policyAdapter.getServiceType().contains("-v")){ - matching = getValueFromDictionary(policyAdapter.getServiceType()); - } else { - String jsonVersion = StringUtils.replaceEach(rootNode.get("version").toString(), new String[]{"\""}, new String[]{""}); - matching = getValueFromDictionary(policyAdapter.getServiceType() + "-v" + jsonVersion); - } - - if (matching != null && !matching.isEmpty()){ - matchMap = Splitter.on(",").withKeyValueSeparator("=").split(matching); - if(policyAdapter.getJsonBody() != null){ - pullMatchValue(rootNode); + Map matchMap = null; + try { + JsonNode rootNode = mapper.readTree(policyAdapter.getJsonBody()); + if (policyAdapter.getTtlDate()==null){ + policyAdapter.setTtlDate("NA"); + } + if (policyAdapter.getServiceType().contains("-v")){ + matching = getValueFromDictionary(policyAdapter.getServiceType()); + } else { + String jsonVersion = StringUtils.replaceEach(rootNode.get("version").toString(), new String[]{"\""}, new String[]{""}); + matching = getValueFromDictionary(policyAdapter.getServiceType() + "-v" + jsonVersion); + } + if (matching != null && !matching.isEmpty()){ + matchMap = Splitter.on(",").withKeyValueSeparator("=").split(matching); + setMatchMap(matchMap); + if(policyAdapter.getJsonBody() != null){ + pullMatchValue(rootNode); + } } + } catch (IOException e1) { + throw new PAPException(e1); } // Match for policyName @@ -422,7 +436,8 @@ public class MicroServiceConfigPolicy extends Policy { assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7)); advice.getAttributeAssignmentExpression().add(assignment7); - + + Map matchMap = getMatchMap(); if (matchMap==null || matchMap.isEmpty()){ AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType(); assignment6.setAttributeId("matching:" + CONFIGID);