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;fp=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcomponents%2FMicroServiceConfigPolicy.java;h=b0e48a7f4c75693cf68a1abca63ebf1943e655f0;hb=24c6b1682bb59691f8d5e631b1074355b7d82a54;hp=b45d2941a67d33d7d51ab0a908651e7da512733a;hpb=461b2b7eeca1586423349bc0c4c65f80f027292d;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 b45d2941a..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; @@ -100,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()){ @@ -125,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 @@ -172,26 +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); - } - Map matchMap = null; - if (matching != null && !matching.isEmpty()){ - matchMap = Splitter.on(",").withKeyValueSeparator("=").split(matching); - setMatchMap(matchMap); - if(policyAdapter.getJsonBody() != null){ - pullMatchValue(rootNode); + 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