summaryrefslogtreecommitdiffstats
path: root/models-pdp/src/main/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-04-11 21:58:12 -0400
committerJim Hahn <jrh3@att.com>2019-04-12 11:37:46 -0400
commit92d9b661cc32b8dcc90e813aa220e26ef6f83b17 (patch)
treec1e2afa2a2294377aa5364e8234713c44b62bfeb /models-pdp/src/main/java
parent8a26f57269caf7a559deb46077050048da92dca8 (diff)
Add validation methods for PAP REST API
Also made the identifier classes comparable. Stupid tabs. Change-Id: I54c0595c6a2c61a1b72b58fe1d667657f9d5d71e Issue-ID: POLICY-1542 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-pdp/src/main/java')
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java59
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java23
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java36
3 files changed, 109 insertions, 9 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java
index 8805ae9ba..53bf3c1c6 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java
@@ -21,13 +21,17 @@
package org.onap.policy.models.pdp.concepts;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-
+import java.util.Set;
import lombok.Data;
import lombok.NoArgsConstructor;
-
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ObjectValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.PfNameVersion;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.pdp.enums.PdpState;
@@ -78,4 +82,55 @@ public class PdpGroup implements PfNameVersion, Comparable<PdpGroup> {
public int compareTo(final PdpGroup other) {
return compareNameVersion(this, other);
}
+
+ /**
+ * Validates that appropriate fields are populated for an incoming call to the PAP
+ * REST API.
+ *
+ * @return the validation result
+ */
+ public ValidationResult validatePapRest() {
+ BeanValidationResult result = new BeanValidationResult("group", this);
+
+ /*
+ * Don't care about version or state, because we override them. Ok if description
+ * is null.
+ */
+
+ result.validateNotNull("name", name);
+ result.validateNotNullList("pdpSubgroups", pdpSubgroups, PdpSubGroup::validatePapRest);
+
+ checkDuplicateSubgroups(result);
+
+ return result;
+ }
+
+ /**
+ * Checks for duplicate subgroups.
+ *
+ * @param result where to place validation results
+ */
+ private void checkDuplicateSubgroups(BeanValidationResult result) {
+ if (pdpSubgroups == null) {
+ return;
+ }
+
+ Set<String> set = new HashSet<>();
+
+ for (PdpSubGroup subgrp : pdpSubgroups) {
+ if (subgrp == null) {
+ continue;
+ }
+
+ String pdpType = subgrp.getPdpType();
+ if (pdpType == null) {
+ continue;
+ }
+
+ if (!set.add(pdpType)) {
+ result.addResult(new ObjectValidationResult("subgroups", pdpType, ValidationStatus.INVALID,
+ "duplicate subgroup"));
+ }
+ }
+ }
}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java
index 32e0b1a29..a7e05dd6b 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java
@@ -24,14 +24,14 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
/**
- * Request deploy or update a set of groups via the PDP Group deployment
- * REST API.
+ * Request deploy or update a set of groups via the PDP Group deployment REST API.
*/
@Getter
@Setter
@@ -41,14 +41,29 @@ public class PdpGroups {
/**
* Get the contents of this class as a list of PDP group maps.
+ *
* @return the PDP groups in a list of maps
*/
public List<Map<String, PdpGroup>> toMapList() {
final Map<String, PdpGroup> pdpGroupMap = new LinkedHashMap<>();
for (PdpGroup pdpGroup : groups) {
- pdpGroupMap.put(pdpGroup.getName() + ':' + pdpGroup.getVersion() , pdpGroup);
+ pdpGroupMap.put(pdpGroup.getName() + ':' + pdpGroup.getVersion(), pdpGroup);
}
return Collections.singletonList(pdpGroupMap);
}
+
+ /**
+ * Validates that appropriate fields are populated for an incoming call to the PAP
+ * REST API.
+ *
+ * @return the validation result
+ */
+ public ValidationResult validatePapRest() {
+ BeanValidationResult result = new BeanValidationResult("groups", this);
+
+ result.validateNotNullList("groups", groups, PdpGroup::validatePapRest);
+
+ return result;
+ }
}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java
index 405408946..2618a5017 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java
@@ -24,16 +24,19 @@ package org.onap.policy.models.pdp.concepts;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-
import lombok.Data;
import lombok.NonNull;
-
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ObjectValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
/**
- * Class to represent a group of all PDP's of the same pdp type running for a particular domain.
+ * Class to represent a group of all PDP's of the same pdp type running for a particular
+ * domain.
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
@@ -68,4 +71,31 @@ public class PdpSubGroup {
this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties));
this.pdpInstances = PfUtils.mapList(source.pdpInstances, Pdp::new);
}
+
+ /**
+ * Validates that appropriate fields are populated for an incoming call to the PAP
+ * REST API.
+ *
+ * @return the validation result
+ */
+ public ValidationResult validatePapRest() {
+ BeanValidationResult result = new BeanValidationResult("group", this);
+
+ result.validateNotNull("pdpType", pdpType);
+ result.validateNotNullList("supportedPolicyTypes", supportedPolicyTypes,
+ ToscaPolicyTypeIdentifier::validatePapRest);
+ result.validateNotNullList("policies", policies, ToscaPolicyIdentifier::validatePapRest);
+
+ if (supportedPolicyTypes != null && supportedPolicyTypes.isEmpty()) {
+ result.addResult(new ObjectValidationResult("supportedPolicyTypes", supportedPolicyTypes,
+ ValidationStatus.INVALID, "empty list"));
+ }
+
+ if (desiredInstanceCount <= 0) {
+ result.addResult(new ObjectValidationResult("desiredInstanceCount", desiredInstanceCount,
+ ValidationStatus.INVALID, "non-positive"));
+ }
+
+ return result;
+ }
}