[FEAT] add decorator @CollectionItemNotNull
This commit is contained in:
parent
3f15d560ed
commit
461aece7a0
@ -85,6 +85,14 @@ public class AnnotationTools {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CollectionItemNotNull getCollectionItemNotNull(final Field element) {
|
||||||
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(CollectionItemNotNull.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (CollectionItemNotNull) annotation[0];
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean getSchemaReadOnly(final Field element) {
|
public static boolean getSchemaReadOnly(final Field element) {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Schema.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Schema.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
|
12
src/org/kar/archidata/annotation/CollectionItemNotNull.java
Normal file
12
src/org/kar/archidata/annotation/CollectionItemNotNull.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package org.kar.archidata.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface CollectionItemNotNull {
|
||||||
|
|
||||||
|
}
|
@ -14,6 +14,7 @@ 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.CollectionItemNotNull;
|
||||||
import org.kar.archidata.annotation.DataJson;
|
import org.kar.archidata.annotation.DataJson;
|
||||||
import org.kar.archidata.dataAccess.DBAccess;
|
import org.kar.archidata.dataAccess.DBAccess;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
@ -542,8 +543,34 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
checkerInstance.check(ioDb, baseName + '.' + fieldName, tmpData, null, options);
|
checkerInstance.check(ioDb, baseName + '.' + fieldName, tmpData, null, options);
|
||||||
|
final CollectionItemNotNull collectionNotNull = AnnotationTools.getCollectionItemNotNull(field);
|
||||||
|
if (collectionNotNull != null) {
|
||||||
|
if (!Collection.class.isAssignableFrom(field.getType())) {
|
||||||
|
throw new DataAccessException(
|
||||||
|
"Request @CollectionItemNotNull on a non collection field: '" + fieldName + "'");
|
||||||
|
}
|
||||||
|
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 Collection<?> tmpCollection = (Collection<?>) tmpData;
|
||||||
|
final Object[] elements = tmpCollection.toArray();
|
||||||
|
for (int iii = 0; iii < elements.length; iii++) {
|
||||||
|
if (elements[iii] == null) {
|
||||||
|
throw new InputException(baseName + fieldName + '[' + iii + ']',
|
||||||
|
"This collection can not conatain NULL item");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// keep this is last ==> take more time...
|
// keep this is last ==> take more time...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user