Browse Source

ValidateTypes

apg 2 weeks ago
parent
commit
5cce194b67

+ 0 - 1
src/main/java/scot/carricksoftware/grants/domains/images/DocumentImage.java

@@ -8,7 +8,6 @@ package scot.carricksoftware.grants.domains.images;
 import jakarta.persistence.Entity;
 import jakarta.persistence.Table;
 
-@SuppressWarnings("JpaDataSourceORMInspection")
 @Entity(name="document_image")
 @Table(name="`document_image`")
 public class DocumentImage extends BaseImage {

+ 2 - 0
src/main/java/scot/carricksoftware/grants/validators/helpers/ValidateTypes.java

@@ -28,6 +28,8 @@ public interface ValidateTypes {
 
     void validateNonNegativeInteger(String integerString, String fieldName, @SuppressWarnings("SameParameterValue") String nullMessage, String formatMessage, String negativeMessage, BindingResult bindingResult);
 
+    void validateNonNegativeStaredInteger(String integerString, String fieldName, @SuppressWarnings("SameParameterValue") String nullMessage, String formatMessage, String negativeMessage, BindingResult bindingResult);
+
     void validateIntegerRange(String integerString,
                               Integer lowValue,
                               Integer highValue,

+ 20 - 1
src/main/java/scot/carricksoftware/grants/validators/helpers/ValidateTypesImpl.java

@@ -78,6 +78,25 @@ public class ValidateTypesImpl implements ValidateTypes {
         }
     }
 
+    @Override
+    public void validateNonNegativeStaredInteger(String integerString, String fieldName, String nullMessage, String formatMessage, String negativeMessage, BindingResult bindingResult) {
+        if (integerString == null || integerString.isEmpty()) {
+            assert integerString != null;
+            Integer pos = integerString.lastIndexOf('*');
+            //noinspection ConstantValue
+            if (pos != null) {
+                //noinspection ConstantValue
+                if (pos != -1) {
+                    String newString = integerString.substring(0, pos);
+                    validateNonNegativeInteger(newString, fieldName, nullMessage, formatMessage, negativeMessage, bindingResult);
+                } else {
+                    validateNonNegativeInteger(integerString, fieldName, nullMessage, formatMessage, negativeMessage, bindingResult);
+                }
+            }
+        }
+
+    }
+
     @Override
     public void validateIntegerRange(String integerString,
                                      Integer lowValue, Integer highValue, String fieldName,
@@ -107,7 +126,7 @@ public class ValidateTypesImpl implements ValidateTypes {
                 break;
             }
         }
-        if (!validExtension){
+        if (!validExtension) {
             bindingResult.rejectValue(fieldName, ApplicationConstants.EMPTY_STRING, null, message);
         }