001package org.kuali.ole.describe.lookup;
002
003import org.apache.commons.lang.StringUtils;
004import org.kuali.ole.OLEConstants;
005import org.kuali.ole.deliver.bo.OleItemSearch;
006import org.kuali.ole.describe.bo.ImportBibUserPreferences;
007import org.kuali.ole.describe.service.DocstoreHelperService;
008import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
009import org.kuali.rice.krad.lookup.LookupableImpl;
010import org.kuali.rice.krad.service.KRADServiceLocator;
011import org.kuali.rice.krad.uif.UifConstants;
012import org.kuali.rice.krad.uif.UifParameters;
013import org.kuali.rice.krad.uif.view.LookupView;
014import org.kuali.rice.krad.util.GlobalVariables;
015import org.kuali.rice.krad.util.KRADConstants;
016import org.kuali.rice.krad.util.KRADUtils;
017import org.kuali.rice.krad.util.UrlFactory;
018import org.kuali.rice.krad.web.form.LookupForm;
019
020import java.util.*;
021
022/**
023 * Created with IntelliJ IDEA.
024 * User: PJ7789
025 * Date: 27/12/12
026 * Time: 6:41 PM
027 * To change this template use File | Settings | File Templates.
028 */
029public class OleUserPreferencesLookupableImpl
030        extends LookupableImpl {
031    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(
032            OleUserPreferencesLookupableImpl.class);
033
034    /**
035     * This method is to override the maintenance mapping
036     *
037     * @param lookupForm
038     * @param dataObject
039     * @param methodToCall
040     * @param pkNames
041     * @return mapping Url
042     */
043    @Override
044    protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall,
045                                      List<String> pkNames) {
046        LOG.debug("Inside getActionUrlHref()");
047        LookupView lookupView = (LookupView) lookupForm.getView();
048
049        Properties props = new Properties();
050        props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
051        LOG.info("Method to call = " + methodToCall);
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, ImportBibUserPreferences.class.getName());
064        props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
065
066        String maintenanceMapping = OLEConstants.OleUserPreferences.USER_PREF_MAINTENANCE_ACTION_LINK;
067
068        return UrlFactory.parameterizeUrl(maintenanceMapping, props);
069    }
070
071    @Override
072    public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
073        LOG.debug("Inside performSearch()");
074        Map<String, String> criteriaMap = new HashMap<String, String>();
075        List<ImportBibUserPreferences> importBibUserPreferencesList = new ArrayList<ImportBibUserPreferences>();
076
077        String shelvingScheme = ((String) searchCriteria.get("shelvingScheme"));
078        if (shelvingScheme != null && !shelvingScheme.equals("")) {
079            criteriaMap.put("shelvingScheme", shelvingScheme);
080            LOG.info("shelvingScheme = " + shelvingScheme);
081        }
082        String importStatus = ((String) searchCriteria.get("importStatus"));
083        if (importStatus != null && !importStatus.equals("")) {
084            criteriaMap.put("importStatus", importStatus);
085            LOG.info("importStatus = " + importStatus);
086        }
087
088        String importType = ((String) searchCriteria.get("importType"));
089        if (importType != null && !importType.equals("")) {
090            criteriaMap.put("importType", importType);
091            LOG.info("importType = " + importType);
092        }
093
094        String removalTags = ((String) searchCriteria.get("removalTags"));
095        if (removalTags != null && !removalTags.equals("")) {
096            criteriaMap.put("removalTags", removalTags);
097            LOG.info("removalTags = " + removalTags);
098        }
099
100        String protectedTags = ((String) searchCriteria.get("protectedTags"));
101        if (protectedTags != null && !protectedTags.equals("")) {
102            criteriaMap.put("protectedTags", protectedTags);
103            LOG.info("protectedTags = " + protectedTags);
104        }
105
106        String permLocation = ((String) searchCriteria.get("permLocation"));
107        if (permLocation != null && !permLocation.equals("")) {
108            criteriaMap.put("permLocation", permLocation);
109            LOG.info("permLocation = " + permLocation);
110        }
111
112        String callNumberSource1 = ((String) searchCriteria.get("callNumberSource1"));
113        if (callNumberSource1 != null && !callNumberSource1.equals("")) {
114            criteriaMap.put("callNumberSource1", callNumberSource1);
115            LOG.info("callNumberSource1 = " + callNumberSource1);
116        }
117
118        String callNumberSource2 = ((String) searchCriteria.get("callNumberSource2"));
119        if (callNumberSource2 != null && !callNumberSource2.equals("")) {
120            criteriaMap.put("callNumberSource2", callNumberSource2);
121            LOG.info("callNumberSource2 = " + callNumberSource2);
122        }
123
124        String callNumberSource3 = ((String) searchCriteria.get("callNumberSource3"));
125        if (callNumberSource3 != null && !callNumberSource3.equals("")) {
126            criteriaMap.put("callNumberSource3", callNumberSource3);
127            LOG.info("callNumberSource3 = " + callNumberSource3);
128        }
129
130        String prefName = ((String) searchCriteria.get("prefName"));
131        if (prefName != null && !prefName.equals("")) {
132            criteriaMap.put("prefName", prefName);
133            LOG.info("prefName = " + prefName);
134        }
135
136        String tempLocation = ((String) searchCriteria.get("tempLocation"));
137        if (tempLocation != null && !tempLocation.equals("")) {
138            criteriaMap.put("tempLocation", tempLocation);
139            LOG.info("tempLocation = " + tempLocation);
140        }
141        importBibUserPreferencesList = (List<ImportBibUserPreferences>) KRADServiceLocator.getBusinessObjectService().findMatching(ImportBibUserPreferences.class, criteriaMap);
142        return importBibUserPreferencesList;
143    }
144}