View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.pdp.businessobject.lookup;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.Properties;
23  
24  import org.kuali.ole.pdp.PdpConstants;
25  import org.kuali.ole.pdp.PdpKeyConstants;
26  import org.kuali.ole.pdp.PdpParameterConstants;
27  import org.kuali.ole.pdp.PdpPropertyConstants;
28  import org.kuali.ole.pdp.businessobject.FormatProcess;
29  import org.kuali.ole.pdp.businessobject.PaymentProcess;
30  import org.kuali.ole.pdp.service.PdpAuthorizationService;
31  import org.kuali.ole.sys.OLEConstants;
32  import org.kuali.rice.core.api.config.property.ConfigurationService;
33  import org.kuali.rice.kim.api.identity.Person;
34  import org.kuali.rice.kns.lookup.HtmlData;
35  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
36  import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
37  import org.kuali.rice.krad.bo.BusinessObject;
38  import org.kuali.rice.krad.util.GlobalVariables;
39  import org.kuali.rice.krad.util.ObjectUtils;
40  import org.kuali.rice.krad.util.UrlFactory;
41  
42  /**
43   * This class allows custom handling of FormatProcesses within the lookup framework.
44   */
45  public class FormatProcessLookupableHelperService extends KualiLookupableHelperServiceImpl {
46  
47      private ConfigurationService configurationService;
48      private PdpAuthorizationService pdpAuthorizationService;
49  
50      /**
51       * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResults(java.util.Map)
52       */
53      @Override
54      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
55          return super.getSearchResults(fieldValues);
56      }
57  
58      /**
59       * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.krad.bo.BusinessObject, java.util.List)
60       */
61      @Override
62      public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
63          List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>();
64          if (businessObject instanceof FormatProcess) {
65              Person person = GlobalVariables.getUserSession().getPerson();
66              FormatProcess formatProcess = (FormatProcess) businessObject;
67              int processId = formatProcess.getPaymentProcIdentifier();
68  
69              Map primaryKeys = new HashMap();
70              primaryKeys.put(PdpPropertyConstants.PaymentProcess.PAYMENT_PROCESS_ID, processId);
71              PaymentProcess paymentProcess = (PaymentProcess) getBusinessObjectService().findByPrimaryKey(PaymentProcess.class, primaryKeys);
72  
73              String linkText = OLEConstants.EMPTY_STRING;
74              String url = OLEConstants.EMPTY_STRING;
75              String basePath = configurationService.getPropertyValueAsString(OLEConstants.APPLICATION_URL_KEY) + "/" + PdpConstants.Actions.FORMAT_PROCESS_ACTION;
76  
77              if (pdpAuthorizationService.hasRemoveFormatLockPermission(person.getPrincipalId()) && ObjectUtils.isNotNull(paymentProcess) && !paymentProcess.isFormattedIndicator()) {
78                  Properties params = new Properties();
79                  params.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, PdpConstants.ActionMethods.CLEAR_FORMAT_PROCESS_ACTION);
80                  params.put(PdpParameterConstants.FormatProcess.PROCESS_ID_PARAM, UrlFactory.encode(String.valueOf(processId)));
81                  url = UrlFactory.parameterizeUrl(basePath, params);
82  
83                  linkText = configurationService.getPropertyValueAsString(PdpKeyConstants.FormatProcess.CLEAR_UNFINISHED_FORMAT_PROCESS);
84  
85                  AnchorHtmlData anchorHtmlData = new AnchorHtmlData(url, PdpConstants.ActionMethods.CONFIRM_CANCEL_ACTION, linkText);
86                  anchorHtmlDataList.add(anchorHtmlData);
87              }
88              else {
89                  AnchorHtmlData anchorHtmlData = new AnchorHtmlData("&nbsp;", "", "");
90                  anchorHtmlDataList.add(anchorHtmlData);
91              }
92  
93          }
94          return anchorHtmlDataList;
95      }
96  
97      /**
98       * This method gets the configurationService.
99       * 
100      * @return configurationService
101      */
102     public ConfigurationService getConfigurationService() {
103         return configurationService;
104     }
105 
106     /**
107      * This method sets the configurationService.
108      * @param configurationService
109      */
110     public void setConfigurationService(ConfigurationService configurationService) {
111         this.configurationService = configurationService;
112     }
113 
114     /**
115      * This method sets the pdpAuthorizationService.
116      * @param pdpAuthorizationService The pdpAuthorizationService to be set.
117      */
118     public void setPdpAuthorizationService(PdpAuthorizationService pdpAuthorizationService) {
119         this.pdpAuthorizationService = pdpAuthorizationService;
120     }
121 }