summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java28
1 files changed, 17 insertions, 11 deletions
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<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);
}