aboutsummaryrefslogtreecommitdiffstats
path: root/applications/common/src/main/java/org/onap
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2024-07-24 21:09:09 +0100
committeradheli.tavares <adheli.tavares@est.tech>2024-07-24 21:09:54 +0100
commit257358ffc369e0813bca5fa92b83710e3d97cfee (patch)
tree3bc494df192dc38fadc2e225cd8b09c88dd4884d /applications/common/src/main/java/org/onap
parent66b1f3ead4f08893da0ea50aad25cd4831367b3c (diff)
Convert unit tests from junit4 to junit5
Issue-ID: POLICY-5094 Change-Id: Id727408a5fd553aa08623a6ede1a56607b760e3f Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'applications/common/src/main/java/org/onap')
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCaller.java19
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyConversionException.java4
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java21
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java64
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyType.java8
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeBoolean.java6
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeFloat.java8
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeInteger.java6
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeList.java5
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeTimestamp.java4
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java65
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyRequest.java21
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java21
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java47
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java23
15 files changed, 162 insertions, 160 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCaller.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCaller.java
index 2ccc694a..b8e1aa67 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCaller.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCaller.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021,2023 Nordix Foundation.
+ * Modifications Copyright (C) 2021, 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory;
* Methods to access policy-api via REST service calls.
*/
public class PolicyApiCaller {
- private static Logger logger = LoggerFactory.getLogger(PolicyApiCaller.class);
+ private static final Logger logger = LoggerFactory.getLogger(PolicyApiCaller.class);
private static final String POLICY_TYPE_URI = "/policy/api/v1/policytypes/";
private static final String POLICY_TYPE_VERSION_URI = "/versions/";
@@ -60,18 +60,19 @@ public class PolicyApiCaller {
try {
Response resp = httpClient
- .get(POLICY_TYPE_URI + type.getName() + POLICY_TYPE_VERSION_URI + type.getVersion());
+ .get(POLICY_TYPE_URI + type.getName() + POLICY_TYPE_VERSION_URI + type.getVersion());
- switch (resp.getStatus()) {
- case HttpURLConnection.HTTP_OK:
- return resp.readEntity(ToscaServiceTemplate.class);
- case HttpURLConnection.HTTP_NOT_FOUND:
+ return switch (resp.getStatus()) {
+ case HttpURLConnection.HTTP_OK -> resp.readEntity(ToscaServiceTemplate.class);
+ case HttpURLConnection.HTTP_NOT_FOUND -> {
logger.warn("policy-api not found {}", resp);
throw new NotFoundException(type.toString());
- default:
+ }
+ default -> {
logger.warn("policy-api request error {}", resp);
throw new PolicyApiException(type.toString());
- }
+ }
+ };
} catch (RuntimeException e) {
logger.warn("policy-api connection error, client info: {} ", httpClient);
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyConversionException.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyConversionException.java
index 071a14e1..bf25707f 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyConversionException.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyConversionException.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,8 +23,11 @@
package org.onap.policy.pdp.xacml.application.common;
+import java.io.Serial;
+
public class ToscaPolicyConversionException extends Exception {
+ @Serial
private static final long serialVersionUID = 1L;
public ToscaPolicyConversionException() {
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java
index 0d23bc1c..9573a1b3 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -172,8 +173,8 @@ public final class ToscaPolicyTranslatorUtils {
theInt = Integer.parseInt(strInteger);
} catch (NumberFormatException e) {
try {
- Double dblLimit = Double.parseDouble(strInteger);
- theInt = dblLimit.intValue();
+ double dblLimit = Double.parseDouble(strInteger);
+ theInt = (int) dblLimit;
} catch (NumberFormatException e1) {
return null;
}
@@ -190,18 +191,18 @@ public final class ToscaPolicyTranslatorUtils {
* @return returns the given anyOf or new AnyTypeOf if null
*/
public static AnyOfType buildAndAppendAllof(AnyOfType anyOf, Object type) {
- if (type instanceof MatchType) {
+ if (type instanceof MatchType matchType) {
var allOf = new AllOfType();
- allOf.getMatch().add((MatchType) type);
+ allOf.getMatch().add(matchType);
if (anyOf == null) {
anyOf = new AnyOfType();
}
anyOf.getAllOf().add(allOf);
- } else if (type instanceof AllOfType) {
+ } else if (type instanceof AllOfType allOfType) {
if (anyOf == null) {
anyOf = new AnyOfType();
}
- anyOf.getAllOf().add((AllOfType) type);
+ anyOf.getAllOf().add(allOfType);
}
return anyOf;
@@ -215,11 +216,11 @@ public final class ToscaPolicyTranslatorUtils {
* @return TargetType
*/
public static TargetType buildAndAppendTarget(TargetType target, Object object) {
- if (object instanceof AnyOfType) {
- target.getAnyOf().add((AnyOfType) object);
- } else if (object instanceof MatchType) {
+ if (object instanceof AnyOfType anyOfType) {
+ target.getAnyOf().add(anyOfType);
+ } else if (object instanceof MatchType matchType) {
var allOf = new AllOfType();
- allOf.getMatch().add((MatchType) object);
+ allOf.getMatch().add(matchType);
var anyOf = new AnyOfType();
anyOf.getAllOf().add(allOf);
target.getAnyOf().add(anyOf);
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java
index 596a3cc6..ccd4d0de 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +39,6 @@ import java.util.Properties;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.Function;
-import java.util.stream.Collectors;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.IdReferenceType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
@@ -62,9 +62,9 @@ public final class XacmlPolicyUtils {
* file name. Does nothing for other OSs.
*/
private static final Function<String, String> SANITIZE_FILE_NAME =
- System.getProperty("os.name").startsWith("Windows")
- ? filename -> filename.replace(':', '_')
- : filename -> filename;
+ System.getProperty("os.name").startsWith("Windows")
+ ? filename -> filename.replace(':', '_')
+ : filename -> filename;
private XacmlPolicyUtils() {
super();
@@ -74,7 +74,7 @@ public final class XacmlPolicyUtils {
* Creates an empty PolicySetType object given the id and combining algorithm. Note,there
* will also be an empty Target created. You can easily override that if need be.
*
- * @param policyId Policy Id
+ * @param policyId Policy Id
* @param policyCombiningAlgorithm Policy Combining Algorithm
* @return PolicySetType object
*/
@@ -90,7 +90,7 @@ public final class XacmlPolicyUtils {
* Creates an empty PolicySetType object given the id and combining algorithm. Note,there
* will also be an empty Target created. You can easily override that if need be.
*
- * @param policyId Policy Id
+ * @param policyId Policy Id
* @param ruleCombiningAlgorithm Rule Combining Algorithm
* @return PolicyType object
*/
@@ -106,12 +106,12 @@ public final class XacmlPolicyUtils {
* This method adds a list of PolicyType objects to a root PolicySetType as
* referenced policies.
*
- * @param rootPolicy Root PolicySet being updated
+ * @param rootPolicy Root PolicySet being updated
* @param referencedPolicies A list of PolicyType being added as a references
* @return the rootPolicy PolicySet object
*/
public static PolicySetType addPoliciesToXacmlRootPolicy(PolicySetType rootPolicy,
- PolicyType... referencedPolicies) {
+ PolicyType... referencedPolicies) {
var factory = new ObjectFactory();
//
// Iterate each policy
@@ -133,12 +133,12 @@ public final class XacmlPolicyUtils {
/**
* This method updates a root PolicySetType by adding in a PolicyType as a reference.
*
- * @param rootPolicy Root PolicySet being updated
+ * @param rootPolicy Root PolicySet being updated
* @param referencedPolicySets A list of PolicySetType being added as a references
* @return the rootPolicy PolicySet object
*/
public static PolicySetType addPolicySetsToXacmlRootPolicy(PolicySetType rootPolicy,
- PolicySetType... referencedPolicySets) {
+ PolicySetType... referencedPolicySets) {
var factory = new ObjectFactory();
//
// Iterate each policy
@@ -160,7 +160,7 @@ public final class XacmlPolicyUtils {
/**
* Adds in the root policy to the PDP properties object.
*
- * @param properties Input properties
+ * @param properties Input properties
* @param rootPolicyPath Path to the root policy file
* @return Properties object
*/
@@ -187,14 +187,14 @@ public final class XacmlPolicyUtils {
// Set the new comma separated list
//
properties.setProperty(XACMLProperties.PROP_ROOTPOLICIES,
- rootPolicies.stream().collect(Collectors.joining(",")));
+ String.join(",", rootPolicies));
return properties;
}
/**
* Adds in the referenced policy to the PDP properties object.
*
- * @param properties Input properties
+ * @param properties Input properties
* @param refPolicyPath Path to the referenced policy file
* @return Properties object
*/
@@ -221,7 +221,7 @@ public final class XacmlPolicyUtils {
// Set the new comma separated list
//
properties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES,
- referencedPolicies.stream().collect(Collectors.joining(",")));
+ String.join(",", referencedPolicies));
return properties;
}
@@ -229,7 +229,7 @@ public final class XacmlPolicyUtils {
* Removes a root policy from the Properties object. Both in the line
* that identifies the policy and the .file property that points to the path.
*
- * @param properties Input Properties object to remove
+ * @param properties Input Properties object to remove
* @param rootPolicyPath The policy file path
* @return Properties object
*/
@@ -273,7 +273,7 @@ public final class XacmlPolicyUtils {
* Removes a referenced policy from the Properties object. Both in the line
* that identifies the policy and the .file property that points to the path.
*
- * @param properties Input Properties object to remove
+ * @param properties Input Properties object to remove
* @param refPolicyPath The policy file path
* @return Properties object
*/
@@ -317,7 +317,7 @@ public final class XacmlPolicyUtils {
* Does a debug dump of referenced and root policy values.
*
* @param properties Input Properties object
- * @param logger Logger object to use
+ * @param logger Logger object to use
*/
public static void debugDumpPolicyProperties(Properties properties, Logger logger) {
//
@@ -356,18 +356,18 @@ public final class XacmlPolicyUtils {
* <P>How do we track that in case we need to know what policies we have loaded?
*
* @param policy PolicyType object
- * @param path Path for policy
+ * @param path Path for policy
* @return Path unique file path for the Policy
*/
public static Path constructUniquePolicyFilename(Object policy, Path path) {
String id;
String version;
- if (policy instanceof PolicyType) {
- id = ((PolicyType) policy).getPolicyId();
- version = ((PolicyType) policy).getVersion();
- } else if (policy instanceof PolicySetType) {
- id = ((PolicySetType) policy).getPolicySetId();
- version = ((PolicySetType) policy).getVersion();
+ if (policy instanceof PolicyType policyType) {
+ id = policyType.getPolicyId();
+ version = policyType.getVersion();
+ } else if (policy instanceof PolicySetType policySetType) {
+ id = policySetType.getPolicySetId();
+ version = policySetType.getVersion();
} else {
throw new IllegalArgumentException("Must pass a PolicyType or PolicySetType");
}
@@ -435,13 +435,13 @@ public final class XacmlPolicyUtils {
* Copies a xacml.properties file to another location and all the policies defined within it.
*
* @param propertiesPath Path to an existing properties file
- * @param properties Properties object
- * @param creator A callback that can create files. Allows JUnit test to pass Temporary folder
+ * @param properties Properties object
+ * @param creator A callback that can create files. Allows JUnit test to pass Temporary folder
* @return File object that points to new Properties file
* @throws IOException Could not read/write files
*/
public static File copyXacmlPropertiesContents(String propertiesPath, Properties properties,
- FileCreator creator) throws IOException {
+ FileCreator creator) throws IOException {
//
// Open the properties file
//
@@ -516,15 +516,15 @@ public final class XacmlPolicyUtils {
/**
* Wraps the call to XACMLPolicyWriter.
*
- * @param path Path to file to be written to.
+ * @param path Path to file to be written to.
* @param policy PolicyType or PolicySetType
* @return Path - the same path passed in most likely from XACMLPolicyWriter. Or NULL if an error occurs.
*/
public static Path writePolicyFile(Path path, Object policy) {
- if (policy instanceof PolicyType) {
- return XACMLPolicyWriter.writePolicyFile(path, (PolicyType) policy);
- } else if (policy instanceof PolicySetType) {
- return XACMLPolicyWriter.writePolicyFile(path, (PolicySetType) policy);
+ if (policy instanceof PolicyType policyType) {
+ return XACMLPolicyWriter.writePolicyFile(path, policyType);
+ } else if (policy instanceof PolicySetType policySetType) {
+ return XACMLPolicyWriter.writePolicyFile(path, policySetType);
} else {
throw new IllegalArgumentException("Expecting PolicyType or PolicySetType");
}
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyType.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyType.java
index ca29c96a..f4011bd0 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyType.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyType.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2021, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,8 +69,8 @@ public class MatchablePolicyType {
);
//@formatter:on
- private ToscaConceptIdentifier policyId;
- private Map<String, MatchableProperty> matchables = new HashMap<>();
+ private final ToscaConceptIdentifier policyId;
+ private final Map<String, MatchableProperty> matchables = new HashMap<>();
public MatchablePolicyType(@NonNull ToscaPolicyType policyType, @NonNull MatchableCallback callback) {
this.policyId = new ToscaConceptIdentifier(policyType.getName(), policyType.getVersion());
@@ -119,7 +119,7 @@ public class MatchablePolicyType {
final String property = entrySet.getKey();
final var toscaProperty = entrySet.getValue();
//
- // Most likely case is its a primitive
+ // Most likely case is it's a primitive
//
if (isPrimitive(toscaProperty.getType())) {
MatchableProperty primitiveProperty = handlePrimitive(property, toscaProperty);
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeBoolean.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeBoolean.java
index 8ea65307..048d6185 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeBoolean.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeBoolean.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,8 +42,8 @@ public class MatchablePropertyTypeBoolean extends MatchablePropertyTypeBase<Bool
@Override
public Boolean validate(Object value) throws ToscaPolicyConversionException {
- if (value instanceof Boolean) {
- return (Boolean) value;
+ if (value instanceof Boolean bolValue) {
+ return bolValue;
}
return Boolean.parseBoolean(value.toString());
}
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeFloat.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeFloat.java
index bc702c1c..cac7d041 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeFloat.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeFloat.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,13 +45,13 @@ public class MatchablePropertyTypeFloat extends MatchablePropertyTypeBase<Float>
//
// Most likely it isn't because Gson does not recognize floats
//
- if (value instanceof Float) {
- return (Float) value;
+ if (value instanceof Float floatValue) {
+ return floatValue;
}
try {
return Float.parseFloat(value.toString());
} catch (NumberFormatException e) {
- throw new ToscaPolicyConversionException("Bad float value" + value.toString(), e);
+ throw new ToscaPolicyConversionException("Bad float value" + value, e);
}
}
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeInteger.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeInteger.java
index b23d344f..fc5b7fdb 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeInteger.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeInteger.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,8 +42,8 @@ public class MatchablePropertyTypeInteger extends MatchablePropertyTypeBase<Inte
@Override
public Integer validate(Object value) throws ToscaPolicyConversionException {
- if (value instanceof Integer) {
- return (Integer) value;
+ if (value instanceof Integer intValue) {
+ return intValue;
}
try {
return Integer.valueOf(value.toString());
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeList.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeList.java
index 0c42d357..24af9973 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeList.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeList.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +33,8 @@ import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionExcepti
import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslatorUtils;
public class MatchablePropertyTypeList extends MatchablePropertyTypeBase<List<MatchablePropertyType<?>>> {
- private MatchableProperty primitiveProperty;
+
+ private final MatchableProperty primitiveProperty;
/**
* constructor.
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeTimestamp.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeTimestamp.java
index 71ea55e8..b79d48ea 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeTimestamp.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePropertyTypeTimestamp.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ public class MatchablePropertyTypeTimestamp extends MatchablePropertyTypeBase<IS
try {
return ISO8601DateTime.fromISO8601DateTimeString(value.toString());
} catch (ParseException e) {
- throw new ToscaPolicyConversionException("bad ISO8601 timevalue " + value.toString(), e);
+ throw new ToscaPolicyConversionException("bad ISO8601 time value " + value, e);
}
}
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 d1c6d38c..c1c0f15c 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
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,16 +60,14 @@ import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@Setter
+@Getter
public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
private static final Logger LOGGER = LoggerFactory.getLogger(StdBaseTranslator.class);
private static final ObjectFactory factory = new ObjectFactory();
- @Getter
- @Setter
protected boolean booleanReturnAttributes = false;
- @Getter
- @Setter
protected boolean booleanReturnSingleValueAttributesAsCollection = false;
public static final String POLICY_ID = "policy-id";
@@ -131,7 +130,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
* obligations. This method must be overridden and be implemented for the specific application as
* obligations may have different expected attributes per application.
*
- * @param obligations Collection of obligation objects
+ * @param obligations Collection of obligation objects
* @param decisionResponse DecisionResponse object used to store any results from obligations.
*/
protected abstract void scanObligations(Collection<Obligation> obligations, DecisionResponse decisionResponse);
@@ -141,7 +140,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
* can be overridden for each specific application as advice may have different expected attributes per
* application.
*
- * @param advice Collection of Advice objects
+ * @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);
@@ -151,10 +150,10 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
* DecisionResponse object.
*
* @param attributeCategories Collection of AttributeCategory objects
- * @param decisionResponse DecisionResponse object used to store any attributes
+ * @param decisionResponse DecisionResponse object used to store any attributes
*/
protected void scanAttributes(Collection<AttributeCategory> attributeCategories,
- DecisionResponse decisionResponse) {
+ DecisionResponse decisionResponse) {
var returnedAttributes = new HashMap<String, Object>();
for (AttributeCategory attributeCategory : attributeCategories) {
var mapCategory = new HashMap<String, Object>();
@@ -163,7 +162,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
// Most attributes have a single value, thus the collection is not necessary to
// return. However, we will allow this to be configurable.
//
- if (! booleanReturnSingleValueAttributesAsCollection && attribute.getValues().size() == 1) {
+ if (!booleanReturnSingleValueAttributesAsCollection && attribute.getValues().size() == 1) {
var iterator = attribute.getValues().iterator();
var value = iterator.next();
mapCategory.put(attribute.getAttributeId().stringValue(), value.getValue().toString());
@@ -173,7 +172,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
}
returnedAttributes.put(attributeCategory.getCategory().stringValue(), mapCategory);
}
- if (! returnedAttributes.isEmpty()) {
+ if (!returnedAttributes.isEmpty()) {
decisionResponse.setAttributes(returnedAttributes);
}
}
@@ -182,25 +181,25 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
* From the TOSCA metadata section, pull in values that are needed into the XACML policy.
*
* @param policy Policy Object to store the metadata
- * @param map The Metadata TOSCA Map
+ * @param map The Metadata TOSCA Map
* @return Same Policy Object
* @throws ToscaPolicyConversionException If there is something missing from the metadata
*/
- protected PolicyType fillMetadataSection(PolicyType policy,
- Map<String, Object> map) throws ToscaPolicyConversionException {
+ protected PolicyType fillMetadataSection(PolicyType policy, Map<String, Object> map)
+ throws ToscaPolicyConversionException {
//
// Ensure the policy-id exists - we don't use it here. It
// is saved in the TOSCA Policy Name field.
//
- if (! map.containsKey(POLICY_ID)) {
+ if (!map.containsKey(POLICY_ID)) {
throw new ToscaPolicyConversionException(policy.getPolicyId() + " missing metadata " + POLICY_ID);
}
//
// Ensure the policy-version exists
//
- if (! map.containsKey(POLICY_VERSION)) {
+ if (!map.containsKey(POLICY_VERSION)) {
throw new ToscaPolicyConversionException(policy.getPolicyId() + " missing metadata "
- + POLICY_VERSION);
+ + POLICY_VERSION);
}
//
// Add in the Policy Version
@@ -214,20 +213,20 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
* return the obligation only instead of adding it directly to a rule/policy/policyset.
* But this is fine for now.
*
- * @param <T> RuleType, PolicyType, PolicySetType object
- * @Param policyId The policy-id
+ * @param <T> RuleType, PolicyType, PolicySetType object
+ * @param policyId The policy-id
* @param ruleOrPolicy Incoming RuleType, PolicyType, PolicySetType object
- * @param jsonPolicy JSON String representation of policy.
- * @param weight Weighting for the policy (optional)
+ * @param jsonPolicy JSON String representation of policy.
+ * @param weight Weighting for the policy (optional)
* @return Return the Incoming RuleType, PolicyType, PolicySetType object for convenience.
*/
protected <T> T addObligation(T ruleOrPolicy, String policyId, String jsonPolicy, Integer weight,
- String policyType) {
+ String policyType) {
//
// Creating obligation for returning policy
//
LOGGER.info("Obligation Policy id: {} type: {} weight: {} policy:{}{}", policyId, policyType, weight,
- XacmlPolicyUtils.LINE_SEPARATOR, jsonPolicy);
+ XacmlPolicyUtils.LINE_SEPARATOR, jsonPolicy);
//
// Create our OnapObligation
//
@@ -241,12 +240,12 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
//
var obligations = new ObligationExpressionsType();
obligations.getObligationExpression().add(obligation);
- if (ruleOrPolicy instanceof RuleType) {
- ((RuleType) ruleOrPolicy).setObligationExpressions(obligations);
- } else if (ruleOrPolicy instanceof PolicyType) {
- ((PolicyType) ruleOrPolicy).setObligationExpressions(obligations);
- } else if (ruleOrPolicy instanceof PolicySetType) {
- ((PolicySetType) ruleOrPolicy).setObligationExpressions(obligations);
+ if (ruleOrPolicy instanceof RuleType ruleType) {
+ ruleType.setObligationExpressions(obligations);
+ } else if (ruleOrPolicy instanceof PolicyType policyType1) {
+ policyType1.setObligationExpressions(obligations);
+ } else if (ruleOrPolicy instanceof PolicySetType policySetType) {
+ policySetType.setObligationExpressions(obligations);
} else {
LOGGER.error("Unsupported class for adding obligation {}", ruleOrPolicy.getClass());
}
@@ -268,11 +267,11 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
// Create the match for the policy type
//
var match = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
- XACML3.ID_FUNCTION_STRING_EQUAL,
- type,
- XACML3.ID_DATATYPE_STRING,
- ToscaDictionary.ID_RESOURCE_POLICY_TYPE,
- XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
+ XACML3.ID_FUNCTION_STRING_EQUAL,
+ type,
+ XACML3.ID_DATATYPE_STRING,
+ ToscaDictionary.ID_RESOURCE_POLICY_TYPE,
+ XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
//
// Add it to an AnyOfType object
//
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyRequest.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyRequest.java
index 3e7c10af..ab32caef 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyRequest.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyRequest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,7 +53,7 @@ public class StdCombinedPolicyRequest {
@XACMLSubject(attributeId = "urn:org:onap:onap-component", includeInResults = true)
private String onapComponent;
- @XACMLSubject(attributeId = "urn:org:onap:onap-instance", includeInResults = true)
+ @XACMLSubject(attributeId = "urn:org:onap:onap-instance", includeInResults = true)
private String onapInstance;
@XACMLAction()
@@ -92,18 +93,18 @@ public class StdCombinedPolicyRequest {
Map<String, Object> resources = decisionRequest.getResource();
for (Entry<String, Object> entrySet : resources.entrySet()) {
if (POLICY_ID_KEY.equals(entrySet.getKey())) {
- if (entrySet.getValue() instanceof Collection) {
- addPolicyIds(request, (Collection) entrySet.getValue());
- } else if (entrySet.getValue() instanceof String) {
- request.resource.add(entrySet.getValue().toString());
+ if (entrySet.getValue() instanceof Collection collection) {
+ addPolicyIds(request, collection);
+ } else if (entrySet.getValue() instanceof String stringValue) {
+ request.resource.add(stringValue);
}
continue;
}
if (POLICY_TYPE_KEY.equals(entrySet.getKey())) {
- if (entrySet.getValue() instanceof Collection) {
- addPolicyTypes(request, (Collection) entrySet.getValue());
- } else if (entrySet.getValue() instanceof String) {
- request.resourcePolicyType.add(entrySet.getValue().toString());
+ if (entrySet.getValue() instanceof Collection collection) {
+ addPolicyTypes(request, collection);
+ } else if (entrySet.getValue() instanceof String stringValue) {
+ request.resourcePolicyType.add(stringValue);
}
}
}
@@ -118,7 +119,7 @@ public class StdCombinedPolicyRequest {
}
protected static StdCombinedPolicyRequest addPolicyTypes(StdCombinedPolicyRequest request,
- Collection<Object> types) {
+ Collection<Object> types) {
for (Object type : types) {
request.resourcePolicyType.add(type.toString());
}
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 42e3d43e..a084ec24 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
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,8 +39,8 @@ import com.att.research.xacml.std.annotations.XACMLRequest;
import com.att.research.xacml.std.annotations.XACMLSubject;
import com.att.research.xacml.util.FactoryException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import lombok.Getter;
@@ -69,13 +70,13 @@ public class StdMatchablePolicyRequest {
@XACMLSubject(attributeId = "urn:org:onap:onap-component", includeInResults = true)
private String onapComponent;
- @XACMLSubject(attributeId = "urn:org:onap:onap-instance", includeInResults = true)
+ @XACMLSubject(attributeId = "urn:org:onap:onap-instance", includeInResults = true)
private String onapInstance;
@XACMLAction()
private String action;
- protected static DataTypeFactory dataTypeFactory = null;
+ protected static DataTypeFactory dataTypeFactory = null;
protected static synchronized DataTypeFactory getDataTypeFactory() {
try {
@@ -148,10 +149,11 @@ public class StdMatchablePolicyRequest {
// and use that to validate the fields that are matchable.
//
try {
- if (entrySet.getValue() instanceof Collection) {
- addResources(resourceAttributes, (Collection) entrySet.getValue(), attributeId);
+ if (entrySet.getValue() instanceof Collection collection) {
+ addResources(resourceAttributes, collection, attributeId);
} else {
- addResources(resourceAttributes, Arrays.asList(entrySet.getValue().toString()), attributeId);
+ addResources(resourceAttributes,
+ Collections.singletonList(entrySet.getValue().toString()), attributeId);
}
} catch (DataTypeException e) {
throw new XacmlApplicationException("Failed to add resource ", e);
@@ -162,19 +164,20 @@ public class StdMatchablePolicyRequest {
}
protected static StdMutableRequestAttributes addResources(StdMutableRequestAttributes attributes,
- Collection<Object> values, String id) throws DataTypeException {
+ Collection<Object> values, String id)
+ throws DataTypeException {
var factory = getDataTypeFactory();
if (factory == null) {
return null;
}
for (Object value : values) {
- var mutableAttribute = new StdMutableAttribute();
+ var mutableAttribute = new StdMutableAttribute();
mutableAttribute.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
mutableAttribute.setAttributeId(new IdentifierImpl(id));
mutableAttribute.setIncludeInResults(true);
- DataType<?> dataTypeExtended = factory.getDataType(XACML3.ID_DATATYPE_STRING);
+ DataType<?> dataTypeExtended = factory.getDataType(XACML3.ID_DATATYPE_STRING);
AttributeValue<?> attributeValue = dataTypeExtended.createAttributeValue(value);
Collection<AttributeValue<?>> attributeValues = new ArrayList<>();
attributeValues.add(attributeValue);
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 732542a2..a58b8c47 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
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,10 +82,9 @@ import org.slf4j.LoggerFactory;
* to translate policies.
*
* @author pameladragosh
- *
*/
@NoArgsConstructor
-public class StdMatchableTranslator extends StdBaseTranslator implements MatchableCallback {
+public class StdMatchableTranslator extends StdBaseTranslator implements MatchableCallback {
private static final Logger LOGGER = LoggerFactory.getLogger(StdMatchableTranslator.class);
private static final StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
@@ -112,7 +111,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
* scanObligations - scans the list of obligations and make appropriate method calls to process
* obligations.
*
- * @param obligations Collection of obligation objects
+ * @param obligations Collection of obligation objects
* @param decisionResponse DecisionResponse object used to store any results from obligations.
*/
@Override
@@ -165,10 +164,10 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
* contents and their details.
*
* @param closestMatches Map holding the current set of highest weight policy types
- * @param obligation Obligation object
+ * @param obligation Obligation object
*/
protected void scanClosestMatchObligation(
- Map<String, Map<Integer, List<Pair<String, Map<String, Object>>>>> closestMatches, Obligation obligation) {
+ Map<String, Map<Integer, List<Pair<String, Map<String, Object>>>>> closestMatches, Obligation obligation) {
//
// Create our OnapObligation object
//
@@ -177,7 +176,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
// All 4 *should* be there
//
if (onapObligation.getPolicyId() == null || onapObligation.getPolicyContent() == null
- || onapObligation.getPolicyType() == null || onapObligation.getWeight() == null) {
+ || onapObligation.getPolicyType() == null || onapObligation.getWeight() == null) {
LOGGER.error("Missing an expected attribute in obligation.");
return;
}
@@ -197,13 +196,13 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
// Only need to check first one - as we will ensure there is only one weight
//
Entry<Integer, List<Pair<String, Map<String, Object>>>> firstEntry =
- weightMap.entrySet().iterator().next();
+ weightMap.entrySet().iterator().next();
if (policyWeight < firstEntry.getKey()) {
//
// Existing policies have a greater weight, so we will not add it
//
LOGGER.info("{} is lesser weight {} than current policies, will not return it", policyWeight,
- firstEntry.getKey());
+ firstEntry.getKey());
} else if (firstEntry.getKey().equals(policyWeight)) {
//
// Same weight - we will add it
@@ -246,7 +245,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
//
if (toscaPolicyTypeTemplate == null) {
throw new ToscaPolicyConversionException(
- "Cannot retrieve Policy Type definition for policy " + toscaPolicy.getName());
+ "Cannot retrieve Policy Type definition for policy " + toscaPolicy.getName());
}
//
// Policy name should be at the root
@@ -340,14 +339,8 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
return null;
}
- private class MyMatchableCallback implements MatchableCallback {
- private StdMatchableTranslator translator;
- private ToscaServiceTemplate template;
-
- public MyMatchableCallback(StdMatchableTranslator translator, ToscaServiceTemplate template) {
- this.translator = translator;
- this.template = template;
- }
+ private record MyMatchableCallback(StdMatchableTranslator translator, ToscaServiceTemplate template)
+ implements MatchableCallback {
@Override
public ToscaPolicyType retrievePolicyType(String derivedFrom) {
@@ -369,7 +362,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
* For generating target type, we scan for matchable properties
* and use those to build the policy.
*
- * @param policy the policy
+ * @param policy the policy
* @param template template containing the policy
* @return {@code Pair<TargetType, Integer>} Returns a TargetType and a Total Weight of matchables.
*/
@@ -394,7 +387,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
// Create the matchable
//
matchablePolicyType = new MatchablePolicyType(
- template.getPolicyTypes().get(policy.getType()), myCallback);
+ template.getPolicyTypes().get(policy.getType()), myCallback);
//
// Cache it
//
@@ -422,7 +415,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
@SuppressWarnings("unchecked")
protected void fillTargetTypeWithMatchables(TargetType target, MatchablePolicyType matchablePolicyType,
- Map<String, Object> properties) throws ToscaPolicyConversionException {
+ Map<String, Object> properties) throws ToscaPolicyConversionException {
for (Entry<String, Object> entrySet : properties.entrySet()) {
String propertyName = entrySet.getKey();
Object propertyValue = entrySet.getValue();
@@ -436,7 +429,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
// Depending on what type it is, add it into the target
//
ToscaPolicyTranslatorUtils.buildAndAppendTarget(target,
- matchable.getType().generate(propertyValue, id));
+ matchable.getType().generate(propertyValue, id));
continue;
}
@@ -480,7 +473,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
// Is it loaded in memory?
//
ToscaServiceTemplate policyTemplate = this.matchablePolicyTypes.get(policyTypeId);
- if (policyTemplate == null) {
+ if (policyTemplate == null) {
//
// Load the policy
//
@@ -540,7 +533,7 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
// Decode the template
//
ToscaServiceTemplate template = standardYamlCoder.decode(new String(bytes, StandardCharsets.UTF_8),
- ToscaServiceTemplate.class);
+ ToscaServiceTemplate.class);
//
// Ensure all the fields are setup correctly
//
@@ -561,12 +554,12 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
* pullPolicyType - pulls the given ToscaConceptIdentifier from the Policy Lifecycle API.
* If successful, will store it locally given the policyTypePath.
*
- * @param policyTypeId ToscaConceptIdentifier
+ * @param policyTypeId ToscaConceptIdentifier
* @param policyTypePath Path object to store locally
* @return ToscaPolicyType object. Null if failure.
*/
protected synchronized ToscaServiceTemplate pullPolicyType(ToscaConceptIdentifier policyTypeId,
- Path policyTypePath) {
+ Path policyTypePath) {
//
// This is what we return
//
@@ -603,6 +596,6 @@ public class StdMatchableTranslator extends StdBaseTranslator implements Matcha
*/
protected Path constructLocalFilePath(ToscaConceptIdentifier policyTypeId) {
return Paths.get(this.pathForData.toAbsolutePath().toString(), policyTypeId.getName() + "-"
- + policyTypeId.getVersion() + ".yaml");
+ + policyTypeId.getVersion() + ".yaml");
}
}
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java
index 466aae12..5036b5a6 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,6 @@ import com.att.research.xacml.api.pdp.PDPEngineFactory;
import com.att.research.xacml.api.pdp.PDPException;
import com.att.research.xacml.util.FactoryException;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -70,7 +69,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
private HttpClient policyApiClient;
private Properties pdpProperties = null;
private PDPEngine pdpEngine = null;
- private Map<ToscaPolicy, Path> mapLoadedPolicies = new HashMap<>();
+ private final Map<ToscaPolicy, Path> mapLoadedPolicies = new HashMap<>();
@Override
public String applicationName() {
@@ -84,7 +83,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
@Override
public void initialize(Path pathForData, HttpClient policyApiClient)
- throws XacmlApplicationException {
+ throws XacmlApplicationException {
//
// Save our path
//
@@ -146,7 +145,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Xacml Policy is {}{}", XacmlPolicyUtils.LINE_SEPARATOR,
- new String(Files.readAllBytes(refPath), StandardCharsets.UTF_8));
+ Files.readString(refPath));
}
//
// Add root policy to properties object
@@ -156,7 +155,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
// Write the properties to disk
//
XacmlPolicyUtils.storeXacmlProperties(newProperties,
- XacmlPolicyUtils.getPropertiesPath(this.getDataPath()));
+ XacmlPolicyUtils.getPropertiesPath(this.getDataPath()));
//
// Reload the engine
//
@@ -175,14 +174,14 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
}
@Override
- public synchronized boolean unloadPolicy(ToscaPolicy toscaPolicy) throws XacmlApplicationException {
+ public synchronized boolean unloadPolicy(ToscaPolicy toscaPolicy) {
//
// Find it in our map
//
Path refPolicy = this.mapLoadedPolicies.get(toscaPolicy);
if (refPolicy == null) {
LOGGER.error("Failed to find ToscaPolicy {} in our map size {}", toscaPolicy.getMetadata(),
- this.mapLoadedPolicies.size());
+ this.mapLoadedPolicies.size());
return false;
}
//
@@ -200,14 +199,14 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
Files.delete(refPolicy);
} catch (IOException e) {
LOGGER.error("Failed to delete policy {} from disk {}", toscaPolicy.getMetadata(),
- refPolicy.toAbsolutePath(), e);
+ refPolicy.toAbsolutePath(), e);
}
//
// Write the properties to disk
//
try {
XacmlPolicyUtils.storeXacmlProperties(newProperties,
- XacmlPolicyUtils.getPropertiesPath(this.getDataPath()));
+ XacmlPolicyUtils.getPropertiesPath(this.getDataPath()));
} catch (IOException e) {
LOGGER.error("Failed to save the properties to disk {}", newProperties, e);
}
@@ -224,7 +223,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
//
if (this.mapLoadedPolicies.remove(toscaPolicy) == null) {
LOGGER.error("Failed to remove toscaPolicy {} from internal map size {}", toscaPolicy.getMetadata(),
- this.mapLoadedPolicies.size());
+ this.mapLoadedPolicies.size());
}
//
// Not sure if any of the errors above warrant returning false
@@ -234,7 +233,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
@Override
public Pair<DecisionResponse, Response> makeDecision(DecisionRequest request,
- Map<String, String[]> requestQueryParams) {
+ Map<String, String[]> requestQueryParams) {
//
// Convert to a XacmlRequest
//