Search in sources :

Example 1 with RassListPropertyDefinition

use of edu.cornell.kfs.rass.batch.RassListPropertyDefinition 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;
}
Also used : RassListPropertyDefinition(edu.cornell.kfs.rass.batch.RassListPropertyDefinition) ArrayList(java.util.ArrayList) RassPropertyDefinition(edu.cornell.kfs.rass.batch.RassPropertyDefinition) RassXmlObject(edu.cornell.kfs.rass.batch.xml.RassXmlObject) PersistableBusinessObject(org.kuali.kfs.krad.bo.PersistableBusinessObject) AutoPopulatingList(org.springframework.util.AutoPopulatingList) List(java.util.List) ArrayList(java.util.ArrayList) RassValueConverter(edu.cornell.kfs.rass.batch.RassValueConverter)

Aggregations

RassListPropertyDefinition (edu.cornell.kfs.rass.batch.RassListPropertyDefinition)1 RassPropertyDefinition (edu.cornell.kfs.rass.batch.RassPropertyDefinition)1 RassValueConverter (edu.cornell.kfs.rass.batch.RassValueConverter)1 RassXmlObject (edu.cornell.kfs.rass.batch.xml.RassXmlObject)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PersistableBusinessObject (org.kuali.kfs.krad.bo.PersistableBusinessObject)1 AutoPopulatingList (org.springframework.util.AutoPopulatingList)1