Bug Fix - Requirement and capabilities feature 77/79777/1
authormojahidi <mojahidul.islam@amdocs.com>
Wed, 6 Mar 2019 12:08:43 +0000 (17:38 +0530)
committermojahidi <mojahidul.islam@amdocs.com>
Wed, 6 Mar 2019 12:10:02 +0000 (17:40 +0530)
Fixed - bugs

Change-Id: I6d5dea6ff1e508caf6580c86c430a0bfcbc23c88
Issue-ID: SDC-2142
Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/RequirementValidation.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java

index dd8cec3..dfdae9b 100644 (file)
@@ -2638,10 +2638,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
         Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
         try {
             Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties = toscaOperationFacade.getComponentInstanceCapabilityProperties(componentId, instanceId, capabilityName, capabilityType, ownerId);
-            if(getComponentInstanceCapabilityProperties.isRight()){
-                resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getComponentInstanceCapabilityProperties.right().value()), capabilityType, instanceId, componentId));
+            if(getComponentInstanceCapabilityProperties != null) {
+                if (getComponentInstanceCapabilityProperties.isRight()) {
+                    resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getComponentInstanceCapabilityProperties.right().value()), capabilityType, instanceId, componentId));
+                } else {
+                    resultOp = Either.left(getComponentInstanceCapabilityProperties.left().value());
+                }
             } else {
-                resultOp =  Either.left(getComponentInstanceCapabilityProperties.left().value());
+                resultOp = Either.left(new ArrayList<>());
             }
         } catch(Exception e){
             log.error("The exception {} occurred upon the component {} instance {} capability {} properties retrieving. ", componentId, instanceId, capabilityName, e);
index 9590ec9..726e9df 100644 (file)
@@ -91,7 +91,7 @@ public class CapabilitiesValidation {
                                                                 ResponseFormatManager responseFormatManager) {
         String maxOccurrences = capabilityDefinition.getMaxOccurrences();
         String minOccurrences = capabilityDefinition.getMinOccurrences();
-        if(StringUtils.isNotEmpty(maxOccurrences) && StringUtils.isNotEmpty(minOccurrences)) {
+        if(maxOccurrences != null && minOccurrences != null) {
             Either<Boolean, ResponseFormat> capabilityOccurrencesValidationEither =
                     validateOccurrences(responseFormatManager, minOccurrences,
                             maxOccurrences);
@@ -189,18 +189,24 @@ public class CapabilitiesValidation {
     private Either<Boolean, ResponseFormat> validateOccurrences        (
             ResponseFormatManager responseFormatManager,
             String minOccurrences, String maxOccurrences ) {
-        if(StringUtils.isNotEmpty(maxOccurrences)&& "UNBOUNDED".equalsIgnoreCase(maxOccurrences)
-                && Integer.parseInt(minOccurrences) >= 0) {
-            return Either.left(Boolean.TRUE);
-        } else if(Integer.parseInt(minOccurrences) < 0) {
-            LOGGER.debug("Invalid occurrences format.low_bound occurrence negative {}", minOccurrences);
+        try {
+            if (StringUtils.isNotEmpty(maxOccurrences) && "UNBOUNDED".equalsIgnoreCase(maxOccurrences)
+                    && Integer.parseInt(minOccurrences) >= 0) {
+                return Either.left(Boolean.TRUE);
+            } else if (Integer.parseInt(minOccurrences) < 0) {
+                LOGGER.debug("Invalid occurrences format.low_bound occurrence negative {}", minOccurrences);
+                ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
+                return Either.right(responseFormat);
+            } else if (Integer.parseInt(maxOccurrences) < Integer.parseInt(minOccurrences)) {
+                LOGGER.error("Capability maxOccurrences should be greater than minOccurrences");
+                ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
+                        .MAX_OCCURRENCES_SHOULD_BE_GREATER_THAN_MIN_OCCURRENCES);
+                return Either.right(errorResponse);
+            }
+        } catch (NumberFormatException ex) {
+            LOGGER.debug("Invalid occurrences. Only Integer allowed");
             ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
             return Either.right(responseFormat);
-        } else if(Integer.parseInt(maxOccurrences) < Integer.parseInt(minOccurrences)){
-            LOGGER.error("Capability maxOccurrences should be greater than minOccurrences");
-            ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
-                    .MAX_OCCURRENCES_SHOULD_BE_GREATER_THAN_MIN_OCCURRENCES);
-            return Either.right(errorResponse);
         }
         return Either.left(Boolean.TRUE);
     }
index 0c6a294..030684e 100644 (file)
@@ -94,7 +94,7 @@ public class RequirementValidation {
                                                                 ResponseFormatManager responseFormatManager) {
         String maxOccurrences = requirementDefinition.getMaxOccurrences();
         String minOccurrences = requirementDefinition.getMinOccurrences();
-        if(StringUtils.isNotEmpty(maxOccurrences) && StringUtils.isNotEmpty(minOccurrences)) {
+        if(maxOccurrences != null && minOccurrences !=null) {
             Either<Boolean, ResponseFormat> requirementOccurrencesValidationEither =
                     validateOccurrences(responseFormatManager, minOccurrences,
                             maxOccurrences);
@@ -151,20 +151,25 @@ public class RequirementValidation {
     private Either<Boolean, ResponseFormat> validateOccurrences        (
             ResponseFormatManager responseFormatManager,
             String minOccurrences, String maxOccurrences ) {
-        if(StringUtils.isNotEmpty(maxOccurrences)&& "UNBOUNDED".equalsIgnoreCase(maxOccurrences)
-                && Integer.parseInt(minOccurrences) >= 0) {
-            return Either.left(Boolean.TRUE);
-        } else if(Integer.parseInt(minOccurrences) < 0) {
-            LOGGER.debug("Invalid occurrences format.low_bound occurrence negative {}", minOccurrences);
+        try {
+            if (StringUtils.isNotEmpty(maxOccurrences) && "UNBOUNDED".equalsIgnoreCase(maxOccurrences)
+                    && Integer.parseInt(minOccurrences) >= 0) {
+                return Either.left(Boolean.TRUE);
+            } else if (Integer.parseInt(minOccurrences) < 0) {
+                LOGGER.debug("Invalid occurrences format.low_bound occurrence negative {}", minOccurrences);
+                ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
+                return Either.right(responseFormat);
+            } else if (Integer.parseInt(maxOccurrences) < Integer.parseInt(minOccurrences)) {
+                LOGGER.error("Requirement maxOccurrences should be greater than minOccurrences");
+                ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
+                        .MAX_OCCURRENCES_SHOULD_BE_GREATER_THAN_MIN_OCCURRENCES);
+                return Either.right(errorResponse);
+            }
+        } catch (NumberFormatException ex) {
+            LOGGER.debug("Invalid occurrences. Only Integer allowed");
             ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
             return Either.right(responseFormat);
         }
-        else if(Integer.parseInt(maxOccurrences) < Integer.parseInt(minOccurrences)){
-            LOGGER.error("Requirement maxOccurrences should be greater than minOccurrences");
-            ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
-                    .MAX_OCCURRENCES_SHOULD_BE_GREATER_THAN_MIN_OCCURRENCES);
-            return Either.right(errorResponse);
-        }
         return Either.left(Boolean.TRUE);
     }
     private Either<Boolean, ResponseFormat> isRequirementCapabilityEmpty(
index 7bd36ea..3e91d74 100644 (file)
@@ -672,13 +672,10 @@ public class NodeTemplateOperation extends BaseOperation {
             Map<String, ListCapabilityDataDefinition> capabilities,
             ComponentInstanceDataDefinition componentInstance,
             MapListCapabilityDataDefinition calculatedCap) {
-        if (capabilities != null) {
             MapListCapabilityDataDefinition allCalculatedCap =
                     new MapListCapabilityDataDefinition(calculatedCap);
             populateCapability(capabilities, componentInstance, allCalculatedCap);
             return allCalculatedCap;
-        }
-        return null;
     }
 
     private void populateCapability(Map<String, ListCapabilityDataDefinition> capabilities,
@@ -702,14 +699,11 @@ public class NodeTemplateOperation extends BaseOperation {
             Map<String, ListRequirementDataDefinition> requirements,
             ComponentInstanceDataDefinition componentInstance,
             MapListRequirementDataDefinition calculatedReqs) {
-        if (requirements != null) {
             MapListRequirementDataDefinition allCalculatedReq =
                     new MapListRequirementDataDefinition(calculatedReqs);
 
             populateRequirement(requirements, componentInstance, allCalculatedReq);
             return allCalculatedReq;
-        }
-        return null;
     }
     private void populateRequirement(Map<String, ListRequirementDataDefinition> requirements,
                                      ComponentInstanceDataDefinition componentInstance,