aboutsummaryrefslogtreecommitdiffstats
path: root/applications/guard/src/main/java/org
diff options
context:
space:
mode:
authorMichael Mokry <michael.mokry@att.com>2019-04-15 12:47:46 -0500
committerJoshua Reich <jreich@research.att.com>2019-04-15 14:20:11 -0700
commitb8f82899e1d5777fc4db912d1dc4030aa7e6d99d (patch)
tree2a35c23cacbecb5324905e2127e7e223fb63b533 /applications/guard/src/main/java/org
parent7a0772a0f09b4aeef7b91cb04bdefaf49e7bdc38 (diff)
Fix a couple of sonar issues one blocker
1. fixed nullpointer blocker issue in CoordinationGuardTranslator.java 2. fixed "log or rethrow exception" critical issue 3. throw exceptions instead of returning null values Change-Id: I2d567fe566c6f761ec2699016c4a868f203c9a01 Issue-ID: POLICY-1451 Signed-off-by: Michael Mokry <michael.mokry@att.com> Signed-off-by: Joshua Reich <jreich@research.att.com>
Diffstat (limited to 'applications/guard/src/main/java/org')
-rw-r--r--applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java30
1 files changed, 14 insertions, 16 deletions
diff --git a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java
index 10456e9f..41c1428e 100644
--- a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java
+++ b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java
@@ -67,7 +67,6 @@ public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
//
// Policy name should be at the root
//
- String policyName = toscaPolicy.getMetadata().get("policy-id");
String type = toscaPolicy.getType();
String coordinationFunctionPath = "src/main/resources/coordination/function";
Map<String, Object> policyProps = toscaPolicy.getProperties();
@@ -78,17 +77,19 @@ public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
cd.setCoordinationFunction(type);
cd.setControlLoop(controlLoop);
LOGGER.debug("CoordinationDirective = {}", cd);
-
+ //
+ // Generate the xacml policy as a string
+ //
String xacmlStr = generateXacmlFromCoordinationDirective(cd, coordinationFunctionPath);
-
LOGGER.debug("xacmlStr\n{}", xacmlStr);
- PolicyType scannedPolicy = null;
+ //
+ // Scan the string and convert to PoilcyType
+ //
try (InputStream is = new ByteArrayInputStream(xacmlStr.getBytes(StandardCharsets.UTF_8))) {
- scannedPolicy = (PolicyType) XACMLPolicyScanner.readPolicy(is);
+ return (PolicyType) XACMLPolicyScanner.readPolicy(is);
} catch (IOException e) {
- LOGGER.error("Failed to read policy", e);
+ throw new ToscaPolicyConversionException("Failed to read policy", e);
}
- return scannedPolicy;
}
@Override
@@ -99,7 +100,7 @@ public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
@Override
public DecisionResponse convertResponse(Response xacmlResponse) {
- LOGGER.info("this convertRequest shouldn't be used");
+ LOGGER.info("this convertResponse shouldn't be used");
return null;
}
@@ -117,9 +118,7 @@ public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
//
Yaml yaml = new Yaml(new Constructor(CoordinationDirective.class));
Object obj = yaml.load(contents);
-
LOGGER.debug(contents);
-
return (CoordinationDirective) obj;
} catch (IOException e) {
LOGGER.error("Error while loading YAML coordination directive", e);
@@ -135,7 +134,7 @@ public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
* @return the generated Xacml policy
*/
public static String generateXacmlFromCoordinationDirective(CoordinationDirective cd,
- String protoDir) {
+ String protoDir) throws ToscaPolicyConversionException {
/*
* Determine file names
*/
@@ -148,18 +147,17 @@ public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
final String cLOne = cd.getControlLoop(0);
final String cLTwo = cd.getControlLoop(1);
/*
- * Replace prototype placeholders with appropriate values
+ * Replace function placeholders with appropriate values
*/
- String xacmlPolicy = null;
try (Stream<String> stream = Files.lines(Paths.get(xacmlProtoFilename))) {
- xacmlPolicy = stream.map(s -> s.replaceAll("UNIQUE_ID", uniqueId))
+ return stream.map(s -> s.replaceAll("UNIQUE_ID", uniqueId))
.map(s -> s.replaceAll("CONTROL_LOOP_ONE", cLOne))
.map(s -> s.replaceAll("CONTROL_LOOP_TWO", cLTwo))
.collect(Collectors.joining(System.lineSeparator()));
} catch (IOException e) {
- LOGGER.error("Error while generating XACML policy for coordination directive", e);
+ throw new
+ ToscaPolicyConversionException("Error while generating XACML policy for coordination directive", e);
}
- return xacmlPolicy;
}
}