summaryrefslogtreecommitdiffstats
path: root/applications/common/src
diff options
context:
space:
mode:
Diffstat (limited to 'applications/common/src')
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java17
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java18
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java4
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java30
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java11
5 files changed, 65 insertions, 15 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java
index 508bc245..34936b06 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -22,6 +22,7 @@
package org.onap.policy.pdp.xacml.application.common.std;
+import com.att.research.xacml.api.Advice;
import com.att.research.xacml.api.Decision;
import com.att.research.xacml.api.Obligation;
import com.att.research.xacml.api.Request;
@@ -92,6 +93,10 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
// Go through obligations
//
scanObligations(xacmlResult.getObligations(), decisionResponse);
+ //
+ // Go through advice
+ //
+ scanAdvice(xacmlResult.getAssociatedAdvice(), decisionResponse);
} else {
//
// TODO we have to return an ErrorResponse object instead
@@ -114,6 +119,16 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
protected abstract void scanObligations(Collection<Obligation> obligations, DecisionResponse decisionResponse);
/**
+ * scanAdvice - scans the list of advice and make appropriate call to process the advice. This method
+ * can be overridden for each specific application as advice may have different expected attributes per
+ * application.
+ *
+ * @param advice Collection of Advice objects
+ * @param decisionResponse DecisionResponse object used to store any results from advice.
+ */
+ protected abstract void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse);
+
+ /**
* From the TOSCA metadata section, pull in values that are needed into the XACML policy.
*
* @param policy Policy Object to store the metadata
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java
index bcd594fb..0a1ace2b 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -22,6 +22,7 @@
package org.onap.policy.pdp.xacml.application.common.std;
+import com.att.research.xacml.api.Advice;
import com.att.research.xacml.api.DataTypeException;
import com.att.research.xacml.api.Identifier;
import com.att.research.xacml.api.Obligation;
@@ -158,6 +159,21 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator {
}
/**
+ * scanAdvice - not implemented in this class.
+ *
+ * @param advice Collection of advice objects
+ * @param DecisionResponse DecisionResponse object
+ */
+ @Override
+ protected void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse) {
+ //
+ // By default there are no advice supported in this object. Please override and provide
+ // any needed functionality.
+ //
+ LOGGER.warn("Advice found - not supported in this class {}", this.getClass());
+ }
+
+ /**
* scanContentObligation - scans the specific obligation for policy-id and policy-content.
*
* @param obligation Obligation incoming obligation object
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java
index 2d83b897..2cb82942 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -92,7 +92,7 @@ public class StdMatchablePolicyRequest {
}
/**
- * Parses the DecisionRequest into a MonitoringRequest.
+ * Parses the DecisionRequest into a XAML request.
*
* @param decisionRequest Input DecisionRequest
* @return Request XACML Request object
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
index 0d1daaa6..e84a9e77 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
@@ -22,6 +22,7 @@
package org.onap.policy.pdp.xacml.application.common.std;
+import com.att.research.xacml.api.Advice;
import com.att.research.xacml.api.Identifier;
import com.att.research.xacml.api.Obligation;
import com.att.research.xacml.api.Request;
@@ -84,6 +85,10 @@ public class StdMatchableTranslator extends StdBaseTranslator {
private static final Logger LOGGER = LoggerFactory.getLogger(StdMatchableTranslator.class);
private static final StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
+ private static final String MSG_WEIGHT = "Weight is {}";
+ private static final String MSG_WEIGHT_LIST = "Weight list is {}";
+ private static final String MSG_WEIGHT_MAP = "Weight map is {}";
+
private final Map<ToscaPolicyTypeIdentifier, ToscaServiceTemplate> matchablePolicyTypes = new HashMap<>();
@Setter
private RestServerParameters apiRestParameters;
@@ -155,6 +160,10 @@ public class StdMatchableTranslator extends StdBaseTranslator {
);
}
+ protected void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse) {
+ LOGGER.warn("scanAdvice not supported by {}", this.getClass());
+ }
+
/**
* scanClosestMatchObligation - scans for the obligation specifically holding policy
* contents and their details.
@@ -384,7 +393,7 @@ public class StdMatchableTranslator extends StdBaseTranslator {
//
int weight = generateMatchable(targetType, entrySet.getKey(), entrySet.getValue(),
property.getLeft(), property.getRight());
- LOGGER.info("Weight is {}", weight);
+ LOGGER.info(MSG_WEIGHT, weight);
totalWeight += weight;
} else {
//
@@ -394,12 +403,12 @@ public class StdMatchableTranslator extends StdBaseTranslator {
if ("list".equals(toscaProperty.getType())) {
int weight = findMatchablesInList(entrySet.getKey(), entrySet.getValue(), toscaProperty,
policyTemplate, targetType);
- LOGGER.info("Weight list is {}", weight);
+ LOGGER.info(MSG_WEIGHT_LIST, weight);
totalWeight += weight;
} else if ("map".equals(toscaProperty.getType())) {
int weight = findMatchablesInMap(entrySet.getKey(), entrySet.getValue(), toscaProperty,
policyTemplate, targetType);
- LOGGER.info("Weight map is {}", weight);
+ LOGGER.info(MSG_WEIGHT_MAP, weight);
totalWeight += weight;
}
}
@@ -460,7 +469,7 @@ public class StdMatchableTranslator extends StdBaseTranslator {
//
int weight = generateMatchable(targetType, entrySet.getKey(), entrySet.getValue(),
toscaProperty, listTemplate);
- LOGGER.info("Weight is {}", weight);
+ LOGGER.info(MSG_WEIGHT, weight);
totalWeight += weight;
} else {
//
@@ -470,12 +479,12 @@ public class StdMatchableTranslator extends StdBaseTranslator {
if ("list".equals(toscaProperty.getType())) {
int weight = findMatchablesInList(entrySet.getKey(), entrySet.getValue(), toscaProperty,
listTemplate, targetType);
- LOGGER.info("Weight list is {}", weight);
+ LOGGER.info(MSG_WEIGHT_LIST, weight);
totalWeight += weight;
} else if ("map".equals(toscaProperty.getType())) {
int weight = findMatchablesInMap(entrySet.getKey(), entrySet.getValue(), toscaProperty,
listTemplate, targetType);
- LOGGER.info("Weight map is {}", weight);
+ LOGGER.info(MSG_WEIGHT_MAP, weight);
totalWeight += weight;
}
}
@@ -529,7 +538,7 @@ public class StdMatchableTranslator extends StdBaseTranslator {
//
int weight = generateMatchable(targetType, entrySet.getKey(), entrySet.getValue(),
toscaProperty, mapTemplate);
- LOGGER.info("Weight is {}", weight);
+ LOGGER.info(MSG_WEIGHT, weight);
totalWeight += weight;
} else {
//
@@ -539,12 +548,12 @@ public class StdMatchableTranslator extends StdBaseTranslator {
if ("list".equals(toscaProperty.getType())) {
int weight = findMatchablesInList(entrySet.getKey(), entrySet.getValue(), toscaProperty,
mapTemplate, targetType);
- LOGGER.info("Weight list is {}", weight);
+ LOGGER.info(MSG_WEIGHT_LIST, weight);
totalWeight += weight;
} else if ("map".equals(toscaProperty.getType())) {
int weight = findMatchablesInMap(entrySet.getKey(), entrySet.getValue(), toscaProperty,
mapTemplate, targetType);
- LOGGER.info("Weight map is {}", weight);
+ LOGGER.info(MSG_WEIGHT_MAP, weight);
totalWeight += weight;
}
}
@@ -721,7 +730,8 @@ public class StdMatchableTranslator extends StdBaseTranslator {
int weight = 0;
if (isYamlType(toscaProperty.getEntrySchema().getType())) {
//
- // PLD TODO - this won't work
+ // PLD TODO - this won't work. Right now there are no maps being used to match.
+ // need to investigate whether we really can support that situation.
//
AnyOfType anyOf = generateMatches((Collection<Object>) value,
new IdentifierImpl(ToscaDictionary.ID_RESOURCE_MATCHABLE + key));
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java
index a7391fab..8039a9cf 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import com.att.research.xacml.api.Advice;
import com.att.research.xacml.api.AttributeAssignment;
import com.att.research.xacml.api.Decision;
import com.att.research.xacml.api.IdReference;
@@ -249,6 +250,10 @@ public class StdBaseTranslatorTest {
protected void scanObligations(Collection<Obligation> obligations, DecisionResponse decisionResponse) {
}
+ @Override
+ protected void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse) {
+ }
+
}
private class TestTranslator extends StdBaseTranslator {
@@ -259,6 +264,10 @@ public class StdBaseTranslatorTest {
}
@Override
+ protected void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse) {
+ }
+
+ @Override
public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
PolicyType xacmlPolicy = new PolicyType();
this.fillMetadataSection(xacmlPolicy, metadata);