001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.pdp.businessobject.lookup;
017
018 import java.util.ArrayList;
019 import java.util.HashMap;
020 import java.util.List;
021 import java.util.Map;
022 import java.util.Properties;
023
024 import org.kuali.kfs.pdp.PdpConstants;
025 import org.kuali.kfs.pdp.PdpKeyConstants;
026 import org.kuali.kfs.pdp.PdpParameterConstants;
027 import org.kuali.kfs.pdp.PdpPropertyConstants;
028 import org.kuali.kfs.pdp.businessobject.FormatProcess;
029 import org.kuali.kfs.pdp.businessobject.PaymentProcess;
030 import org.kuali.kfs.pdp.service.PdpAuthorizationService;
031 import org.kuali.kfs.sys.KFSConstants;
032 import org.kuali.rice.kim.bo.Person;
033 import org.kuali.rice.kns.bo.BusinessObject;
034 import org.kuali.rice.kns.lookup.HtmlData;
035 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
036 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
037 import org.kuali.rice.kns.service.KualiConfigurationService;
038 import org.kuali.rice.kns.util.GlobalVariables;
039 import org.kuali.rice.kns.util.ObjectUtils;
040 import org.kuali.rice.kns.util.UrlFactory;
041
042 /**
043 * This class allows custom handling of FormatProcesses within the lookup framework.
044 */
045 public class FormatProcessLookupableHelperService extends KualiLookupableHelperServiceImpl {
046
047 private KualiConfigurationService configurationService;
048 private PdpAuthorizationService pdpAuthorizationService;
049
050 /**
051 * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResults(java.util.Map)
052 */
053 @Override
054 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
055 return super.getSearchResults(fieldValues);
056 }
057
058 /**
059 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject, java.util.List)
060 */
061 @Override
062 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
063 List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>();
064 if (businessObject instanceof FormatProcess) {
065 Person person = GlobalVariables.getUserSession().getPerson();
066 FormatProcess formatProcess = (FormatProcess) businessObject;
067 int processId = formatProcess.getPaymentProcIdentifier();
068
069 Map primaryKeys = new HashMap();
070 primaryKeys.put(PdpPropertyConstants.PaymentProcess.PAYMENT_PROCESS_ID, processId);
071 PaymentProcess paymentProcess = (PaymentProcess) getBusinessObjectService().findByPrimaryKey(PaymentProcess.class, primaryKeys);
072
073 String linkText = KFSConstants.EMPTY_STRING;
074 String url = KFSConstants.EMPTY_STRING;
075 String basePath = configurationService.getPropertyString(KFSConstants.APPLICATION_URL_KEY) + "/" + PdpConstants.Actions.FORMAT_PROCESS_ACTION;
076
077 if (pdpAuthorizationService.hasRemoveFormatLockPermission(person.getPrincipalId()) && ObjectUtils.isNotNull(paymentProcess) && !paymentProcess.isFormattedIndicator()) {
078 Properties params = new Properties();
079 params.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, PdpConstants.ActionMethods.CLEAR_FORMAT_PROCESS_ACTION);
080 params.put(PdpParameterConstants.FormatProcess.PROCESS_ID_PARAM, UrlFactory.encode(String.valueOf(processId)));
081 url = UrlFactory.parameterizeUrl(basePath, params);
082
083 linkText = configurationService.getPropertyString(PdpKeyConstants.FormatProcess.CLEAR_UNFINISHED_FORMAT_PROCESS);
084
085 AnchorHtmlData anchorHtmlData = new AnchorHtmlData(url, PdpConstants.ActionMethods.CONFIRM_CANCEL_ACTION, linkText);
086 anchorHtmlDataList.add(anchorHtmlData);
087 }
088 else {
089 AnchorHtmlData anchorHtmlData = new AnchorHtmlData(" ", "", "");
090 anchorHtmlDataList.add(anchorHtmlData);
091 }
092
093 }
094 return anchorHtmlDataList;
095 }
096
097 /**
098 * This method gets the configurationService.
099 *
100 * @return configurationService
101 */
102 public KualiConfigurationService getConfigurationService() {
103 return configurationService;
104 }
105
106 /**
107 * This method sets the configurationService.
108 * @param configurationService
109 */
110 public void setConfigurationService(KualiConfigurationService 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 }