001package org.kuali.ole.select.lookup;
002
003import org.apache.commons.lang.StringUtils;
004import org.kuali.ole.OLEConstants;
005import org.kuali.rice.krad.lookup.LookupableImpl;
006import org.kuali.rice.krad.uif.UifConstants;
007import org.kuali.rice.krad.uif.UifParameters;
008import org.kuali.rice.krad.uif.view.LookupView;
009import org.kuali.rice.krad.util.KRADConstants;
010import org.kuali.rice.krad.util.KRADUtils;
011import org.kuali.rice.krad.util.UrlFactory;
012import org.kuali.rice.krad.web.form.LookupForm;
013
014import java.util.List;
015import java.util.Map;
016import java.util.Properties;
017
018/**
019 * Created with IntelliJ IDEA.
020 * User: JuliyaMonica.S
021 * Date: 10/26/12
022 * Time: 7:44 PM
023 * To change this template use File | Settings | File Templates.
024 */
025public class OleGloballyProtectedFieldLookupableImpl extends LookupableImpl {
026
027    /**
028     * This method returns  URL for checklist maintenance action.
029     *
030     * @param lookupForm
031     * @param dataObject
032     * @param methodToCall
033     * @param pkNames
034     * @return String
035     */
036    @Override
037    protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall,
038                                      List<String> pkNames) {
039        LookupView lookupView = (LookupView) lookupForm.getView();
040
041        Properties props = new Properties();
042        props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
043
044        Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
045        for (String primaryKey : primaryKeyValues.keySet()) {
046            String primaryKeyValue = primaryKeyValues.get(primaryKey);
047
048            props.put(primaryKey, primaryKeyValue);
049        }
050
051        if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
052            props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
053        }
054
055        props.put(UifParameters.DATA_OBJECT_CLASS_NAME, lookupForm.getDataObjectClassName());
056        props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
057
058        String maintenanceMapping = OLEConstants.OleGloballyProtectedField.GLOBALLY_PROTECTED_ACTION_LINK;
059        return UrlFactory.parameterizeUrl(maintenanceMapping, props);
060    }
061}