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