View Javadoc

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