Compare commits
No commits in common. "218fa3be2e35e6c7108c1aa8ef6aa37dffde36a8" and "3d5a024084a12454b71b46bb9c66581530f4017a" have entirely different histories.
218fa3be2e
...
3d5a024084
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>kangaroo-and-rabbit</groupId>
|
<groupId>kangaroo-and-rabbit</groupId>
|
||||||
<artifactId>archidata</artifactId>
|
<artifactId>archidata</artifactId>
|
||||||
<version>0.23.0</version>
|
<version>0.22.0</version>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
<maven.compiler.version>3.1</maven.compiler.version>
|
<maven.compiler.version>3.1</maven.compiler.version>
|
||||||
|
@ -41,24 +41,6 @@ import jakarta.ws.rs.DefaultValue;
|
|||||||
public class AnnotationTools {
|
public class AnnotationTools {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(AnnotationTools.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(AnnotationTools.class);
|
||||||
|
|
||||||
public static <TYPE extends Annotation> TYPE get(final Field element, final Class<TYPE> clazz) {
|
|
||||||
final TYPE[] annotations = element.getDeclaredAnnotationsByType(clazz);
|
|
||||||
|
|
||||||
if (annotations.length == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return annotations[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <TYPE extends Annotation> TYPE[] gets(final Field element, final Class<TYPE> clazz) {
|
|
||||||
final TYPE[] annotations = element.getDeclaredAnnotationsByType(clazz);
|
|
||||||
|
|
||||||
if (annotations.length == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return annotations;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For SQL declaration table Name
|
// For SQL declaration table Name
|
||||||
public static String getTableName(final Class<?> clazz, final QueryOptions options) throws DataAccessException {
|
public static String getTableName(final Class<?> clazz, final QueryOptions options) throws DataAccessException {
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
@ -110,15 +92,27 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static CollectionItemNotNull getCollectionItemNotNull(final Field element) {
|
public static CollectionItemNotNull getCollectionItemNotNull(final Field element) {
|
||||||
return get(element, CollectionItemNotNull.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(CollectionItemNotNull.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (CollectionItemNotNull) annotation[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CollectionItemUnique getCollectionItemUnique(final Field element) {
|
public static CollectionItemUnique getCollectionItemUnique(final Field element) {
|
||||||
return get(element, CollectionItemUnique.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(CollectionItemUnique.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (CollectionItemUnique) annotation[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CollectionNotEmpty getCollectionNotEmpty(final Field element) {
|
public static CollectionNotEmpty getCollectionNotEmpty(final Field element) {
|
||||||
return get(element, CollectionNotEmpty.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(CollectionNotEmpty.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (CollectionNotEmpty) annotation[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getSchemaReadOnly(final Field element) {
|
public static boolean getSchemaReadOnly(final Field element) {
|
||||||
@ -170,39 +164,75 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ManyToOne getManyToOne(final Field element) {
|
public static ManyToOne getManyToOne(final Field element) {
|
||||||
return get(element, ManyToOne.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ManyToOne.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (ManyToOne) annotation[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ManyToMany getManyToMany(final Field element) {
|
public static ManyToMany getManyToMany(final Field element) {
|
||||||
return get(element, ManyToMany.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ManyToMany.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (ManyToMany) annotation[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OneToMany getOneToMany(final Field element) {
|
public static OneToMany getOneToMany(final Field element) {
|
||||||
return get(element, OneToMany.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(OneToMany.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (OneToMany) annotation[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataJson getDataJson(final Field element) {
|
public static DataJson getDataJson(final Field element) {
|
||||||
return get(element, DataJson.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DataJson.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (DataJson) annotation[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Checker[] getConstraintsCheckers(final Field element) {
|
public static Checker[] getCheckers(final Field element) {
|
||||||
return gets(element, Checker.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Checker.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (Checker[]) annotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DecimalMin getConstraintsDecimalMin(final Field element) {
|
public static DecimalMin getConstraintsDecimalMin(final Field element) {
|
||||||
return get(element, DecimalMin.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DecimalMin.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ((DecimalMin) annotation[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DecimalMax getConstraintsDecimalMax(final Field element) {
|
public static DecimalMax getConstraintsDecimalMax(final Field element) {
|
||||||
return get(element, DecimalMax.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DecimalMax.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ((DecimalMax) annotation[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Max getConstraintsMax(final Field element) {
|
public static Long getConstraintsMax(final Field element) {
|
||||||
return get(element, Max.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Max.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ((Max) annotation[0]).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Min getConstraintsMin(final Field element) {
|
public static Long getConstraintsMin(final Field element) {
|
||||||
return get(element, Min.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Min.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ((Min) annotation[0]).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getLimitSize(final Field element) {
|
public static int getLimitSize(final Field element) {
|
||||||
@ -215,15 +245,27 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Size getConstraintsSize(final Field element) {
|
public static Size getConstraintsSize(final Field element) {
|
||||||
return get(element, Size.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Size.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (Size) annotation[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Pattern getConstraintsPattern(final Field element) {
|
public static String getConstraintsPattern(final Field element) {
|
||||||
return get(element, Pattern.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Pattern.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ((Pattern) annotation[0]).regexp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Email getConstraintsEmail(final Field element) {
|
public static boolean getConstraintsEmail(final Field element) {
|
||||||
return get(element, Email.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Email.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAnnotationGroup(final Field field, final Class<?> annotationType) {
|
public static boolean isAnnotationGroup(final Field field, final Class<?> annotationType) {
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
package org.kar.archidata.annotation.checker;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
@Target({ ElementType.TYPE, ElementType.FIELD })
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface CheckForeignKey {
|
|
||||||
Class<?> target();
|
|
||||||
}
|
|
@ -12,15 +12,16 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
import org.kar.archidata.annotation.checker.CheckForeignKey;
|
|
||||||
import org.kar.archidata.annotation.checker.Checker;
|
import org.kar.archidata.annotation.checker.Checker;
|
||||||
import org.kar.archidata.annotation.checker.CollectionItemNotNull;
|
import org.kar.archidata.annotation.checker.CollectionItemNotNull;
|
||||||
import org.kar.archidata.annotation.checker.CollectionItemUnique;
|
import org.kar.archidata.annotation.checker.CollectionItemUnique;
|
||||||
import org.kar.archidata.annotation.checker.CollectionNotEmpty;
|
import org.kar.archidata.annotation.checker.CollectionNotEmpty;
|
||||||
import org.kar.archidata.dataAccess.DBAccess;
|
import org.kar.archidata.dataAccess.DBAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.dataAccess.QueryCondition;
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
import org.kar.archidata.dataAccess.QueryOptions;
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
import org.kar.archidata.dataAccess.options.CheckFunctionInterface;
|
import org.kar.archidata.dataAccess.options.CheckFunctionInterface;
|
||||||
@ -35,8 +36,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.validation.constraints.DecimalMax;
|
import jakarta.validation.constraints.DecimalMax;
|
||||||
import jakarta.validation.constraints.DecimalMin;
|
import jakarta.validation.constraints.DecimalMin;
|
||||||
import jakarta.validation.constraints.Max;
|
|
||||||
import jakarta.validation.constraints.Min;
|
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
public class CheckJPA<T> implements CheckFunctionInterface {
|
public class CheckJPA<T> implements CheckFunctionInterface {
|
||||||
@ -135,8 +134,6 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
if (maxValueDecimal != null) {
|
if (maxValueDecimal != null) {
|
||||||
final long maxValue = Long.parseLong(maxValueDecimal.value());
|
final long maxValue = Long.parseLong(maxValueDecimal.value());
|
||||||
final boolean inclusive = maxValueDecimal.inclusive();
|
final boolean inclusive = maxValueDecimal.inclusive();
|
||||||
final String exceptionComment = "Value too height max=" + maxValue
|
|
||||||
+ (inclusive ? " (inclusive)" : " (exclusive)");
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -151,10 +148,12 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Long elemTyped = (Long) elem;
|
final Long elemTyped = (Long) elem;
|
||||||
if (inclusive) {
|
if (inclusive) {
|
||||||
if (elemTyped > maxValue) {
|
if (elemTyped > maxValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
} else if (elemTyped >= maxValue) {
|
} else if (elemTyped >= maxValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -162,8 +161,6 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
if (minValueDecimal != null) {
|
if (minValueDecimal != null) {
|
||||||
final long minValue = Long.parseLong(minValueDecimal.value());
|
final long minValue = Long.parseLong(minValueDecimal.value());
|
||||||
final boolean inclusive = minValueDecimal.inclusive();
|
final boolean inclusive = minValueDecimal.inclusive();
|
||||||
final String exceptionComment = "Value too low min=" + minValue
|
|
||||||
+ (inclusive ? " (inclusive)" : " (exclusive)");
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -178,17 +175,17 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Long elemTyped = (Long) elem;
|
final Long elemTyped = (Long) elem;
|
||||||
if (inclusive) {
|
if (inclusive) {
|
||||||
if (elemTyped < minValue) {
|
if (elemTyped < minValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
}
|
}
|
||||||
} else if (elemTyped <= minValue) {
|
} else if (elemTyped <= minValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
final Max maxValue = AnnotationTools.getConstraintsMax(field);
|
final Long maxValue = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValue != null) {
|
if (maxValue != null) {
|
||||||
final Long maxValueTmp = maxValue.value();
|
|
||||||
final String exceptionComment = "Value too height max=" + maxValueTmp + " (inclusive)";
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -201,15 +198,14 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Long elemTyped = (Long) elem;
|
final Long elemTyped = (Long) elem;
|
||||||
if (elemTyped > maxValueTmp) {
|
if (elemTyped > maxValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
final Min minValue = AnnotationTools.getConstraintsMin(field);
|
final Long minValue = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValue != null) {
|
if (minValue != null) {
|
||||||
final Long minValueTmp = minValue.value();
|
|
||||||
final String exceptionComment = "Value too low min=" + minValueTmp + " (inclusive)";
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -222,18 +218,42 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Long elemTyped = (Long) elem;
|
final Long elemTyped = (Long) elem;
|
||||||
if (elemTyped < minValueTmp) {
|
if (elemTyped < minValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||||
|
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||||
|
add(fieldName,
|
||||||
|
(
|
||||||
|
final DBAccess ioDb,
|
||||||
|
final String baseName,
|
||||||
|
final T data,
|
||||||
|
final List<String> modifiedValue,
|
||||||
|
final QueryOptions options) -> {
|
||||||
|
final Object elem = field.get(data);
|
||||||
|
if (elem == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||||
|
final Condition conditionCheck = condCheckers.isEmpty() ? null
|
||||||
|
: condCheckers.get(0).toCondition();
|
||||||
|
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem,
|
||||||
|
conditionCheck);
|
||||||
|
if (count == 0) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Foreign element does not exist in the DB:" + elem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
} else if (type == Integer.class || type == int.class) {
|
} else if (type == Integer.class || type == int.class) {
|
||||||
final DecimalMax maxValueDecimal = AnnotationTools.getConstraintsDecimalMax(field);
|
final DecimalMax maxValueDecimal = AnnotationTools.getConstraintsDecimalMax(field);
|
||||||
if (maxValueDecimal != null) {
|
if (maxValueDecimal != null) {
|
||||||
final int maxValue = Integer.parseInt(maxValueDecimal.value());
|
final int maxValue = Integer.parseInt(maxValueDecimal.value());
|
||||||
final boolean inclusive = maxValueDecimal.inclusive();
|
final boolean inclusive = maxValueDecimal.inclusive();
|
||||||
final String exceptionComment = "Value too height max=" + maxValue
|
|
||||||
+ (inclusive ? " (inclusive)" : " (exclusive)");
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -248,11 +268,13 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Integer elemTyped = (Integer) elem;
|
final Integer elemTyped = (Integer) elem;
|
||||||
if (inclusive) {
|
if (inclusive) {
|
||||||
if (elemTyped > maxValue) {
|
if (elemTyped > maxValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
} else if (elemTyped >= maxValue) {
|
} else if (elemTyped >= maxValue) {
|
||||||
|
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -260,8 +282,6 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
if (minValueDecimal != null) {
|
if (minValueDecimal != null) {
|
||||||
final int minValue = Integer.parseInt(minValueDecimal.value());
|
final int minValue = Integer.parseInt(minValueDecimal.value());
|
||||||
final boolean inclusive = minValueDecimal.inclusive();
|
final boolean inclusive = minValueDecimal.inclusive();
|
||||||
final String exceptionComment = "Value too low min=" + minValue
|
|
||||||
+ (inclusive ? " (inclusive)" : " (exclusive)");
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -276,17 +296,18 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Integer elemTyped = (Integer) elem;
|
final Integer elemTyped = (Integer) elem;
|
||||||
if (inclusive) {
|
if (inclusive) {
|
||||||
if (elemTyped < minValue) {
|
if (elemTyped < minValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
}
|
}
|
||||||
} else if (elemTyped <= minValue) {
|
} else if (elemTyped <= minValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
final Max maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValueRoot != null) {
|
if (maxValueRoot != null) {
|
||||||
final int maxValue = (int) maxValueRoot.value();
|
final int maxValue = maxValueRoot.intValue();
|
||||||
final String exceptionComment = "Value too height max=" + maxValue + " (inclusive)";
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -300,14 +321,14 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
final Integer elemTyped = (Integer) elem;
|
final Integer elemTyped = (Integer) elem;
|
||||||
if (elemTyped > maxValue) {
|
if (elemTyped > maxValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
final Min minValueRoot = AnnotationTools.getConstraintsMin(field);
|
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValueRoot != null) {
|
if (minValueRoot != null) {
|
||||||
final int minValue = (int) minValueRoot.value();
|
final int minValue = minValueRoot.intValue();
|
||||||
final String exceptionComment = "Value too low min=" + minValue + " (inclusive)";
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -321,7 +342,49 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
final Integer elemTyped = (Integer) elem;
|
final Integer elemTyped = (Integer) elem;
|
||||||
if (elemTyped < minValue) {
|
if (elemTyped < minValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||||
|
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||||
|
add(fieldName,
|
||||||
|
(
|
||||||
|
final DBAccess ioDb,
|
||||||
|
final String baseName,
|
||||||
|
final T data,
|
||||||
|
final List<String> modifiedValue,
|
||||||
|
final QueryOptions options) -> {
|
||||||
|
final Object elem = field.get(data);
|
||||||
|
if (elem == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem);
|
||||||
|
if (count == 0) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Foreign element does not exist in the DB:" + elem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (type == UUID.class) {
|
||||||
|
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||||
|
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||||
|
add(fieldName,
|
||||||
|
(
|
||||||
|
final DBAccess ioDb,
|
||||||
|
final String baseName,
|
||||||
|
final T data,
|
||||||
|
final List<String> modifiedValue,
|
||||||
|
final QueryOptions options) -> {
|
||||||
|
final Object elem = field.get(data);
|
||||||
|
if (elem == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem);
|
||||||
|
if (count == 0) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Foreign element does not exist in the DB:" + elem);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -332,8 +395,6 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
if (maxValueDecimal != null) {
|
if (maxValueDecimal != null) {
|
||||||
final float maxValue = Float.parseFloat(maxValueDecimal.value());
|
final float maxValue = Float.parseFloat(maxValueDecimal.value());
|
||||||
final boolean inclusive = maxValueDecimal.inclusive();
|
final boolean inclusive = maxValueDecimal.inclusive();
|
||||||
final String exceptionComment = "Value too height max=" + maxValue
|
|
||||||
+ (inclusive ? " (inclusive)" : " (exclusive)");
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -348,10 +409,12 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Float elemTyped = (Float) elem;
|
final Float elemTyped = (Float) elem;
|
||||||
if (inclusive) {
|
if (inclusive) {
|
||||||
if (elemTyped > maxValue) {
|
if (elemTyped > maxValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
} else if (elemTyped >= maxValue) {
|
} else if (elemTyped >= maxValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -359,8 +422,6 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
if (minValueDecimal != null) {
|
if (minValueDecimal != null) {
|
||||||
final float minValue = Float.parseFloat(minValueDecimal.value());
|
final float minValue = Float.parseFloat(minValueDecimal.value());
|
||||||
final boolean inclusive = minValueDecimal.inclusive();
|
final boolean inclusive = minValueDecimal.inclusive();
|
||||||
final String exceptionComment = "Value too low min=" + minValue
|
|
||||||
+ (inclusive ? " (inclusive)" : " (exclusive)");
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -375,17 +436,18 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Float elemTyped = (Float) elem;
|
final Float elemTyped = (Float) elem;
|
||||||
if (inclusive) {
|
if (inclusive) {
|
||||||
if (elemTyped < minValue) {
|
if (elemTyped < minValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
}
|
}
|
||||||
} else if (elemTyped <= minValue) {
|
} else if (elemTyped <= minValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
final Max maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValueRoot != null) {
|
if (maxValueRoot != null) {
|
||||||
final float maxValue = maxValueRoot.value();
|
final float maxValue = maxValueRoot.floatValue();
|
||||||
final String exceptionComment = "Value too height max=" + maxValue + " (inclusive)";
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -400,14 +462,14 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Float elemTyped = (Float) elem;
|
final Float elemTyped = (Float) elem;
|
||||||
|
|
||||||
if (elemTyped > maxValue) {
|
if (elemTyped > maxValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
final Min minValueRoot = AnnotationTools.getConstraintsMin(field);
|
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValueRoot != null) {
|
if (minValueRoot != null) {
|
||||||
final float minValue = minValueRoot.value();
|
final float minValue = minValueRoot.floatValue();
|
||||||
final String exceptionComment = "Value too low min=" + minValue + " (inclusive)";
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -421,7 +483,8 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
final Float elemTyped = (Float) elem;
|
final Float elemTyped = (Float) elem;
|
||||||
if (elemTyped < minValue) {
|
if (elemTyped < minValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -430,8 +493,6 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
if (maxValueDecimal != null) {
|
if (maxValueDecimal != null) {
|
||||||
final double maxValue = Float.parseFloat(maxValueDecimal.value());
|
final double maxValue = Float.parseFloat(maxValueDecimal.value());
|
||||||
final boolean inclusive = maxValueDecimal.inclusive();
|
final boolean inclusive = maxValueDecimal.inclusive();
|
||||||
final String exceptionComment = "Value too height max=" + maxValue
|
|
||||||
+ (inclusive ? " (inclusive)" : " (exclusive)");
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -446,10 +507,12 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Double elemTyped = (Double) elem;
|
final Double elemTyped = (Double) elem;
|
||||||
if (inclusive) {
|
if (inclusive) {
|
||||||
if (elemTyped > maxValue) {
|
if (elemTyped > maxValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
} else if (elemTyped >= maxValue) {
|
} else if (elemTyped >= maxValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -457,8 +520,6 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
if (minValueDecimal != null) {
|
if (minValueDecimal != null) {
|
||||||
final double minValue = Float.parseFloat(minValueDecimal.value());
|
final double minValue = Float.parseFloat(minValueDecimal.value());
|
||||||
final boolean inclusive = minValueDecimal.inclusive();
|
final boolean inclusive = minValueDecimal.inclusive();
|
||||||
final String exceptionComment = "Value too low min=" + minValue
|
|
||||||
+ (inclusive ? " (inclusive)" : " (exclusive)");
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -477,14 +538,14 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
"Value too Low min: " + minValue);
|
"Value too Low min: " + minValue);
|
||||||
}
|
}
|
||||||
} else if (elemTyped <= minValue) {
|
} else if (elemTyped <= minValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
final Max maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValueRoot != null) {
|
if (maxValueRoot != null) {
|
||||||
final double maxValue = maxValueRoot.value();
|
final double maxValue = maxValueRoot.doubleValue();
|
||||||
final String exceptionComment = "Value too height max=" + maxValue + " (inclusive)";
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -498,14 +559,14 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
final Double elemTyped = (Double) elem;
|
final Double elemTyped = (Double) elem;
|
||||||
if (elemTyped > maxValue) {
|
if (elemTyped > maxValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
final Min minValueRoot = AnnotationTools.getConstraintsMin(field);
|
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValueRoot != null) {
|
if (minValueRoot != null) {
|
||||||
final double minValue = minValueRoot.value();
|
final double minValue = minValueRoot.doubleValue();
|
||||||
final String exceptionComment = "Value too low min=" + minValue + " (inclusive)";
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -519,7 +580,8 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
final Double elemTyped = (Double) elem;
|
final Double elemTyped = (Double) elem;
|
||||||
if (elemTyped < minValue) {
|
if (elemTyped < minValue) {
|
||||||
throw new InputException(baseName + fieldName, exceptionComment);
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -530,6 +592,26 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
} else if (type == LocalTime.class) {
|
} else if (type == LocalTime.class) {
|
||||||
|
|
||||||
} else if (type == String.class) {
|
} else if (type == String.class) {
|
||||||
|
final int maxSizeString = AnnotationTools.getLimitSize(field);
|
||||||
|
if (maxSizeString > 0) {
|
||||||
|
add(fieldName,
|
||||||
|
(
|
||||||
|
final DBAccess ioDb,
|
||||||
|
final String baseName,
|
||||||
|
final T data,
|
||||||
|
final List<String> modifiedValue,
|
||||||
|
final QueryOptions options) -> {
|
||||||
|
final Object elem = field.get(data);
|
||||||
|
if (elem == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final String elemTyped = (String) elem;
|
||||||
|
if (elemTyped.length() > maxSizeString) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Too long size must be <= " + maxSizeString);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
final Size limitSize = AnnotationTools.getConstraintsSize(field);
|
final Size limitSize = AnnotationTools.getConstraintsSize(field);
|
||||||
if (limitSize != null) {
|
if (limitSize != null) {
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
@ -554,10 +636,9 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
final jakarta.validation.constraints.Pattern patternString = AnnotationTools
|
final String patternString = AnnotationTools.getConstraintsPattern(field);
|
||||||
.getConstraintsPattern(field);
|
if (patternString != null) {
|
||||||
if (patternString != null && patternString.regexp() != null) {
|
final Pattern pattern = Pattern.compile(patternString);
|
||||||
final Pattern pattern = Pattern.compile(patternString.regexp());
|
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
(
|
(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
@ -572,12 +653,12 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final String elemTyped = (String) elem;
|
final String elemTyped = (String) elem;
|
||||||
if (!pattern.matcher(elemTyped).find()) {
|
if (!pattern.matcher(elemTyped).find()) {
|
||||||
throw new InputException(baseName + fieldName,
|
throw new InputException(baseName + fieldName,
|
||||||
"does not match the required pattern (constraints) must be '" + pattern
|
"does not match the required pattern (constraints) must be '"
|
||||||
+ "'");
|
+ patternString + "'");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (AnnotationTools.getConstraintsEmail(field) != null) {
|
if (AnnotationTools.getConstraintsEmail(field)) {
|
||||||
final String emailPattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
|
final String emailPattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
|
||||||
final Pattern pattern = Pattern.compile(emailPattern);
|
final Pattern pattern = Pattern.compile(emailPattern);
|
||||||
add(fieldName,
|
add(fieldName,
|
||||||
@ -602,7 +683,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
} else if (type.isEnum()) {
|
} else if (type.isEnum()) {
|
||||||
// nothing to do.
|
// nothing to do.
|
||||||
}
|
}
|
||||||
final Checker[] checkers = AnnotationTools.getConstraintsCheckers(field);
|
final Checker[] checkers = AnnotationTools.getCheckers(field);
|
||||||
if (checkers != null) {
|
if (checkers != null) {
|
||||||
for (final Checker checker : checkers) {
|
for (final Checker checker : checkers) {
|
||||||
if (checker == null || checker.value() == CheckFunctionVoid.class) {
|
if (checker == null || checker.value() == CheckFunctionVoid.class) {
|
||||||
@ -652,87 +733,6 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final CheckForeignKey foreighKey = AnnotationTools.get(field, CheckForeignKey.class);
|
|
||||||
if (foreighKey != null) {
|
|
||||||
if (Collection.class.isAssignableFrom(field.getType())) {
|
|
||||||
add(fieldName,
|
|
||||||
(
|
|
||||||
final DBAccess ioDb,
|
|
||||||
final String baseName,
|
|
||||||
final T data,
|
|
||||||
final List<String> modifiedValue,
|
|
||||||
final QueryOptions options) -> {
|
|
||||||
// get the field of the specific element
|
|
||||||
final Object tmpData = field.get(data);
|
|
||||||
// It is not the objective of this element to check if it is authorize to set NULL
|
|
||||||
if (tmpData == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
|
||||||
final Condition conditionCheck = condCheckers.isEmpty() ? null
|
|
||||||
: condCheckers.get(0).toCondition();
|
|
||||||
final Collection<?> tmpCollection = (Collection<?>) tmpData;
|
|
||||||
final Object[] elements = tmpCollection.toArray();
|
|
||||||
for (int iii = 0; iii < elements.length; iii++) {
|
|
||||||
if (elements[iii] == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final Long count = ioDb.count(foreighKey.target(), elements[iii],
|
|
||||||
conditionCheck);
|
|
||||||
if (count != 1) {
|
|
||||||
throw new InputException(baseName + fieldName + '[' + iii + ']',
|
|
||||||
"Foreign-key does not exist in the DB:" + elements[iii]);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
add(fieldName,
|
|
||||||
(
|
|
||||||
final DBAccess ioDb,
|
|
||||||
final String baseName,
|
|
||||||
final T data,
|
|
||||||
final List<String> modifiedValue,
|
|
||||||
final QueryOptions options) -> {
|
|
||||||
final Object tmpData = field.get(data);
|
|
||||||
if (tmpData == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
|
||||||
final Condition conditionCheck = condCheckers.isEmpty() ? null
|
|
||||||
: condCheckers.get(0).toCondition();
|
|
||||||
final Long count = ioDb.count(foreighKey.target(), tmpData, conditionCheck);
|
|
||||||
if (count != 1) {
|
|
||||||
throw new InputException(baseName + fieldName,
|
|
||||||
"Foreign-key does not exist in the DB:" + tmpData);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// check if we really want to keep it ...
|
|
||||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
|
||||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
|
||||||
add(fieldName,
|
|
||||||
(
|
|
||||||
final DBAccess ioDb,
|
|
||||||
final String baseName,
|
|
||||||
final T data,
|
|
||||||
final List<String> modifiedValue,
|
|
||||||
final QueryOptions options) -> {
|
|
||||||
final Object elem = field.get(data);
|
|
||||||
if (elem == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
|
||||||
final Condition conditionCheck = condCheckers.isEmpty() ? null
|
|
||||||
: condCheckers.get(0).toCondition();
|
|
||||||
final long count = ioDb.count(annotationManyToOne.targetEntity(), elem, conditionCheck);
|
|
||||||
if (count == 0) {
|
|
||||||
throw new InputException(baseName + fieldName,
|
|
||||||
"Foreign element does not exist in the DB:" + elem);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
final CollectionItemUnique collectionUnique = AnnotationTools.getCollectionItemUnique(field);
|
final CollectionItemUnique collectionUnique = AnnotationTools.getCollectionItemUnique(field);
|
||||||
if (collectionUnique != null) {
|
if (collectionUnique != null) {
|
||||||
if (!Collection.class.isAssignableFrom(field.getType())) {
|
if (!Collection.class.isAssignableFrom(field.getType())) {
|
||||||
@ -781,7 +781,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
for (int iii = 0; iii < elements.length; iii++) {
|
for (int iii = 0; iii < elements.length; iii++) {
|
||||||
if (elements[iii] == null) {
|
if (elements[iii] == null) {
|
||||||
throw new InputException(baseName + fieldName + '[' + iii + ']',
|
throw new InputException(baseName + fieldName + '[' + iii + ']',
|
||||||
"Collection can not contain NULL item");
|
"This collection can not conatain NULL item");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -805,7 +805,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
final Collection<?> tmpCollection = (Collection<?>) tmpData;
|
final Collection<?> tmpCollection = (Collection<?>) tmpData;
|
||||||
if (tmpCollection.isEmpty()) {
|
if (tmpCollection.isEmpty()) {
|
||||||
throw new InputException(baseName + fieldName, "Collection can not be empty");
|
throw new InputException(baseName + fieldName, "Can not be empty");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -822,16 +822,15 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||||
Object other = null;
|
Object other = null;
|
||||||
if (condCheckers.isEmpty()) {
|
if (condCheckers.isEmpty()) {
|
||||||
other = ioDb.getWhere(this.clazz,
|
other = DataAccess.getWhere(this.clazz,
|
||||||
new Condition(new QueryCondition(fieldName, "==", field.get(data))));
|
new Condition(new QueryCondition(fieldName, "==", field.get(data))));
|
||||||
} else {
|
} else {
|
||||||
other = ioDb.getWhere(this.clazz,
|
other = DataAccess.getWhere(this.clazz,
|
||||||
new Condition(new QueryCondition(fieldName, "==", field.get(data))),
|
new Condition(new QueryCondition(fieldName, "==", field.get(data))),
|
||||||
condCheckers.get(0).toCondition());
|
condCheckers.get(0).toCondition());
|
||||||
}
|
}
|
||||||
if (other != null) {
|
if (other != null) {
|
||||||
throw new InputException(baseName + fieldName,
|
throw new InputException(baseName + fieldName, "Name already exist in the DB");
|
||||||
"The field is already exist in the DB");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,38 @@ public class DotClassElement {
|
|||||||
return ".optional()";
|
return ".optional()";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String maxSizeZod(final FieldProperty field) {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
final Class<?> clazz = field.model().getOriginClasses();
|
||||||
|
if (clazz == String.class) {
|
||||||
|
if (field.sizeMin() > 0) {
|
||||||
|
builder.append(".min(");
|
||||||
|
builder.append(field.sizeMin());
|
||||||
|
builder.append(")");
|
||||||
|
}
|
||||||
|
if (field.sizeMax() > 0) {
|
||||||
|
builder.append(".max(");
|
||||||
|
builder.append(field.sizeMax());
|
||||||
|
builder.append(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clazz == short.class || clazz == Short.class || clazz == int.class || clazz == Integer.class
|
||||||
|
|| clazz == long.class || clazz == Long.class || clazz == float.class || clazz == Float.class
|
||||||
|
|| clazz == double.class || clazz == Double.class) {
|
||||||
|
if (field.min() != null && field.min() > 0) {
|
||||||
|
builder.append(".min(");
|
||||||
|
builder.append(field.min());
|
||||||
|
builder.append(")");
|
||||||
|
}
|
||||||
|
if (field.max() != null && field.max() > 0) {
|
||||||
|
builder.append(".max(");
|
||||||
|
builder.append(field.max());
|
||||||
|
builder.append(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public String readOnlyZod(final FieldProperty field) {
|
public String readOnlyZod(final FieldProperty field) {
|
||||||
if (field.readOnly()) {
|
if (field.readOnly()) {
|
||||||
return ".readonly()";
|
return ".readonly()";
|
||||||
|
@ -18,12 +18,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import jakarta.persistence.ManyToMany;
|
import jakarta.persistence.ManyToMany;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import jakarta.validation.constraints.DecimalMax;
|
|
||||||
import jakarta.validation.constraints.DecimalMin;
|
|
||||||
import jakarta.validation.constraints.Email;
|
|
||||||
import jakarta.validation.constraints.Max;
|
|
||||||
import jakarta.validation.constraints.Min;
|
|
||||||
import jakarta.validation.constraints.Pattern;
|
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
public class ClassObjectModel extends ClassModel {
|
public class ClassObjectModel extends ClassModel {
|
||||||
@ -67,31 +61,24 @@ public class ClassObjectModel extends ClassModel {
|
|||||||
ClassModel model,
|
ClassModel model,
|
||||||
ClassModel linkClass, // link class when use remote ID (ex: list<UUID>)
|
ClassModel linkClass, // link class when use remote ID (ex: list<UUID>)
|
||||||
String comment,
|
String comment,
|
||||||
Size stringSize, // String Size
|
int sizeMin, // String SizeMin
|
||||||
Min min, // number min value
|
int sizeMax, // String SizeMax
|
||||||
Max max, // number max value
|
Long min, // number min value
|
||||||
DecimalMin decimalMin,
|
Long max, // number max value
|
||||||
DecimalMax decimalMax,
|
|
||||||
Pattern pattern,
|
|
||||||
Email email,
|
|
||||||
Boolean readOnly,
|
Boolean readOnly,
|
||||||
Boolean notNull,
|
Boolean notNull,
|
||||||
Boolean columnNotNull,
|
Boolean columnNotNull,
|
||||||
Boolean nullable) {
|
Boolean nullable) {
|
||||||
|
|
||||||
public FieldProperty(final String name, final ClassModel model, final ClassModel linkClass,
|
public FieldProperty(final String name, final ClassModel model, final ClassModel linkClass,
|
||||||
final String comment, final Size stringSize, final Min min, final Max max, final DecimalMin decimalMin,
|
final String comment, final int sizeMin, final int sizeMax, final Long min, final Long max,
|
||||||
final DecimalMax decimalMax, final Pattern pattern, final Email email, final Boolean readOnly,
|
final Boolean readOnly, final Boolean notNull, final Boolean columnNotNull, final Boolean nullable) {
|
||||||
final Boolean notNull, final Boolean columnNotNull, final Boolean nullable) {
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.linkClass = linkClass;
|
this.linkClass = linkClass;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.stringSize = stringSize;
|
this.sizeMin = sizeMin;
|
||||||
this.decimalMin = decimalMin;
|
this.sizeMax = sizeMax;
|
||||||
this.decimalMax = decimalMax;
|
|
||||||
this.pattern = pattern;
|
|
||||||
this.email = email;
|
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
this.readOnly = readOnly;
|
this.readOnly = readOnly;
|
||||||
@ -101,6 +88,17 @@ public class ClassObjectModel extends ClassModel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int getStringMinSize(final Field field) throws DataAccessException {
|
||||||
|
final Size size = AnnotationTools.getConstraintsSize(field);
|
||||||
|
return size != null ? size.min() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getStringMaxSize(final Field field) throws DataAccessException {
|
||||||
|
final Size size = AnnotationTools.getConstraintsSize(field);
|
||||||
|
final int colomnLimitSize = AnnotationTools.getLimitSize(field);
|
||||||
|
return size == null ? colomnLimitSize : colomnLimitSize < size.max() ? colomnLimitSize : size.max();
|
||||||
|
}
|
||||||
|
|
||||||
private static Class<?> getSubModelIfExist2(final Field field) {
|
private static Class<?> getSubModelIfExist2(final Field field) {
|
||||||
final ManyToOne manyToOne = AnnotationTools.getManyToOne(field);
|
final ManyToOne manyToOne = AnnotationTools.getManyToOne(field);
|
||||||
if (manyToOne != null) {
|
if (manyToOne != null) {
|
||||||
@ -139,13 +137,10 @@ public class ClassObjectModel extends ClassModel {
|
|||||||
ClassModel.getModel(field.getGenericType(), previous), //
|
ClassModel.getModel(field.getGenericType(), previous), //
|
||||||
getSubModelIfExist(field, previous), //
|
getSubModelIfExist(field, previous), //
|
||||||
AnnotationTools.getSchemaDescription(field), //
|
AnnotationTools.getSchemaDescription(field), //
|
||||||
AnnotationTools.getConstraintsSize(field), //
|
getStringMinSize(field), //
|
||||||
|
getStringMaxSize(field), //
|
||||||
AnnotationTools.getConstraintsMin(field), //
|
AnnotationTools.getConstraintsMin(field), //
|
||||||
AnnotationTools.getConstraintsMax(field), //
|
AnnotationTools.getConstraintsMax(field), //
|
||||||
AnnotationTools.getConstraintsDecimalMin(field), //
|
|
||||||
AnnotationTools.getConstraintsDecimalMax(field), //
|
|
||||||
AnnotationTools.getConstraintsPattern(field), //
|
|
||||||
AnnotationTools.getConstraintsEmail(field), //
|
|
||||||
AnnotationTools.getSchemaReadOnly(field), //
|
AnnotationTools.getSchemaReadOnly(field), //
|
||||||
AnnotationTools.getConstraintsNotNull(field), //
|
AnnotationTools.getConstraintsNotNull(field), //
|
||||||
AnnotationTools.getColumnNotNull(field), //
|
AnnotationTools.getColumnNotNull(field), //
|
||||||
|
@ -259,59 +259,30 @@ public class TsClassElement {
|
|||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
final Class<?> clazz = field.model().getOriginClasses();
|
final Class<?> clazz = field.model().getOriginClasses();
|
||||||
if (clazz == String.class) {
|
if (clazz == String.class) {
|
||||||
if (field.stringSize() != null) {
|
if (field.sizeMin() > 0) {
|
||||||
if (field.stringSize().min() > 0) {
|
|
||||||
// A string size can not be lower at 0
|
|
||||||
builder.append(".min(");
|
builder.append(".min(");
|
||||||
builder.append(field.stringSize().min());
|
builder.append(field.sizeMin());
|
||||||
builder.append(")");
|
builder.append(")");
|
||||||
}
|
}
|
||||||
if (field.stringSize().max() != Integer.MAX_VALUE) {
|
if (field.sizeMax() > 0) {
|
||||||
builder.append(".max(");
|
builder.append(".max(");
|
||||||
builder.append(field.stringSize().max());
|
builder.append(field.sizeMax());
|
||||||
builder.append(")");
|
builder.append(")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*Must be tested before
|
|
||||||
if (field.pattern() != null) {
|
|
||||||
builder.append(".regex((");
|
|
||||||
builder.append(field.pattern().regexp());
|
|
||||||
builder.append(")");
|
|
||||||
}*/
|
|
||||||
/*Must be tested before
|
|
||||||
if (field.email() != null) {
|
|
||||||
builder.append(".regex((");
|
|
||||||
builder.append(field.email().regexp());
|
|
||||||
builder.append(")");
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
if (clazz == short.class || clazz == Short.class || clazz == int.class || clazz == Integer.class
|
if (clazz == short.class || clazz == Short.class || clazz == int.class || clazz == Integer.class
|
||||||
|| clazz == long.class || clazz == Long.class || clazz == float.class || clazz == Float.class
|
|| clazz == long.class || clazz == Long.class || clazz == float.class || clazz == Float.class
|
||||||
|| clazz == double.class || clazz == Double.class) {
|
|| clazz == double.class || clazz == Double.class) {
|
||||||
if (field.min() != null) {
|
if (field.min() != null && field.min() > 0) {
|
||||||
builder.append(".min(");
|
builder.append(".min(");
|
||||||
builder.append(field.min().value());
|
builder.append(field.min());
|
||||||
builder.append(")");
|
builder.append(")");
|
||||||
}
|
}
|
||||||
if (field.max() != null) {
|
if (field.max() != null && field.max() > 0) {
|
||||||
builder.append(".max(");
|
builder.append(".max(");
|
||||||
builder.append(field.max().value());
|
builder.append(field.max());
|
||||||
builder.append(")");
|
builder.append(")");
|
||||||
}
|
}
|
||||||
if (field.decimalMax() != null) {
|
|
||||||
builder.append(".max(");
|
|
||||||
builder.append(field.decimalMax().value());
|
|
||||||
builder.append(", { inclusive: ");
|
|
||||||
builder.append(field.decimalMax().inclusive() ? "true" : "false");
|
|
||||||
builder.append("})");
|
|
||||||
}
|
|
||||||
if (field.decimalMin() != null) {
|
|
||||||
builder.append(".min(");
|
|
||||||
builder.append(field.decimalMin().value());
|
|
||||||
builder.append(", { inclusive: ");
|
|
||||||
builder.append(field.decimalMin().inclusive() ? "true" : "false");
|
|
||||||
builder.append("})");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,7 @@ public class MySecurityContext implements SecurityContext {
|
|||||||
}
|
}
|
||||||
// get associated Roles:
|
// get associated Roles:
|
||||||
final PartRight rightPart = getRightOfRoleInGroup(group, role);
|
final PartRight rightPart = getRightOfRoleInGroup(group, role);
|
||||||
|
LOGGER.info("detect : {}", rightPart);
|
||||||
if (PartRight.READ_WRITE.equals(rightPart)) {
|
if (PartRight.READ_WRITE.equals(rightPart)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
@Table(name = "data")
|
@Table(name = "data")
|
||||||
@DataIfNotExists
|
@DataIfNotExists
|
||||||
@ -15,11 +14,9 @@ import jakarta.validation.constraints.Size;
|
|||||||
public class Data extends OIDGenericDataSoftDelete {
|
public class Data extends OIDGenericDataSoftDelete {
|
||||||
@Column(length = 128, nullable = false)
|
@Column(length = 128, nullable = false)
|
||||||
@Schema(description = "Sha512 of the data")
|
@Schema(description = "Sha512 of the data")
|
||||||
@Size(max = 512)
|
|
||||||
public String sha512;
|
public String sha512;
|
||||||
@Column(length = 128, nullable = false)
|
@Column(length = 128, nullable = false)
|
||||||
@Schema(description = "Mime -type of the media")
|
@Schema(description = "Mime -type of the media")
|
||||||
@Size(max = 512)
|
|
||||||
public String mimeType;
|
public String mimeType;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@Schema(description = "Size in Byte of the data")
|
@Schema(description = "Size in Byte of the data")
|
||||||
|
@ -51,7 +51,6 @@ public class User extends GenericDataSoftDelete {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public Boolean blocked = false;
|
public Boolean blocked = false;
|
||||||
@Column(length = 512)
|
@Column(length = 512)
|
||||||
@Size(max = 512)
|
|
||||||
public String blockedReason;
|
public String blockedReason;
|
||||||
|
|
||||||
@Schema(description = "List of Id of the specific covers")
|
@Schema(description = "List of Id of the specific covers")
|
||||||
|
@ -1 +1 @@
|
|||||||
0.23.0
|
0.22.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user