aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main/java/org/onap')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java41
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/depundep/ProviderBase.java8
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java35
3 files changed, 67 insertions, 17 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java
index ee66b35c..fa721054 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java
@@ -251,6 +251,7 @@ public class PdpGroupDeployProvider extends ProviderBase {
BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp);
+ result.addResult(validateSupportedTypes(data, subgrp));
result.addResult(validatePolicies(data, subgrp));
return result;
@@ -345,32 +346,46 @@ public class PdpGroupDeployProvider extends ProviderBase {
}
/**
- * Performs additional validations of the policies within a subgroup.
+ * Performs additional validations of the supported policy types within a subgroup.
*
* @param data session data
* @param subgrp the subgroup to be validated
* @param result the validation result
* @throws PfModelException if an error occurred
*/
- private ValidationResult validatePolicies(SessionData data, PdpSubGroup subgrp) throws PfModelException {
+ private ValidationResult validateSupportedTypes(SessionData data, PdpSubGroup subgrp) throws PfModelException {
BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp);
- for (ToscaPolicyIdentifier ident : subgrp.getPolicies()) {
- try {
- ToscaPolicy policy = data.getPolicy(new ToscaPolicyIdentifierOptVersion(ident));
+ for (ToscaPolicyTypeIdentifier type : subgrp.getSupportedPolicyTypes()) {
+ if (data.getPolicyType(type) == null) {
+ result.addResult(new ObjectValidationResult("policy type", type, ValidationStatus.INVALID,
+ "unknown policy type"));
+ }
+ }
- if (!subgrp.getSupportedPolicyTypes().contains(policy.getTypeIdentifier())) {
- result.addResult(new ObjectValidationResult("policy", ident, ValidationStatus.INVALID,
- "not a supported policy for the subgroup"));
- }
+ return result;
+ }
- } catch (PfModelException e) {
- if (e.getErrorResponse().getResponseCode() != Status.NOT_FOUND) {
- throw e;
- }
+ /**
+ * Performs additional validations of the policies within a subgroup.
+ *
+ * @param data session data
+ * @param subgrp the subgroup to be validated
+ * @param result the validation result
+ * @throws PfModelException if an error occurred
+ */
+ private ValidationResult validatePolicies(SessionData data, PdpSubGroup subgrp) throws PfModelException {
+ BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp);
+ for (ToscaPolicyIdentifier ident : subgrp.getPolicies()) {
+ ToscaPolicy policy = data.getPolicy(new ToscaPolicyIdentifierOptVersion(ident));
+ if (policy == null) {
result.addResult(new ObjectValidationResult("policy", ident, ValidationStatus.INVALID,
"unknown policy"));
+
+ } else if (!subgrp.getSupportedPolicyTypes().contains(policy.getTypeIdentifier())) {
+ result.addResult(new ObjectValidationResult("policy", ident, ValidationStatus.INVALID,
+ "not a supported policy for the subgroup"));
}
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/ProviderBase.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/ProviderBase.java
index a66b03d2..d3f0d13e 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/ProviderBase.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/ProviderBase.java
@@ -248,7 +248,13 @@ public abstract class ProviderBase {
*/
private ToscaPolicy getPolicy(SessionData data, ToscaPolicyIdentifierOptVersion ident) {
try {
- return data.getPolicy(ident);
+ ToscaPolicy policy = data.getPolicy(ident);
+ if (policy == null) {
+ throw new PfModelRuntimeException(Status.NOT_FOUND,
+ "cannot find policy: " + ident.getName() + " " + ident.getVersion());
+ }
+
+ return policy;
} catch (PfModelException e) {
throw new PfModelRuntimeException(e.getErrorResponse().getResponseCode(),
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
index 98a5e675..a76d6e13 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
@@ -27,7 +27,6 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
-import javax.ws.rs.core.Response.Status;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.PdpGroup;
@@ -40,6 +39,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter.ToscaPolicyFilterBuilder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
/**
@@ -79,6 +79,11 @@ public class SessionData {
*/
private final Map<ToscaPolicyIdentifierOptVersion, ToscaPolicy> policyCache = new HashMap<>();
+ /**
+ * Maps a policy type's identifier to the policy.
+ */
+ private final Map<ToscaPolicyTypeIdentifier, ToscaPolicyType> typeCache = new HashMap<>();
+
/**
* Constructs the object.
@@ -90,6 +95,31 @@ public class SessionData {
}
/**
+ * Gets the policy type, referenced by an identifier. Loads it from the cache, if possible.
+ * Otherwise, gets it from the DB.
+ *
+ * @param desiredType policy type identifier
+ * @return the specified policy type
+ * @throws PfModelException if an error occurred
+ */
+ public ToscaPolicyType getPolicyType(ToscaPolicyTypeIdentifier desiredType) throws PfModelException {
+
+ ToscaPolicyType type = typeCache.get(desiredType);
+ if (type == null) {
+
+ List<ToscaPolicyType> lst = dao.getPolicyTypeList(desiredType.getName(), desiredType.getVersion());
+ if (lst.isEmpty()) {
+ return null;
+ }
+
+ type = lst.get(0);
+ typeCache.put(desiredType, type);
+ }
+
+ return type;
+ }
+
+ /**
* Gets the policy, referenced by an identifier. Loads it from the cache, if possible.
* Otherwise, gets it from the DB.
*
@@ -106,8 +136,7 @@ public class SessionData {
List<ToscaPolicy> lst = dao.getFilteredPolicyList(filterBuilder.build());
if (lst.isEmpty()) {
- throw new PfModelException(Status.NOT_FOUND,
- "cannot find policy: " + desiredPolicy.getName() + " " + desiredPolicy.getVersion());
+ return null;
}
policy = lst.get(0);