aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src/main
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-tosca/src/main
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-tosca/src/main')
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifier.java38
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java21
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifier.java38
3 files changed, 94 insertions, 3 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifier.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifier.java
index e55c6bd4d..f98a238ff 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifier.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifier.java
@@ -23,13 +23,16 @@ package org.onap.policy.models.tosca.authorative.concepts;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
/**
* Identifies a policy. Both the name and version must be non-null.
*/
@Data
@NoArgsConstructor
-public class ToscaPolicyIdentifier {
+public class ToscaPolicyIdentifier implements Comparable<ToscaPolicyIdentifier> {
@NonNull
private String name;
@@ -47,4 +50,37 @@ public class ToscaPolicyIdentifier {
this.name = source.name;
this.version = source.version;
}
+
+ /**
+ * 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("name", name);
+ result.validateNotNull("version", version);
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(ToscaPolicyIdentifier other) {
+ if (this == other) {
+ return 0;
+ }
+
+ if (other == null) {
+ return 1;
+ }
+
+ int result = ObjectUtils.compare(getName(), other.getName());
+ if (result != 0) {
+ return result;
+ }
+
+ return ObjectUtils.compare(getVersion(), other.getVersion());
+ }
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java
index 9296780d5..d5ddb0522 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java
@@ -24,13 +24,14 @@ import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
+import org.apache.commons.lang3.ObjectUtils;
/**
* Policy identifier with an optional version; only the "name" is required.
*/
@Data
@NoArgsConstructor
-public class ToscaPolicyIdentifierOptVersion {
+public class ToscaPolicyIdentifierOptVersion implements Comparable<ToscaPolicyIdentifierOptVersion> {
@NonNull
@SerializedName("policy-id")
@@ -58,4 +59,22 @@ public class ToscaPolicyIdentifierOptVersion {
public boolean isNullVersion() {
return (version == null);
}
+
+ @Override
+ public int compareTo(ToscaPolicyIdentifierOptVersion other) {
+ if (this == other) {
+ return 0;
+ }
+
+ if (other == null) {
+ return 1;
+ }
+
+ int result = ObjectUtils.compare(getName(), other.getName());
+ if (result != 0) {
+ return result;
+ }
+
+ return ObjectUtils.compare(getVersion(), other.getVersion());
+ }
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifier.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifier.java
index a10c3eb9c..4cd1764de 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifier.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifier.java
@@ -23,13 +23,16 @@ package org.onap.policy.models.tosca.authorative.concepts;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
/**
* Identifies a policy type. Both the name and version must be non-null.
*/
@Data
@NoArgsConstructor
-public class ToscaPolicyTypeIdentifier {
+public class ToscaPolicyTypeIdentifier implements Comparable<ToscaPolicyTypeIdentifier> {
@NonNull
private String name;
@@ -47,4 +50,37 @@ public class ToscaPolicyTypeIdentifier {
this.name = source.name;
this.version = source.version;
}
+
+ /**
+ * 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("name", name);
+ result.validateNotNull("version", version);
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(ToscaPolicyTypeIdentifier other) {
+ if (this == other) {
+ return 0;
+ }
+
+ if (other == null) {
+ return 1;
+ }
+
+ int result = ObjectUtils.compare(getName(), other.getName());
+ if (result != 0) {
+ return result;
+ }
+
+ return ObjectUtils.compare(getVersion(), other.getVersion());
+ }
}