001package org.kuali.ole.deliver.lookup;
002
003import org.apache.commons.lang.StringUtils;
004import org.kuali.ole.OLEConstants;
005import org.kuali.ole.deliver.bo.OleCirculationDesk;
006import org.kuali.rice.krad.lookup.LookupView;
007import org.kuali.rice.krad.lookup.LookupableImpl;
008import org.kuali.rice.krad.uif.UifConstants;
009import org.kuali.rice.krad.uif.UifParameters;
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.lookup.LookupForm;
015
016import java.util.*;
017
018/**
019 * OleLicenseRequestLookupableImpl is the view helper service class for Ole License Request Document
020 */
021public class OleCirculationDeskLocationLookupableImpl extends LookupableImpl {
022    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleCirculationDeskLocationLookupableImpl.class);
023
024    /**
025     * This method returns action URL as oleLicenseRequest.
026     *
027     * @param lookupForm
028     * @param dataObject
029     * @param methodToCall
030     * @param pkNames
031     * @return String
032     */
033    protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall,
034                                      List<String> pkNames) {
035        LOG.debug("Inside getActionUrlHref()");
036        LookupView lookupView = (LookupView) lookupForm.getView();
037
038        Properties props = new Properties();
039        props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
040        Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
041        for (String primaryKey : primaryKeyValues.keySet()) {
042            String primaryKeyValue = primaryKeyValues.get(primaryKey);
043
044            props.put(primaryKey, primaryKeyValue);
045        }
046
047        if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
048            props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
049        }
050
051        props.put(UifParameters.DATA_OBJECT_CLASS_NAME, OleCirculationDesk.class.getName());
052        props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
053
054        String maintenanceMapping = "oleCirculationDeskMaintenance";
055
056        return UrlFactory.parameterizeUrl(maintenanceMapping, props);
057    }
058
059    @Override
060    /*protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {*/
061    public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
062
063        List<?> searchResults;
064        List<OleCirculationDesk> finalSearchResult = new ArrayList<OleCirculationDesk>();
065        List<OleCirculationDesk> oleCirculationDesk = new ArrayList<OleCirculationDesk>();
066
067        /*oleCirculationDesk = (List<OleCirculationDesk>) super.getSearchResults(form, searchCriteria, unbounded);*/
068        oleCirculationDesk = (List<OleCirculationDesk>) super.performSearch(form, searchCriteria, unbounded);
069        finalSearchResult.addAll(oleCirculationDesk);
070
071        searchResults = finalSearchResult;
072        if (searchResults.size() == 0) {
073            GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
074        }
075        sortSearchResults(form, searchResults);
076        return searchResults;
077    }
078
079    @Override
080    protected String getMaintenanceActionUrl(LookupForm lookupForm, Object dataObject, String methodToCall,
081                                             List<String> pkNames) {
082        LookupView lookupView = (LookupView) lookupForm.getView();
083
084        Properties props = new Properties();
085        props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
086
087        Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
088        for (String primaryKey : primaryKeyValues.keySet()) {
089            String primaryKeyValue = primaryKeyValues.get(primaryKey);
090
091            props.put(primaryKey, primaryKeyValue);
092        }
093
094        if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
095            props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
096        }
097
098        props.put(UifParameters.DATA_OBJECT_CLASS_NAME, lookupForm.getDataObjectClassName());
099        props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
100
101        String maintenanceMapping = OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_MAINTENANCE_ACTION_LINK;
102
103        return UrlFactory.parameterizeUrl(maintenanceMapping, props);
104    }
105
106
107}