Patched the upperBound calculation

This commit is contained in:
Luca Frosini 2021-03-12 12:44:01 +01:00
parent f29c258375
commit 1877291fba
1 changed files with 18 additions and 1 deletions

View File

@ -147,8 +147,12 @@ public class Validator {
// now validate fields // now validate fields
int metadataIndex = 0; int metadataIndex = 0;
Map<String, MetadataField> metadataFieldMap = new HashMap<>();
for(MetadataField metadataField : metadataFields) { for(MetadataField metadataField : metadataFields) {
metadataFieldMap.put(metadataField.getFieldName(), metadataField);
int categoryIdIndex = categoriesIds.indexOf(metadataField.getCategoryRef()); int categoryIdIndex = categoriesIds.indexOf(metadataField.getCategoryRef());
logger.debug("Found index for category " + metadataField.getCategoryRef() + " " + categoryIdIndex); logger.debug("Found index for category " + metadataField.getCategoryRef() + " " + categoryIdIndex);
List<CustomField> validCFs = validateAgainstMetadataField(metadataIndex, categoryIdIndex, List<CustomField> validCFs = validateAgainstMetadataField(metadataIndex, categoryIdIndex,
@ -167,7 +171,20 @@ public class Validator {
Map.Entry<java.lang.String,java.lang.Integer> entry = (Map.Entry<java.lang.String,java.lang.Integer>) iteratorLowerBounds Map.Entry<java.lang.String,java.lang.Integer> entry = (Map.Entry<java.lang.String,java.lang.Integer>) iteratorLowerBounds
.next(); .next();
int lowerBound = entry.getValue(); int lowerBound = entry.getValue();
int upperBound = fieldsMandatoryUpperBoundMap.get(entry.getKey());
// int upperBound = fieldsMandatoryUpperBoundMap.get(entry.getKey());
String maxOccurs = metadataFieldMap.get(entry.getKey()).getMaxOccurs();
int upperBound = Integer.MAX_VALUE;
if(maxOccurs.compareTo("*")==0) {
upperBound = Integer.MAX_VALUE;
}else {
try {
upperBound = Integer.valueOf(maxOccurs);
}catch (Exception e) {
}
}
int inserted = numberFieldsMandatorySameKeyMap.get(entry.getKey()); int inserted = numberFieldsMandatorySameKeyMap.get(entry.getKey());
logger.info("Field with key '" + entry.getKey() + "' has been found " + inserted logger.info("Field with key '" + entry.getKey() + "' has been found " + inserted