summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-03-30 18:58:34 +0100
committerChristophe Closset <christophe.closset@intl.att.com>2021-04-01 13:50:52 +0000
commit92cfb1ac0ea9c9ae3884ec60325b9e59217436d4 (patch)
tree6a8379b1167703d48410bebfa2838cb5f30c6ed8 /catalog-model/src/main
parent6ab5e3189921e3d7762e5acba47c5a3fcc357251 (diff)
Increase TOSCA integer validator supported range
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: Iebd6f977cec5f40ed7b07fceaf3dd62a3c138e2c Issue-ID: SDC-3541
Diffstat (limited to 'catalog-model/src/main')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/IntegerValidator.java47
1 files changed, 25 insertions, 22 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/IntegerValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/IntegerValidator.java
index f2745c95ea..53bfc1ee3c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/IntegerValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/IntegerValidator.java
@@ -19,18 +19,25 @@
*/
package org.openecomp.sdc.be.model.tosca.validators;
+import java.math.BigInteger;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class IntegerValidator implements PropertyTypeValidator {
- private static IntegerValidator integerValidator = new IntegerValidator();
- private PatternBase base8Pattern = new PatternBase(Pattern.compile("([-+])?0o([0-7]+)"), 8);
- private PatternBase base10Pattern = new PatternBase(Pattern.compile("([-+])?(0|[1-9][0-9]*)"), 10);
- private PatternBase base16Pattern = new PatternBase(Pattern.compile("([-+])?0x([0-9a-fA-F]+)"), 16);
- private PatternBase[] patterns = {base10Pattern, base8Pattern, base16Pattern};
+ private static final Logger log = LoggerFactory.getLogger(IntegerValidator.class);
+
+ private static final IntegerValidator integerValidator = new IntegerValidator();
+ private final PatternBase base8Pattern = new PatternBase(Pattern.compile("([-+])?0o([0-7]+)"), 8);
+ private final PatternBase base10Pattern = new PatternBase(Pattern.compile("([-+])?(0|[1-9][0-9]*)"), 10);
+ private final PatternBase base16Pattern = new PatternBase(Pattern.compile("([-+])?0x([0-9a-fA-F]+)"), 16);
+ private final PatternBase[] patterns = {base10Pattern, base8Pattern, base16Pattern};
private IntegerValidator() {
}
@@ -40,21 +47,19 @@ public class IntegerValidator implements PropertyTypeValidator {
}
@Override
- public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ public boolean isValid(final String value, final String innerType, final Map<String, DataTypeDefinition> allDataTypes) {
+
if (value == null || value.isEmpty()) {
return true;
}
- for (PatternBase patternBase : patterns) {
- Matcher matcher = patternBase.pattern.matcher(value);
- Long parsed = null;
+ for (final PatternBase patternBase : patterns) {
+ final Matcher matcher = patternBase.getPattern().matcher(value);
if (matcher.matches()) {
try {
- parsed = Long.parseLong(matcher.group(2), patternBase.base);
- if (matcher.group(1) != null && matcher.group(1).compareTo("-") == 0) {
- parsed *= -1;
- }
- return (Integer.MIN_VALUE <= parsed && parsed <= (Integer.MAX_VALUE)) ? true : false;
- } catch (NumberFormatException e) {
+ new BigInteger(matcher.group(2), patternBase.base);
+ return true;
+ } catch (Exception e) {
+ log.warn("Failed to build BigInteger {}", value, e);
return false;
}
}
@@ -63,18 +68,16 @@ public class IntegerValidator implements PropertyTypeValidator {
}
@Override
- public boolean isValid(String value, String innerType) {
+ public boolean isValid(final String value, final String innerType) {
return isValid(value, innerType, null);
}
+ @Getter
+ @AllArgsConstructor
private class PatternBase {
- Pattern pattern;
- Integer base;
+ private final Pattern pattern;
+ private final Integer base;
- public PatternBase(Pattern pattern, Integer base) {
- this.pattern = pattern;
- this.base = base;
- }
}
}