use of org.jumpmind.pos.persist.ColumnDef in project openpos-framework by JumpMind.
the class ModelValidator method checkCrossRefFields.
protected static void checkCrossRefFields(ModelClassMetaData meta) {
Class<?> modelClass = meta.getClazz();
List<Class<?>> compositeDefClasses = getCompositeDefClasses(modelClass);
for (Field field : modelClass.getDeclaredFields()) {
ColumnDef columnAnnotation = field.getAnnotation(ColumnDef.class);
if (columnAnnotation != null) {
if (field.getType().isAssignableFrom(Money.class)) {
if (StringUtils.isEmpty(columnAnnotation.crossReference()) && columnAnnotation.crossReferences().length == 0) {
throw new PersistException("columns of Money type require a ColumnDef with crossReference, " + "such as @ColumnDef(crossReference=\"isoCurrencyCode\"). see " + field.getName() + " on model " + modelClass);
}
}
if (!StringUtils.isEmpty(columnAnnotation.crossReference())) {
FieldMetaData xRefFieldMeta = meta.getEntityFieldMetaDatas().get(columnAnnotation.crossReference());
if (xRefFieldMeta == null) {
xRefFieldMeta = meta.getEntityIdFieldMetaDatas().get(columnAnnotation.crossReference());
}
if (xRefFieldMeta == null) {
throw new PersistException("No matching field found for ColumnDef crossReference=\"" + columnAnnotation.crossReference() + "\" see the \"" + field.getName() + "\" field on model " + modelClass);
}
}
}
}
}
use of org.jumpmind.pos.persist.ColumnDef in project openpos-framework by JumpMind.
the class ModelValidator method checkOrphanedFields.
protected static void checkOrphanedFields(ModelClassMetaData meta) {
List<Class<?>> compositeDefClasses;
Class<?> modelClass = meta.getClazz();
for (Field field : modelClass.getDeclaredFields()) {
ColumnDef columnAnnotation = field.getAnnotation(ColumnDef.class);
if (columnAnnotation != null) {
// an annotated column MUST have a getter/setter pair to be handled properly
// by the persistence layer.
String fieldNameCapatalized = StringUtils.capitalize(field.getName());
try {
Method setter = modelClass.getDeclaredMethod("set" + fieldNameCapatalized, field.getType());
if (setter == null) {
throw new PersistException("Failed to locate setter set" + fieldNameCapatalized);
}
String prefix = field.getType().isAssignableFrom(boolean.class) ? "is" : "get";
Method getter = modelClass.getDeclaredMethod(prefix + fieldNameCapatalized);
if (!getter.getReturnType().isAssignableFrom(field.getType())) {
throw new PersistException("getter has wrong return type. " + getter);
}
} catch (Exception ex) {
throw new PersistException("Failed to locate required getter/setter pair for " + field.getName() + " on model " + modelClass + ". Make sure your model class as the proper getter/setter for @ColumnDef field " + field.getName() + " (" + ex.toString() + ")");
}
}
}
}
Aggregations