View Javadoc
1   package org.kuali.ole.select.lookup;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.select.bo.OleLicenseRequestBo;
6   import org.kuali.ole.service.OleLicenseRequestService;
7   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
8   import org.kuali.rice.krad.lookup.LookupableImpl;
9   import org.kuali.rice.krad.uif.UifConstants;
10  import org.kuali.rice.krad.uif.UifParameters;
11  import org.kuali.rice.krad.uif.view.LookupView;
12  import org.kuali.rice.krad.util.GlobalVariables;
13  import org.kuali.rice.krad.util.KRADConstants;
14  import org.kuali.rice.krad.util.KRADUtils;
15  import org.kuali.rice.krad.util.UrlFactory;
16  import org.kuali.rice.krad.web.form.LookupForm;
17  
18  import java.text.SimpleDateFormat;
19  import java.util.*;
20  
21  /**
22   * OleLicenseRequestLookupableImpl is the view helper service class for Ole License Request Document
23   */
24  public class OleLicenseRequestLookupableImpl extends LookupableImpl {
25  
26      private OleLicenseRequestService oleLicenseRequestService;
27  
28      private String returnLocation = "";
29  
30      /**
31       * Gets the returnLocation attribute.
32       *
33       * @return Returns the returnLocation
34       */
35      public String getReturnLocation() {
36          return returnLocation;
37      }
38  
39      /**
40       * Sets the returnLocation attribute value.
41       *
42       * @param returnLocation The returnLocation to set.
43       */
44      public void setReturnLocation(String returnLocation) {
45          this.returnLocation = returnLocation;
46      }
47  
48      /**
49       * This method returns action URL as oleLicenseRequest.
50       *
51       * @param lookupForm
52       * @param dataObject
53       * @param methodToCall
54       * @param pkNames
55       * @return String
56       */
57      @Override
58      protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall,
59                                        List<String> pkNames) {
60          LookupView lookupView = (LookupView) lookupForm.getView();
61  
62          Properties props = new Properties();
63          props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
64  
65          Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
66          for (String primaryKey : primaryKeyValues.keySet()) {
67              String primaryKeyValue = primaryKeyValues.get(primaryKey);
68  
69              props.put(primaryKey, primaryKeyValue);
70          }
71  
72          if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
73              props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
74              returnLocation = lookupForm.getReturnLocation();
75          }
76  
77          props.put(UifParameters.DATA_OBJECT_CLASS_NAME, lookupForm.getDataObjectClassName());
78          props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
79  
80          String maintenanceMapping = "oleLicenseRequest";
81  
82          return UrlFactory.parameterizeUrl(maintenanceMapping, props);
83      }
84  
85      /**
86       * This method performs the search for license request based on the search criterias
87       *
88       * @param form
89       * @param criteria
90       * @param bounded
91       * @return
92       */
93      @Override
94      public Collection<?> performSearch(LookupForm form, Map<String, String> criteria, boolean bounded) {
95          returnLocation = form.getReturnLocation();
96          SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
97          String createdDateFrom = criteria.get(OLEConstants.OleLicenseRequest.CREATED_FROM_DATE);
98          String createdDateTo = criteria.get(OLEConstants.OleLicenseRequest.CREATED_TO_DATE);
99          String lastModifiedDateFrom = criteria.get(OLEConstants.OleLicenseRequest.LAST_MOD_FROM_DATE);
100         String lastModifiedDateTo = criteria.get(OLEConstants.OleLicenseRequest.LAST_MOD_TO_DATE);
101         /*String bibliographicTitle = criteria.get(OLEConstants.OleLicenseRequest.BIB_TITLE);
102         String licenseRequestStatusCode = criteria.get(OLEConstants.OleLicenseRequest.STATUS_CODE);
103         String assignee = criteria.get(OLEConstants.OleLicenseRequest.ASSIGNEE);
104         String locationId = criteria.get(OLEConstants.OleLicenseRequest.LOCATION_ID);
105         String licenseRequestTypeId = criteria.get(OLEConstants.OleLicenseRequest.LICENSE_REQUEST_TYPE_ID) ;*/
106 
107         if (!createdDateFrom.equalsIgnoreCase("") && !createdDateTo.equalsIgnoreCase("")) {
108             if (createdDateFrom.compareTo(createdDateTo) > 0) {
109                 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleLicenseRequest.ERROR_DATE_FROM_EXCEEDS_DATE_TO);
110                 return Collections.emptyList();
111             }
112         }
113         if (!lastModifiedDateFrom.equalsIgnoreCase("") && !lastModifiedDateTo.equalsIgnoreCase("")) {
114             if (lastModifiedDateFrom.compareTo(lastModifiedDateTo) > 0) {
115                 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleLicenseRequest.ERROR_DATE_FROM_EXCEEDS_DATE_TO);
116                 return Collections.emptyList();
117             }
118         }/*else if (bibliographicTitle.isEmpty() && licenseRequestStatusCode.isEmpty() && assignee.isEmpty() &&
119                 locationId.isEmpty() && licenseRequestTypeId.isEmpty() && createdDateFrom.equalsIgnoreCase("") && createdDateTo.equalsIgnoreCase("")) {
120                 createdDateFrom = dateFormat.format(new Date());
121                 criteria.put(OLEConstants.OleLicenseRequest.CREATED_FROM_DATE,createdDateFrom);
122             }*/
123         Collection<?> displayList = null;
124         try {
125             displayList = getOleLicenseRequestservice().findLicenseRequestByCriteria(criteria);
126         } catch (Exception e) {
127             e.printStackTrace();
128             throw new RuntimeException(e);
129         }
130         if (displayList.size() == 0) {
131             GlobalVariables.getMessageMap().putInfo(OLEConstants.OleLicenseRequest.ERROR_NOT_FOUND, OLEConstants.OleLicenseRequest.ERROR_NOT_FOUND);
132         }
133         return displayList;
134 
135     }
136 
137 
138     /**
139      * This method returns the url for viewing the Requisition Document
140      *
141      * @param object
142      * @return url
143      */
144     public String viewParticularDocument(Object object) {
145         OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo) object;
146         String url = "";
147         if (returnLocation != null & !returnLocation.isEmpty())
148             url = returnLocation.substring(0, returnLocation.indexOf("portal.do"));
149         return url + "kew/DocHandler.do?command=displayDocSearchView&docId=" + oleLicenseRequestBo.getDocumentNumber();
150     }
151 
152     /**
153      * This method returns the OleLicenseRequestService object
154      *
155      * @return
156      */
157     public OleLicenseRequestService getOleLicenseRequestservice() {
158         if (oleLicenseRequestService == null) {
159             oleLicenseRequestService = GlobalResourceLoader.getService("oleLicenseRequestService");
160         }
161         return oleLicenseRequestService;
162     }
163 
164 }