Commit 92229e5e authored by Piotr Gawron's avatar Piotr Gawron

method checking property validity extracted

parent 8d4a48e7
......@@ -19,7 +19,6 @@ import org.springframework.stereotype.Repository;
import org.springframework.util.ReflectionUtils;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.DbUtils;
......@@ -483,44 +482,22 @@ public abstract class BaseDao<T> {
ReflectionUtils.doWithFields(object.getClass(), new ReflectionUtils.FieldCallback() {
@Override
public void doWith(Field arg0) throws IllegalArgumentException, IllegalAccessException {
Column column = getAnnotationColumn(arg0);
Object property = arg0.get(object);
if (skippedClasses.contains(arg0.getType())) {
// skip
} else if (java.lang.reflect.Modifier.isStatic(arg0.getModifiers())) {
// skip static
} else if (arg0.getType() == String.class) {
arg0.setAccessible(true);
String newObject = (String) arg0.get(object);
Column column = getAnnotationColumn(arg0);
if (column != null) {
if (!column.nullable()) {
if (newObject == null) {
processIssue.accept(object, arg0);
}
}
if (newObject != null && column.length() <= newObject.length()
&& !column.columnDefinition().equals("TEXT")) {
processIssue.accept(object, arg0);
}
}
} else if (arg0.getType() == Double.class || arg0.getType() == Integer.class || arg0.getType() == Color.class
|| arg0.getType() == Calendar.class || arg0.getType() == Class.class
} else if (arg0.getType() == String.class || arg0.getType() == Double.class || arg0.getType() == Integer.class
|| arg0.getType() == Color.class || arg0.getType() == Calendar.class || arg0.getType() == Class.class
|| arg0.getType() == Calendar.class || arg0.getType().isEnum()) {
arg0.setAccessible(true);
Object newObject = arg0.get(object);
Column column = getAnnotationColumn(arg0);
if (column != null) {
if (!column.nullable()) {
if (newObject == null) {
processIssue.accept(object, arg0);
}
}
if (isProblematicProperty(property, column)) {
processIssue.accept(object, arg0);
}
} else if (Collection.class.isAssignableFrom(arg0.getType())) {
arg0.setAccessible(true);
Collection<?> newObjectSet = (Collection<?>) arg0.get(object);
Collection<?> newObjectSet = (Collection<?>) property;
if (newObjectSet != null) {
for (Object newObject : newObjectSet) {
if (newObject != null && !skippedClasses.contains(newObject.getClass())) {
......@@ -543,12 +520,32 @@ public abstract class BaseDao<T> {
}
}
} else {
throw new InvalidStateException("Don't know how to process: " + arg0.getType());
logger.error("Don't know how to process: " + arg0.getType());
}
}
});
}
}
private boolean isProblematicProperty(Object property, Column column)
throws IllegalArgumentException, IllegalAccessException {
if (column != null) {
if (property instanceof String) {
String stringProperty = (String) property;
if (stringProperty != null && column.length() <= stringProperty.length()
&& !column.columnDefinition().equals("TEXT")) {
return true;
}
}
if (!column.nullable()) {
if (property == null) {
return true;
}
}
}
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment