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.sys.businessobject.lookup;
017
018import java.util.Properties;
019
020import org.kuali.ole.sys.businessobject.TaxRegion;
021import org.kuali.ole.sys.businessobject.TaxRegionType;
022import org.kuali.ole.sys.context.SpringContext;
023import org.kuali.rice.core.api.config.property.ConfigurationService;
024import org.kuali.rice.kns.lookup.KualiLookupableImpl;
025import org.kuali.rice.krad.util.KRADConstants;
026import org.kuali.rice.krad.util.UrlFactory;
027
028public class TaxRegionLookupableImpl extends KualiLookupableImpl {
029
030    /**
031     * Make create new action go to Tax Region Type lookup first. Adding the tax region from lookup indicator
032     * (CREATE_TAX_REGION_FROM_LOOKUP_INDICATOR) to the conversion fields to control when you should do a regular tax region type
033     * code lookup vs. one that actually creates a tax region.  This indicator is then used in
034     * TaxRegionTypeLookupableImpl.
035     * 
036     * @see org.kuali.core.lookup.KualiLookupableImpl#getCreateNewUrl()
037     */
038    @Override
039    public String getCreateNewUrl() {
040        String url = "";
041
042        if (getLookupableHelperService().allowsMaintenanceNewOrCopyAction()) {
043            Properties parameters = new Properties();
044            parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, TaxRegionType.class.getName());
045            parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY) + "/" + KRADConstants.MAPPING_PORTAL);
046            parameters.put(KRADConstants.DOC_FORM_KEY, getTaxRegionDocumentTypeName()); 
047            parameters.put(KRADConstants.CONVERSION_FIELDS_PARAMETER, "taxRegionTypeCode:taxRegionTypeCode");
048            url = getCreateNewUrl(UrlFactory.parameterizeUrl(KRADConstants.LOOKUP_ACTION, parameters)); 
049        }
050
051        return url;
052    }
053    
054    private String getTaxRegionDocumentTypeName() {
055        return getDataDictionaryService().getDataDictionary().getMaintenanceDocumentEntryForBusinessObjectClass(TaxRegion.class).getDocumentTypeName();
056    } 
057
058}