001/*
002 * Copyright 2008 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 */
016package org.kuali.ole.pdp.businessobject.lookup;
017
018import java.util.ArrayList;
019import java.util.HashMap;
020import java.util.List;
021import java.util.Map;
022import java.util.Properties;
023
024import org.kuali.ole.pdp.PdpConstants;
025import org.kuali.ole.pdp.PdpKeyConstants;
026import org.kuali.ole.pdp.PdpParameterConstants;
027import org.kuali.ole.pdp.PdpPropertyConstants;
028import org.kuali.ole.pdp.businessobject.FormatProcess;
029import org.kuali.ole.pdp.businessobject.PaymentProcess;
030import org.kuali.ole.pdp.service.PdpAuthorizationService;
031import org.kuali.ole.sys.OLEConstants;
032import org.kuali.rice.core.api.config.property.ConfigurationService;
033import org.kuali.rice.kim.api.identity.Person;
034import org.kuali.rice.kns.lookup.HtmlData;
035import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
036import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
037import org.kuali.rice.krad.bo.BusinessObject;
038import org.kuali.rice.krad.util.GlobalVariables;
039import org.kuali.rice.krad.util.ObjectUtils;
040import org.kuali.rice.krad.util.UrlFactory;
041
042/**
043 * This class allows custom handling of FormatProcesses within the lookup framework.
044 */
045public class FormatProcessLookupableHelperService extends KualiLookupableHelperServiceImpl {
046
047    private ConfigurationService 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.krad.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 = OLEConstants.EMPTY_STRING;
074            String url = OLEConstants.EMPTY_STRING;
075            String basePath = configurationService.getPropertyValueAsString(OLEConstants.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(OLEConstants.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.getPropertyValueAsString(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("&nbsp;", "", "");
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 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}