From db91542f3b768260cdf535e05a3976271a70de23 Mon Sep 17 00:00:00 2001 From: mojahidi Date: Wed, 6 Mar 2019 17:38:43 +0530 Subject: Bug Fix - Requirement and capabilities feature Fixed - bugs Change-Id: I6d5dea6ff1e508caf6580c86c430a0bfcbc23c88 Issue-ID: SDC-2142 Signed-off-by: mojahidi --- .../impl/ComponentInstanceBusinessLogic.java | 10 +++++--- .../validation/CapabilitiesValidation.java | 28 +++++++++++++-------- .../validation/RequirementValidation.java | 29 +++++++++++++--------- 3 files changed, 41 insertions(+), 26 deletions(-) (limited to 'catalog-be/src/main/java') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index dd8cec347c..dfdae9be5e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -2638,10 +2638,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { Either, ResponseFormat> resultOp = null; try { Either, 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); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java index 9590ec97d9..726e9dff82 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java @@ -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 capabilityOccurrencesValidationEither = validateOccurrences(responseFormatManager, minOccurrences, maxOccurrences); @@ -189,18 +189,24 @@ public class CapabilitiesValidation { private Either 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); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/RequirementValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/RequirementValidation.java index 0c6a29415a..030684ebb5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/RequirementValidation.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/RequirementValidation.java @@ -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 requirementOccurrencesValidationEither = validateOccurrences(responseFormatManager, minOccurrences, maxOccurrences); @@ -151,20 +151,25 @@ public class RequirementValidation { private Either 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 isRequirementCapabilityEmpty( -- cgit 1.2.3-korg