<commit_before>/*
 * Copyright 2007 The Kuali Foundation.
 *
 * Licensed under the Educational Community License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl1.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.kfs.vnd.businessobject.lookup;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;
import org.kuali.kfs.sys.KFSConstants;
import org.kuali.kfs.vnd.VendorConstants;
import org.kuali.kfs.vnd.VendorKeyConstants;
import org.kuali.kfs.vnd.VendorParameterConstants;
import org.kuali.kfs.vnd.VendorPropertyConstants;
import org.kuali.kfs.vnd.businessobject.VendorAddress;
import org.kuali.kfs.vnd.businessobject.VendorDetail;
import org.kuali.kfs.vnd.document.service.VendorService;
import org.kuali.rice.kns.bo.BusinessObject;
import org.kuali.rice.kns.exception.ValidationException;
import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl;
import org.kuali.rice.kns.lookup.CollectionIncomplete;
import org.kuali.rice.kns.lookup.HtmlData;
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
import org.kuali.rice.kns.service.ParameterService;
import org.kuali.rice.kns.util.BeanPropertyComparator;
import org.kuali.rice.kns.util.GlobalVariables;
import org.kuali.rice.kns.util.KNSConstants;
import org.kuali.rice.kns.util.ObjectUtils;
import org.kuali.rice.kns.util.UrlFactory;
import org.kuali.rice.kns.web.format.Formatter;

public class VendorLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
    private VendorService vendorService;
    private ParameterService parameterService;

    private static String VNDR_LOOKUP_MIN_NAME_LENGTH;
    private static String VNDR_MIN_NUM_LOOKUP_CRITERIA;

    /**
     * Allows only active parent vendors to create new divisions
     *
     * @see org.kuali.rice.kns.lookup.LookupableHelperService#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject, java.util.List, java.util.List pkNames)
     */
    @Override
    public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
        VendorDetail vendor = (VendorDetail) businessObject;
        AnchorHtmlData anchorHtmlData = super.getUrlData(businessObject, KNSConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, pkNames);
        List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>();
        anchorHtmlDataList.add(anchorHtmlData);
        if (vendor.isVendorParentIndicator() && vendor.isActiveIndicator()) {
            // only allow active parent vendors to create new divisions
            anchorHtmlDataList.add(super.getUrlData(
                    businessObject, KFSConstants.MAINTENANCE_NEWWITHEXISTING_ACTION, VendorConstants.CREATE_DIVISION, pkNames));
        }
        return anchorHtmlDataList;
    }

    /**
     * Used by getActionUrls to print the url on the Vendor Lookup page for the links to edit a Vendor or to create a new division.
     * We won't provide a link to copy a vendor because we decided it wouldn't make sense to copy a vendor. We should display the
     * link to create a new division only if the vendor is a parent vendor, and also remove the vendor detail assigned id from the
     * query string in the link to create a new division. We'll add the vendor detail assigned id in the query string if the vendor
     * is not a parent, or if the vendor is a parent and the link is not the create new division link (i.e. if the link is "edit").
     * We'll always add the vendor header id in the query string in all links.
     *
     * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getActionUrlHref(org.kuali.rice.kns.bo.BusinessObject, java.lang.String, java.util.List)
     */
    @Override
    protected String getActionUrlHref(BusinessObject businessObject, String methodToCall, List pkNames){
        if (!methodToCall.equals(KFSConstants.COPY_METHOD)) {
            Properties parameters = new Properties();
            parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
            parameters.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, businessObject.getClass().getName());

            for (Iterator<String> iter = pkNames.iterator(); iter.hasNext();) {<commit_msg>KULPURAP-3607<commit_after>/*
 * Copyright 2007 The Kuali Foundation.
 *
 * Licensed under the Educational Community License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl1.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.kfs.vnd.businessobject.lookup;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;
import org.kuali.kfs.sys.KFSConstants;
import org.kuali.kfs.vnd.VendorConstants;
import org.kuali.kfs.vnd.VendorKeyConstants;
import org.kuali.kfs.vnd.VendorParameterConstants;
import org.kuali.kfs.vnd.VendorPropertyConstants;
import org.kuali.kfs.vnd.businessobject.VendorAddress;
import org.kuali.kfs.vnd.businessobject.VendorDetail;
import org.kuali.kfs.vnd.document.service.VendorService;
import org.kuali.rice.kns.bo.BusinessObject;
import org.kuali.rice.kns.exception.ValidationException;
import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl;
import org.kuali.rice.kns.lookup.CollectionIncomplete;
import org.kuali.rice.kns.lookup.HtmlData;
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
import org.kuali.rice.kns.service.ParameterService;
import org.kuali.rice.kns.util.BeanPropertyComparator;
import org.kuali.rice.kns.util.GlobalVariables;
import org.kuali.rice.kns.util.KNSConstants;
import org.kuali.rice.kns.util.ObjectUtils;
import org.kuali.rice.kns.util.UrlFactory;
import org.kuali.rice.kns.web.format.Formatter;

public class VendorLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
    private VendorService vendorService;
    private ParameterService parameterService;

    private static String VNDR_LOOKUP_MIN_NAME_LENGTH;
    private static String VNDR_MIN_NUM_LOOKUP_CRITERIA;

    /**
     * Allows only active parent vendors to create new divisions
     *
     * @see org.kuali.rice.kns.lookup.LookupableHelperService#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject, java.util.List, java.util.List pkNames)
     */
    @Override
    public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
        VendorDetail vendor = (VendorDetail) businessObject;
        List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>();
        //Adding a "Shopping" link for B2B vendors.
        if (vendor.isB2BVendor()) {
            Properties theProperties = new Properties();
            theProperties.put("channelTitle", "Shop Catalogs");
            String b2bUrlString = "&channelUrl=b2b.do?methodToCall=shopCatalogs";
            String href = UrlFactory.parameterizeUrl(getBackLocation(), theProperties);            
            anchorHtmlDataList.add(new AnchorHtmlData(href + b2bUrlString, null, "Shop"));
        }
        AnchorHtmlData anchorHtmlData = super.getUrlData(businessObject, KNSConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, pkNames);
        anchorHtmlDataList.add(anchorHtmlData);
        if (vendor.isVendorParentIndicator() && vendor.isActiveIndicator()) {
            // only allow active parent vendors to create new divisions
            anchorHtmlDataList.add(super.getUrlData(
                    businessObject, KFSConstants.MAINTENANCE_NEWWITHEXISTING_ACTION, VendorConstants.CREATE_DIVISION, pkNames));
        }
        return anchorHtmlDataList;
    }

    /**
     * Used by getActionUrls to print the url on the Vendor Lookup page for the links to edit a Vendor or to create a new division.
     * We won't provide a link to copy a vendor because we decided it wouldn't make sense to copy a vendor. We should display the
     * link to create a new division only if the vendor is a parent vendor, and also remove the vendor detail assigned id from the
     * query string in the link to create a new division. We'll add the vendor detail assigned id in the query string if the vendor
     * is not a parent, or if the vendor is a parent and the link is not the create new division link (i.e. if the link is "edit").
     * We'll always add the vendor header id in the query string in all links.
     *
     * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getActionUrlHref(org.kuali.rice.kns.bo.BusinessObject, java.lang.String, java.util.List)
     */
    @Override
    protected String getActionUrlHref(BusinessObject businessObject, String methodToCall, List pkNames){
        if (!methodToCall.equals(KFSConstants.COPY_METHOD)) {
            Properties parameters = new Properties();
            parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
            parameters.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, businessObject.getClass().getName());

            for (Iterator<String> iter = pkNames.iterator(); iter.hasNext();) {
{'fraction_non_alphanumeric': 0.0838, 'fraction_numerical': 0.0023, 'mean_word_length': 4.0921588594704685, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7325235', 'n_tokens_mistral': 2972, 'n_tokens_neox': 2920, 'n_words': 796}