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;
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;
private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceConfigPolicy.class);
private static Map<String, String> mapAttribute = new HashMap<>();
- private static Map<String, String> matchMap = new HashMap<>();
+ private static Map<String, String> mapMatch = new HashMap<>();
+
+ private static synchronized Map<String, String> getMatchMap () {
+ return mapMatch;
+ }
+
+ private static synchronized void setMatchMap(Map<String, String> mm) {
+ mapMatch = mm;
+ }
public MicroServiceConfigPolicy() {
super();
@Override
- public Map<String, String> savePolicies() throws Exception {
+ public Map<String, String> savePolicies() throws PAPException {
Map<String, String> successMap = new HashMap<>();
if(isPolicyExists()){
//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
//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<String, String> 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
assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
advice.getAttributeAssignmentExpression().add(assignment7);
-
+
+ Map<String, String> matchMap = getMatchMap();
if (matchMap==null || matchMap.isEmpty()){
AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
assignment6.setAttributeId("matching:" + CONFIGID);