use of org.motechproject.mds.exception.action.ActionHandlerException in project motech by motech.
the class ActionHandlerServiceImpl method setPlainInstanceProperty.
private void setPlainInstanceProperty(Object instance, Field field, Object value) throws ActionHandlerException {
try {
Class<?> propertyType = PropertyUtil.getPropertyType(instance, field.getName());
Object parsedValue = TypeHelper.parse(value, propertyType);
PropertyUtil.setProperty(instance, field.getName(), parsedValue);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new ActionHandlerException("Cannot set instance property " + field.getName() + " with value " + value, e);
}
}
use of org.motechproject.mds.exception.action.ActionHandlerException in project motech by motech.
the class ActionHandlerServiceImpl method setRelationshipInstanceProperty.
private void setRelationshipInstanceProperty(Object instance, Field field, Object value) throws ActionHandlerException {
RelationshipHolder relationshipHolder = new RelationshipHolder(field);
try {
if (null != value) {
String relatedClassName = relationshipHolder.getRelatedClass();
MotechDataService relatedClassDataService = getEntityDataService(relatedClassName);
if (relationshipHolder.isManyToOne() || relationshipHolder.isOneToOne()) {
Object relatedInstance = getRelatedInstance(relatedClassDataService, value);
PropertyUtil.safeSetProperty(instance, field.getName(), relatedInstance);
} else if (relationshipHolder.isManyToMany() || relationshipHolder.isOneToMany()) {
List<Object> relatedInstances = getRelatedInstances(relatedClassDataService, value);
PropertyUtil.safeSetCollectionProperty(instance, field.getName(), relatedInstances);
}
} else {
PropertyUtil.safeSetProperty(instance, field.getName(), null);
}
} catch (RuntimeException e) {
throw new ActionHandlerException("Cannot set instance property " + field.getName() + " with value " + value, e);
}
}
Aggregations