[DEV] add checker option to permit to inject some property in the checker
This commit is contained in:
parent
8c30336bdb
commit
f1c3b88a00
@ -796,7 +796,7 @@ public class DataAccess {
|
|||||||
// External checker of data:
|
// External checker of data:
|
||||||
final List<CheckFunction> checks = options.get(CheckFunction.class);
|
final List<CheckFunction> checks = options.get(CheckFunction.class);
|
||||||
for (final CheckFunction check : checks) {
|
for (final CheckFunction check : checks) {
|
||||||
check.getChecker().check("", data, AnnotationTools.getFieldsNames(clazz));
|
check.getChecker().check("", data, AnnotationTools.getFieldsNames(clazz), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
@ -1119,7 +1119,7 @@ public class DataAccess {
|
|||||||
if (options != null) {
|
if (options != null) {
|
||||||
final List<CheckFunction> checks = options.get(CheckFunction.class);
|
final List<CheckFunction> checks = options.get(CheckFunction.class);
|
||||||
for (final CheckFunction check : checks) {
|
for (final CheckFunction check : checks) {
|
||||||
check.getChecker().check("", data, filter.getValues());
|
check.getChecker().check("", data, filter.getValues(), options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final List<LazyGetter> asyncActions = new ArrayList<>();
|
final List<LazyGetter> asyncActions = new ArrayList<>();
|
||||||
@ -1293,8 +1293,7 @@ public class DataAccess {
|
|||||||
return stmt.execute(query);
|
return stmt.execute(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T getWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
|
public static <T> T getWhere(final Class<T> clazz, final QueryOptions options) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
|
||||||
options.add(new Limit(1));
|
options.add(new Limit(1));
|
||||||
final List<T> values = getsWhere(clazz, options);
|
final List<T> values = getsWhere(clazz, options);
|
||||||
if (values.size() == 0) {
|
if (values.size() == 0) {
|
||||||
@ -1303,6 +1302,11 @@ public class DataAccess {
|
|||||||
return values.get(0);
|
return values.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> T getWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
|
||||||
|
final QueryOptions options = new QueryOptions(option);
|
||||||
|
return getWhere(clazz, options);
|
||||||
|
}
|
||||||
|
|
||||||
public static void generateSelectField(//
|
public static void generateSelectField(//
|
||||||
final StringBuilder querySelect, //
|
final StringBuilder querySelect, //
|
||||||
final StringBuilder query, //
|
final StringBuilder query, //
|
||||||
@ -1484,12 +1488,19 @@ public class DataAccess {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <ID_TYPE> long count(final Class<?> clazz, final ID_TYPE id) throws Exception {
|
public static <ID_TYPE> long count(final Class<?> clazz, final ID_TYPE id, final QueryOption... option)
|
||||||
return DataAccess.countWhere(clazz, new Condition(getTableIdCondition(clazz, id)));
|
throws Exception {
|
||||||
|
final QueryOptions options = new QueryOptions(option);
|
||||||
|
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||||
|
return DataAccess.countWhere(clazz, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long countWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
public static long countWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
|
return countWhere(clazz, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long countWhere(final Class<?> clazz, final QueryOptions options) throws Exception {
|
||||||
final Condition condition = conditionFusionOrEmpty(options, false);
|
final Condition condition = conditionFusionOrEmpty(options, false);
|
||||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||||
DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
|
@ -3,6 +3,7 @@ package org.kar.archidata.dataAccess.options;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
|
|
||||||
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
||||||
public interface CheckFunctionInterface {
|
public interface CheckFunctionInterface {
|
||||||
@ -11,10 +12,11 @@ public interface CheckFunctionInterface {
|
|||||||
* @param data The object that might be injected.
|
* @param data The object that might be injected.
|
||||||
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
||||||
* @throws Exception Exception is generate if the data are incorrect. */
|
* @throws Exception Exception is generate if the data are incorrect. */
|
||||||
void check(final String baseName, Object data, List<String> filterValue) throws Exception;
|
void check(final String baseName, Object data, List<String> filterValue, final QueryOptions options)
|
||||||
|
throws Exception;
|
||||||
|
|
||||||
default void checkAll(final String baseName, final Object data) throws Exception {
|
default void checkAll(final String baseName, final Object data, final QueryOptions options) throws Exception {
|
||||||
check(baseName, data, AnnotationTools.getAllFieldsNames(data.getClass()));
|
check(baseName, data, AnnotationTools.getAllFieldsNames(data.getClass()), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,16 @@ package org.kar.archidata.dataAccess.options;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
|
|
||||||
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
||||||
public class CheckFunctionVoid implements CheckFunctionInterface {
|
public class CheckFunctionVoid implements CheckFunctionInterface {
|
||||||
@Override
|
@Override
|
||||||
public void check(final String baseName, Object data, List<String> filterValue) {
|
public void check(
|
||||||
|
final String baseName,
|
||||||
|
final Object data,
|
||||||
|
final List<String> filterValue,
|
||||||
|
final QueryOptions options) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import org.kar.archidata.annotation.AnnotationTools;
|
|||||||
import org.kar.archidata.annotation.DataJson;
|
import org.kar.archidata.annotation.DataJson;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
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.exception.DataAccessException;
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
import org.kar.archidata.exception.InputException;
|
import org.kar.archidata.exception.InputException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -37,7 +38,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
* @param data The object that might be injected.
|
* @param data The object that might be injected.
|
||||||
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
||||||
* @throws Exception Exception is generate if the data are incorrect. */
|
* @throws Exception Exception is generate if the data are incorrect. */
|
||||||
void check(final String baseName, final K data) throws Exception;
|
void check(final String baseName, final K data, final QueryOptions options) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String, List<CheckInterface<T>>> checking = null;
|
protected Map<String, List<CheckInterface<T>>> checking = null;
|
||||||
@ -66,20 +67,20 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
for (final Field field : this.clazz.getFields()) {
|
for (final Field field : this.clazz.getFields()) {
|
||||||
final String fieldName = field.getName(); // AnnotationTools.getFieldName(field);
|
final String fieldName = field.getName(); // AnnotationTools.getFieldName(field);
|
||||||
if (AnnotationTools.isPrimaryKey(field)) {
|
if (AnnotationTools.isPrimaryKey(field)) {
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
throw new InputException(baseName + fieldName,
|
throw new InputException(baseName + fieldName,
|
||||||
"This is a '@Id' (primaryKey) ==> can not be change");
|
"This is a '@Id' (primaryKey) ==> can not be change");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (AnnotationTools.getConstraintsNotNull(field)) {
|
if (AnnotationTools.getConstraintsNotNull(field)) {
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
if (field.get(data) == null) {
|
if (field.get(data) == null) {
|
||||||
throw new InputException(baseName + fieldName, "Can not be null");
|
throw new InputException(baseName + fieldName, "Can not be null");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (AnnotationTools.isCreatedAtField(field) || AnnotationTools.isUpdateAtField(field)) {
|
if (AnnotationTools.isCreatedAtField(field) || AnnotationTools.isUpdateAtField(field)) {
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
throw new InputException(baseName + fieldName, "It is forbidden to change this field");
|
throw new InputException(baseName + fieldName, "It is forbidden to change this field");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -88,7 +89,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
if (type == Long.class || type == long.class) {
|
if (type == Long.class || type == long.class) {
|
||||||
final Long maxValue = AnnotationTools.getConstraintsMax(field);
|
final Long maxValue = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValue != null) {
|
if (maxValue != null) {
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -101,7 +102,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
final Long minValue = AnnotationTools.getConstraintsMin(field);
|
final Long minValue = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValue != null) {
|
if (minValue != null) {
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -114,12 +115,19 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem);
|
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||||
|
long count = 0;
|
||||||
|
if (condCheckers.isEmpty()) {
|
||||||
|
count = DataAccess.count(annotationManyToOne.targetEntity(), elem);
|
||||||
|
} else {
|
||||||
|
count = DataAccess.count(annotationManyToOne.targetEntity(), elem,
|
||||||
|
condCheckers.get(0).toCondition());
|
||||||
|
}
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
throw new InputException(baseName + fieldName,
|
throw new InputException(baseName + fieldName,
|
||||||
"Foreign element does not exist in the DB:" + elem);
|
"Foreign element does not exist in the DB:" + elem);
|
||||||
@ -131,7 +139,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValueRoot != null) {
|
if (maxValueRoot != null) {
|
||||||
final int maxValue = maxValueRoot.intValue();
|
final int maxValue = maxValueRoot.intValue();
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -145,7 +153,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValueRoot != null) {
|
if (minValueRoot != null) {
|
||||||
final int minValue = minValueRoot.intValue();
|
final int minValue = minValueRoot.intValue();
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -158,7 +166,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -173,7 +181,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
} else if (type == UUID.class) {
|
} else if (type == UUID.class) {
|
||||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -191,7 +199,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValueRoot != null) {
|
if (maxValueRoot != null) {
|
||||||
final float maxValue = maxValueRoot.floatValue();
|
final float maxValue = maxValueRoot.floatValue();
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -205,7 +213,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValueRoot != null) {
|
if (minValueRoot != null) {
|
||||||
final float minValue = minValueRoot.floatValue();
|
final float minValue = minValueRoot.floatValue();
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -220,7 +228,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValueRoot != null) {
|
if (maxValueRoot != null) {
|
||||||
final double maxValue = maxValueRoot.doubleValue();
|
final double maxValue = maxValueRoot.doubleValue();
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -234,7 +242,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValueRoot != null) {
|
if (minValueRoot != null) {
|
||||||
final double minValue = minValueRoot.doubleValue();
|
final double minValue = minValueRoot.doubleValue();
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -254,7 +262,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
} else if (type == String.class) {
|
} else if (type == String.class) {
|
||||||
final int maxSizeString = AnnotationTools.getLimitSize(field);
|
final int maxSizeString = AnnotationTools.getLimitSize(field);
|
||||||
if (maxSizeString > 0) {
|
if (maxSizeString > 0) {
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -268,7 +276,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
final Size limitSize = AnnotationTools.getConstraintsSize(field);
|
final Size limitSize = AnnotationTools.getConstraintsSize(field);
|
||||||
if (limitSize != null) {
|
if (limitSize != null) {
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -287,7 +295,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final String patternString = AnnotationTools.getConstraintsPattern(field);
|
final String patternString = AnnotationTools.getConstraintsPattern(field);
|
||||||
if (patternString != null) {
|
if (patternString != null) {
|
||||||
final Pattern pattern = Pattern.compile(patternString);
|
final Pattern pattern = Pattern.compile(patternString);
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object elem = field.get(data);
|
final Object elem = field.get(data);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return;
|
return;
|
||||||
@ -306,8 +314,8 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
// Here if we have an error it crash at start and no new instance after creation...
|
// Here if we have an error it crash at start and no new instance after creation...
|
||||||
final CheckFunctionInterface instance = jsonAnnotation.checker().getDeclaredConstructor()
|
final CheckFunctionInterface instance = jsonAnnotation.checker().getDeclaredConstructor()
|
||||||
.newInstance();
|
.newInstance();
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
instance.checkAll(baseName + fieldName + ".", field.get(data));
|
instance.checkAll(baseName + fieldName + ".", field.get(data), options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (type.isEnum()) {
|
} else if (type.isEnum()) {
|
||||||
@ -316,9 +324,17 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
// keep this is last ==> take more time...
|
// keep this is last ==> take more time...
|
||||||
if (AnnotationTools.isUnique(field)) {
|
if (AnnotationTools.isUnique(field)) {
|
||||||
// Create the request ...
|
// Create the request ...
|
||||||
add(fieldName, (final String baseName, final T data) -> {
|
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||||
final Object other = DataAccess.getWhere(this.clazz,
|
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||||
|
Object other = null;
|
||||||
|
if (condCheckers.isEmpty()) {
|
||||||
|
other = DataAccess.getWhere(this.clazz,
|
||||||
new Condition(new QueryCondition(fieldName, "==", field.get(data))));
|
new Condition(new QueryCondition(fieldName, "==", field.get(data))));
|
||||||
|
} else {
|
||||||
|
other = DataAccess.getWhere(this.clazz,
|
||||||
|
new Condition(new QueryCondition(fieldName, "==", field.get(data))),
|
||||||
|
condCheckers.get(0).toCondition());
|
||||||
|
}
|
||||||
if (other != null) {
|
if (other != null) {
|
||||||
throw new InputException(baseName + fieldName, "Name already exist in the DB");
|
throw new InputException(baseName + fieldName, "Name already exist in the DB");
|
||||||
}
|
}
|
||||||
@ -333,7 +349,11 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void check(final String baseName, final Object data, final List<String> filterValue) throws Exception {
|
public void check(
|
||||||
|
final String baseName,
|
||||||
|
final Object data,
|
||||||
|
final List<String> filterValue,
|
||||||
|
final QueryOptions options) throws Exception {
|
||||||
if (this.checking == null) {
|
if (this.checking == null) {
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
@ -348,13 +368,13 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (final CheckInterface<T> action : actions) {
|
for (final CheckInterface<T> action : actions) {
|
||||||
action.check(baseName, dataCasted);
|
action.check(baseName, dataCasted, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkTyped(dataCasted, filterValue);
|
checkTyped(dataCasted, filterValue, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkTyped(final T data, final List<String> filterValue) throws Exception {
|
public void checkTyped(final T data, final List<String> filterValue, final QueryOptions options) throws Exception {
|
||||||
// nothing to do ...
|
// nothing to do ...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package org.kar.archidata.dataAccess.options;
|
||||||
|
|
||||||
|
import org.kar.archidata.dataAccess.QueryItem;
|
||||||
|
|
||||||
|
/** Condition model apply to the check models. */
|
||||||
|
public class ConditionChecker extends QueryOption {
|
||||||
|
public final QueryItem condition;
|
||||||
|
|
||||||
|
public ConditionChecker(final QueryItem items) {
|
||||||
|
this.condition = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConditionChecker() {
|
||||||
|
this.condition = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Condition toCondition() {
|
||||||
|
return new Condition(this.condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -55,7 +55,7 @@ public class TsApiGeneration {
|
|||||||
if (tsModel.nativeType != DefinedPosition.NATIVE) {
|
if (tsModel.nativeType != DefinedPosition.NATIVE) {
|
||||||
imports.add(model);
|
imports.add(model);
|
||||||
}
|
}
|
||||||
if (tsModel.nativeType == DefinedPosition.BASIC) {
|
if (tsModel.nativeType != DefinedPosition.NORMAL) {
|
||||||
return tsModel.tsTypeName;
|
return tsModel.tsTypeName;
|
||||||
}
|
}
|
||||||
if (writeMode) {
|
if (writeMode) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user