Changed identifiers to concept identifiers
[policy/models.git] / models-pdp / src / main / java / org / onap / policy / models / pdp / concepts / PdpSubGroup.java
index 2618a50..bfd9dac 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,6 +21,7 @@
 
 package org.onap.policy.models.pdp.concepts;
 
+import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -31,8 +32,7 @@ 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;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 /**
  * Class to represent a group of all PDP's of the same pdp type running for a particular
@@ -43,8 +43,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi
 @Data
 public class PdpSubGroup {
     private String pdpType;
-    private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes;
-    private List<ToscaPolicyIdentifier> policies;
+    private List<ToscaConceptIdentifier> supportedPolicyTypes;
+    private List<ToscaConceptIdentifier> policies;
     private int currentInstanceCount;
     private int desiredInstanceCount;
     private Map<String, String> properties;
@@ -64,31 +64,36 @@ public class PdpSubGroup {
      */
     public PdpSubGroup(@NonNull final PdpSubGroup source) {
         this.pdpType = source.pdpType;
-        this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaPolicyTypeIdentifier::new);
-        this.policies = PfUtils.mapList(source.policies, ToscaPolicyIdentifier::new);
+        this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaConceptIdentifier::new,
+                        new ArrayList<>(0));
+        this.policies = PfUtils.mapList(source.policies, ToscaConceptIdentifier::new, new ArrayList<>(0));
         this.currentInstanceCount = source.currentInstanceCount;
         this.desiredInstanceCount = source.desiredInstanceCount;
         this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties));
-        this.pdpInstances = PfUtils.mapList(source.pdpInstances, Pdp::new);
+        this.pdpInstances = PfUtils.mapList(source.pdpInstances, Pdp::new, new ArrayList<>(0));
     }
 
     /**
      * Validates that appropriate fields are populated for an incoming call to the PAP
      * REST API.
      *
+     * @param updateGroupFlow if the operation is pdp group update
      * @return the validation result
      */
-    public ValidationResult validatePapRest() {
+    public ValidationResult validatePapRest(boolean updateGroupFlow) {
         BeanValidationResult result = new BeanValidationResult("group", this);
 
         result.validateNotNull("pdpType", pdpType);
-        result.validateNotNullList("supportedPolicyTypes", supportedPolicyTypes,
-                        ToscaPolicyTypeIdentifier::validatePapRest);
-        result.validateNotNullList("policies", policies, ToscaPolicyIdentifier::validatePapRest);
+        // When doing PdpGroup Update operation, supported policy types and policies doesn't have to be validated.
+        if (!updateGroupFlow) {
+            result.validateNotNullList("policies", policies, ToscaConceptIdentifier::validatePapRest);
+            result.validateNotNullList("supportedPolicyTypes", supportedPolicyTypes,
+                ToscaConceptIdentifier::validatePapRest);
 
-        if (supportedPolicyTypes != null && supportedPolicyTypes.isEmpty()) {
-            result.addResult(new ObjectValidationResult("supportedPolicyTypes", supportedPolicyTypes,
-                            ValidationStatus.INVALID, "empty list"));
+            if (supportedPolicyTypes != null && supportedPolicyTypes.isEmpty()) {
+                result.addResult(new ObjectValidationResult("supportedPolicyTypes", supportedPolicyTypes,
+                    ValidationStatus.INVALID, "empty list"));
+            }
         }
 
         if (desiredInstanceCount <= 0) {