001package org.kuali.rice.krad.service.impl;
002
003import org.kuali.rice.krad.data.metadata.DataObjectMetadata;
004import org.kuali.rice.krad.service.KRADServiceLocator;
005import org.kuali.rice.krad.util.KRADUtils;
006import org.springframework.beans.PropertyAccessorUtils;
007
008import java.util.HashMap;
009import java.util.List;
010import java.util.Map;
011
012/**
013 * An extension of {@link KRADLegacyDataAdapterImpl} to work around rice bug
014 * TODO: KSENROLL-12567 remove class KSKRADLegacyDataAdapterImpl
015 *
016 * TODO: KSCM-2322 - This class is duplicated at
017 * ks-cm-krad/src/main/java/org/kuali/student/cm/rice/KSKRADLegacyDataAdapterImpl.java
018 */
019public class KSKRADLegacyDataAdapterImpl extends KRADLegacyDataAdapterImpl {
020    @Override
021    public Map<String, String> getInquiryParameters(Object dataObject, List<String> keys, String propertyName) {
022        Map<String, String> inquiryParameters = new HashMap<String, String>();
023        DataObjectMetadata objectMetadata =
024                KRADServiceLocator.getDataObjectService().getMetadataRepository().getMetadata(dataObject.getClass());
025        org.kuali.rice.krad.data.metadata.DataObjectRelationship dataObjectRelationship = null;
026        // KS customization: added null check for objectMetadata
027        if (objectMetadata != null) {
028            objectMetadata.getRelationshipByLastAttributeInRelationship(propertyName);
029        }
030        for (String keyName : keys) {
031            String keyConversion = keyName;
032            if (dataObjectRelationship != null) {
033                keyConversion = dataObjectRelationship.getParentAttributeNameRelatedToChildAttributeName(keyName);
034            } else if (PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName)) {
035                String nestedAttributePrefix = KRADUtils.getNestedAttributePrefix(propertyName);
036                keyConversion = nestedAttributePrefix + "." + keyName;
037            }
038            inquiryParameters.put(keyConversion, keyName);
039        }
040        return inquiryParameters;
041    }
042}