1 /*
2 * Copyright 2007 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.coa.businessobject.lookup;
17
18 import java.util.List;
19 import java.util.Map;
20 import java.util.Properties;
21
22 import org.kuali.ole.coa.businessobject.AccountDelegateGlobal;
23 import org.kuali.ole.sys.OLEConstants;
24 import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
25 import org.kuali.rice.kns.lookup.HtmlData;
26 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
27 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
28 import org.kuali.rice.kns.web.struts.form.LookupForm;
29 import org.kuali.rice.krad.bo.BusinessObject;
30
31 /**
32 * This class overrides the getBackLocation, getReturnUrl, setFieldConversions and getActionUrls for
33 * {@link OrganizationRoutingModelName}
34 */
35 public class OrganizationRoutingModelNameLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
36 private boolean initializingDelegate = true;
37
38 /**
39 * Overrides the base implementation to always return to {@link OLEConstants.MAINTENANCE_ACTION}
40 *
41 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getBackLocation()
42 */
43 @Override
44 public String getBackLocation() {
45 // it doesn't really matter what the backLocation is set to; we're
46 // always going to return to the maintenance screen
47 return OLEConstants.MAINTENANCE_ACTION;
48 }
49
50 /**
51 * Overrides the base implementation to add in new parameters to the return url
52 * <ul>
53 * <li>{@link OLEConstants.DISPATCH_REQUEST_PARAMETER}</li>
54 * <li>{@link OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE}</li>
55 * <li>{@link OLEConstants.OVERRIDE_KEYS}</li>
56 * </ul>
57 * {@link OLEConstants.DISPATCH_REQUEST_PARAMETER}
58 *
59 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getReturnUrl(org.kuali.rice.krad.bo.BusinessObject, java.util.Map,
60 * java.lang.String)
61 */
62 @Override
63 public HtmlData getReturnUrl(BusinessObject businessObject, LookupForm lookupForm, List returnKeys, BusinessObjectRestrictions businessObjectRestrictions) {
64 String originalBackLocation = this.backLocation;
65 Properties parameters = getParameters(businessObject, lookupForm.getFieldConversions(), lookupForm.getLookupableImplServiceName(), returnKeys);
66 parameters.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.MAINTENANCE_NEWWITHEXISTING_ACTION);
67 parameters.put(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, AccountDelegateGlobal.class.getName());
68 parameters.put(OLEConstants.OVERRIDE_KEYS, "modelName" + OLEConstants.FIELD_CONVERSIONS_SEPERATOR + "modelChartOfAccountsCode" + OLEConstants.FIELD_CONVERSIONS_SEPERATOR + "modelOrganizationCode");
69 setBackLocation(OLEConstants.MAINTENANCE_ACTION);
70 AnchorHtmlData htmlData = (AnchorHtmlData)getReturnAnchorHtmlData(businessObject, parameters, lookupForm, returnKeys, businessObjectRestrictions);
71 setBackLocation(originalBackLocation); //set this to prevent breaking Account Delegate Model returnLocation
72 return htmlData;
73 }
74
75 /**
76 * Overrides base implementation to determine whether or not we are dealing with looking up the model or editing it
77 *
78 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#setFieldConversions(java.util.Map)
79 */
80 @Override
81 public void setFieldConversions(Map fieldConversions) {
82 super.setFieldConversions(fieldConversions);
83 if (fieldConversions == null || fieldConversions.size() == 0) {
84 // if we don't have any field conversions, then we must be
85 // actually dealing with the model, instead of looking up the model
86 // in order to initalize a new global account delegate
87 //
88 // yeah, it's a hack...but at least a semi-clever hack
89 initializingDelegate = false;
90 }
91 }
92
93 /**
94 * Overrides base implementation to remove the action urls if we are initializing the delegate model
95 *
96 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.krad.bo.BusinessObject, java.util.List)
97 */
98 @Override
99 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
100 if (!initializingDelegate) {
101 return super.getCustomActionUrls(businessObject, pkNames);
102 }
103 else {
104 return super.getEmptyActionUrls();
105 }
106 }
107 }