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;
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());
+ }
}