001package org.kuali.ole.describe.lookup;
002
003import org.apache.commons.lang.StringUtils;
004import org.kuali.ole.OLEConstants;
005import org.kuali.ole.describe.bo.OleItemAvailableStatus;
006import org.kuali.rice.krad.lookup.LookupableImpl;
007import org.kuali.rice.krad.uif.UifConstants;
008import org.kuali.rice.krad.uif.UifParameters;
009import org.kuali.rice.krad.uif.view.LookupView;
010import org.kuali.rice.krad.util.GlobalVariables;
011import org.kuali.rice.krad.util.KRADConstants;
012import org.kuali.rice.krad.util.KRADUtils;
013import org.kuali.rice.krad.util.UrlFactory;
014import org.kuali.rice.krad.web.form.LookupForm;
015
016import java.util.ArrayList;
017import java.util.List;
018import java.util.Map;
019import java.util.Properties;
020
021/**
022 * Created with IntelliJ IDEA.
023 * User: ?
024 * Date: 1/24/13
025 * Time: 4:17 PM
026 * To change this template use File | Settings | File Templates.
027 */
028public class OleItemAvailableStatusLookupableImpl extends LookupableImpl {
029    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleInstanceItemTypeLookupableImpl.class);
030
031
032    /**
033     * Generates a URL to perform a maintenance action on the given result data object
034     * <p/>
035     * <p>
036     * Will build a URL containing keys of the data object to invoke the given maintenance action method
037     * within the maintenance controller
038     * </p>
039     *
040     * @param dataObject   - data object instance for the line to build the maintenance action link for
041     * @param methodToCall - method name on the maintenance controller that should be invoked
042     * @param pkNames      - list of primary key field names for the data object whose key/value pairs will be added to
043     *                     the maintenance link
044     * @return String URL link for the maintenance action
045     */
046    protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall,
047                                      List<String> pkNames) {
048        LookupView lookupView = (LookupView) lookupForm.getView();
049        Properties props = new Properties();
050        props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
051
052        Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
053        for (String primaryKey : primaryKeyValues.keySet()) {
054            String primaryKeyValue = primaryKeyValues.get(primaryKey);
055
056            props.put(primaryKey, primaryKeyValue);
057        }
058
059        if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
060            props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
061        }
062
063        props.put(UifParameters.DATA_OBJECT_CLASS_NAME, lookupForm.getDataObjectClassName());
064        props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
065
066        String maintenanceMapping = "itemAvailableStatusMaintenance";
067
068        return UrlFactory.parameterizeUrl(maintenanceMapping, props);
069    }
070
071    @Override
072    protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
073
074        List<?> searchResults;
075        List<OleItemAvailableStatus> finalSearchResult = new ArrayList<OleItemAvailableStatus>();
076        List<OleItemAvailableStatus> oleItemAvailableStatus = new ArrayList<OleItemAvailableStatus>();
077
078        oleItemAvailableStatus = (List<OleItemAvailableStatus>) super.getSearchResults(form, searchCriteria, unbounded);
079        finalSearchResult.addAll(oleItemAvailableStatus);
080
081        searchResults = finalSearchResult;
082        if (searchResults.size() == 0) {
083            GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
084        }
085        sortSearchResults(form, searchResults);
086        return searchResults;
087    }
088
089}