use of edu.cornell.kfs.rass.batch.RassPropertyDefinition in project cu-kfs by CU-CommunityApps.
the class RassUpdateServiceImpl method buildAndPopulateBusinessObjectFromPojo.
protected <T extends RassXmlObject, R extends PersistableBusinessObject> R buildAndPopulateBusinessObjectFromPojo(T xmlObject, Supplier<R> businessObjectSupplier, RassObjectTranslationDefinition<T, R> objectDefinition, String maintenanceAction) {
Class<R> businessObjectClass = objectDefinition.getBusinessObjectClass();
R businessObject = businessObjectSupplier.get();
List<String> missingRequiredFields = new ArrayList<>();
for (RassPropertyDefinition propertyMapping : objectDefinition.getPropertyMappingsApplicableForAction(maintenanceAction)) {
Object xmlPropertyValue = ObjectPropertyUtils.getPropertyValue(xmlObject, propertyMapping.getXmlPropertyName());
RassValueConverter valueConverter = propertyMapping.getValueConverter();
Object convertedValue = valueConverter.convert(businessObjectClass, propertyMapping, xmlPropertyValue);
if (convertedValue == null && propertyMapping.isRequired()) {
missingRequiredFields.add(propertyMapping.getXmlPropertyName());
} else if (propertyMapping instanceof RassListPropertyDefinition) {
RassListPropertyDefinition listPropertyMapping = (RassListPropertyDefinition) propertyMapping;
List<?> newSubObjects = (List<?>) convertedValue;
copyForeignKeyValuesToNewSubObjects(businessObject, listPropertyMapping, newSubObjects);
mergeBusinessObjectListProperty(businessObject, (RassListPropertyDefinition) propertyMapping, (List<?>) convertedValue);
} else {
ObjectPropertyUtils.setPropertyValue(businessObject, propertyMapping.getBoPropertyName(), convertedValue);
}
}
if (!missingRequiredFields.isEmpty()) {
throw new RuntimeException(objectDefinition.printObjectLabelAndKeys(xmlObject) + " is missing values for the following required fields: " + missingRequiredFields.toString());
}
if (StringUtils.equalsIgnoreCase(maintenanceAction, KRADConstants.MAINTENANCE_NEW_ACTION)) {
objectDefinition.makeBusinessObjectActiveIfApplicable(xmlObject, businessObject);
}
return businessObject;
}
Aggregations