* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
package org.onap.policy.pap.xacml.rest.components;
+import com.att.research.xacml.api.pap.PAPException;
+import com.att.research.xacml.std.IdentifierImpl;
+
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
-import org.apache.commons.io.FilenameUtils;
-import org.onap.policy.common.logging.eelf.MessageCodes;
-import org.onap.policy.common.logging.eelf.PolicyLogger;
-import org.onap.policy.common.logging.flexlogger.FlexLogger;
-import org.onap.policy.common.logging.flexlogger.Logger;
-import org.onap.policy.rest.adapter.PolicyRestAdapter;
-
-import com.att.research.xacml.api.pap.PAPException;
-import com.att.research.xacml.std.IdentifierImpl;
-
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
+
+import org.apache.commons.io.FilenameUtils;
+import org.onap.policy.common.logging.eelf.MessageCodes;
+import org.onap.policy.common.logging.eelf.PolicyLogger;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.rest.adapter.PolicyRestAdapter;
public class ClosedLoopPolicy extends Policy {
super();
}
- public ClosedLoopPolicy(PolicyRestAdapter policyAdapter){
+ public ClosedLoopPolicy(PolicyRestAdapter policyAdapter) {
this.policyAdapter = policyAdapter;
}
- //save configuration of the policy based on the policyname
+ // save configuration of the policy based on the policyname
private void saveConfigurations(String policyName, String jsonBody) {
- if(policyName.endsWith(".xml")){
- policyName = policyName.replace(".xml", "");
- }
- try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator+ policyName +".json")){
+ if (policyName.endsWith(".xml")) {
+ policyName = policyName.replace(".xml", "");
+ }
+ try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".json")) {
String body = jsonBody;
- //Remove the trapMaxAge in Verification Signature
+ // Remove the trapMaxAge in Verification Signature
body = body.replace(",\"trapMaxAge\":null", "");
this.policyAdapter.setJsonBody(body);
out.println(body);
} catch (Exception e) {
- LOGGER.error("Exception Occured while writing Configuration Data"+e);
+ LOGGER.error("Exception Occured while writing Configuration Data" + e);
}
}
- //Utility to read json data from the existing file to a string
+ // Utility to read json data from the existing file to a string
static String readFile(String path, Charset encoding) throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
}
- //create the configuration file based on the policy name on adding the extension as .json
+ // create the configuration file based on the policy name on adding the extension as .json
private String getConfigFile(String filename) {
filename = FilenameUtils.removeExtension(filename);
if (filename.endsWith(".xml")) {
public Map<String, String> savePolicies() throws PAPException {
Map<String, String> successMap = new HashMap<>();
- if(isPolicyExists()){
+ if (isPolicyExists()) {
successMap.put("EXISTS", "This Policy already exist on the PAP");
return successMap;
}
- if(!isPreparedToSave()){
+ if (!isPreparedToSave()) {
prepareToSave();
}
Path newPolicyPath = null;
newPolicyPath = Paths.get(policyAdapter.getNewFileName());
- successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());
+ successMap = createPolicy(newPolicyPath, getCorrectPolicyDataObject());
return successMap;
}
- //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
+ // 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 PAPException{
+ public boolean prepareToSave() throws PAPException {
- if(isPreparedToSave()){
- //we have already done this
+ if (isPreparedToSave()) {
+ // we have already done this
return true;
}
AllOfType allOfOne = new AllOfType();
String fileName = policyAdapter.getNewFileName();
- String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
+ String name = fileName.substring(fileName.lastIndexOf("\\") + 1);
if ((name == null) || (name.equals(""))) {
- name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
+ name = fileName.substring(fileName.lastIndexOf("/") + 1);
}
allOfOne.getMatch().add(createMatch("PolicyName", name));
AllOfType allOf = new AllOfType();
// Match for Onap
allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
// Match for riskType
- allOf.getMatch().add(
- createDynamicMatch("RiskType", policyAdapter.getRiskType()));
+ allOf.getMatch().add(createDynamicMatch("RiskType", policyAdapter.getRiskType()));
// Match for riskLevel
- allOf.getMatch().add(
- createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
+ allOf.getMatch().add(createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
// Match for riskguard
- allOf.getMatch().add(
- createDynamicMatch("guard", policyAdapter.getGuard()));
+ allOf.getMatch().add(createDynamicMatch("guard", policyAdapter.getGuard()));
// Match for ttlDate
- allOf.getMatch().add(
- createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
+ allOf.getMatch().add(createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
AnyOfType anyOf = new AnyOfType();
anyOf.getAllOf().add(allOfOne);
try {
accessURI = new URI(ACTION_ID);
} catch (URISyntaxException e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateClosedLoopPolicy", "Exception creating ACCESS URI");
+ PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateClosedLoopPolicy",
+ "Exception creating ACCESS URI");
}
accessAttributeDesignator.setCategory(CATEGORY_ACTION);
accessAttributeDesignator.setDataType(STRING_DATATYPE);
try {
closedURI = new URI(RESOURCE_ID);
} catch (URISyntaxException e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateClosedLoopPolicy", "Exception creating closed URI");
+ PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateClosedLoopPolicy",
+ "Exception creating closed URI");
}
closedAttributeDesignator.setCategory(CATEGORY_RESOURCE);
closedAttributeDesignator.setDataType(STRING_DATATYPE);
AttributeValueType AttributeValue = new AttributeValueType();
AttributeValue.setDataType(URI_DATATYPE);
- String content = CONFIG_URL +"/Config/" + getConfigFile(policyName);
+ String content = CONFIG_URL + "/Config/" + getConfigFile(policyName);
System.out.println("URL value :" + content);
AttributeValue.getContent().add(content);
assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
attributeValue3.setDataType(STRING_DATATYPE);
fileName = FilenameUtils.removeExtension(fileName);
fileName = fileName + ".xml";
- String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
+ String name = fileName.substring(fileName.lastIndexOf("\\") + 1);
if ((name == null) || (name.equals(""))) {
- name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
+ name = fileName.substring(fileName.lastIndexOf("/") + 1);
}
attributeValue3.getContent().add(name);
assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
advice.getAttributeAssignmentExpression().add(assignment5);
- //Risk Attributes
+ // Risk Attributes
AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
assignment6.setAttributeId("RiskType");
assignment6.setCategory(CATEGORY_RESOURCE);
advice.getAttributeAssignmentExpression().add(assignment9);
-
-
advices.getAdviceExpression().add(advice);
return advices;
}
return policyAdapter.getPolicyData();
}
-
}