001/* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 1.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/ecl1.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.vnd.businessobject.lookup; 017 018import java.util.ArrayList; 019import java.util.List; 020import java.util.Map; 021import java.util.Properties; 022 023import org.kuali.ole.sys.OLEConstants; 024import org.kuali.ole.vnd.VendorConstants; 025import org.kuali.ole.vnd.VendorPropertyConstants; 026import org.kuali.ole.vnd.batch.service.VendorExcludeService; 027import org.kuali.ole.vnd.businessobject.DebarredVendorMatch; 028import org.kuali.ole.vnd.businessobject.VendorDetail; 029import org.kuali.ole.vnd.document.service.VendorService; 030import org.kuali.rice.core.api.config.property.ConfigurationService; 031import org.kuali.rice.kns.lookup.HtmlData; 032import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; 033import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; 034import org.kuali.rice.krad.bo.BusinessObject; 035import org.kuali.rice.krad.util.KRADConstants; 036import org.kuali.rice.krad.util.UrlFactory; 037 038public class VendorExclusionLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl{ 039 VendorExcludeService vendorExcludeService; 040 VendorService vendorService; 041 ConfigurationService kualiConfigurationService; 042 043 private String confirmStatusFieldValue=""; 044 045 /** 046 * Custom action urls for Asset. 047 * 048 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject, 049 * List pkNames) 050 */ 051 @Override 052 public List<HtmlData> getCustomActionUrls(BusinessObject bo, List pkNames) { 053 List<HtmlData> anchorHtmlDataList = super.getCustomActionUrls(bo, pkNames); 054 anchorHtmlDataList.add(getInquiryUrl(bo)); 055 anchorHtmlDataList.add(getEditUrl(bo)); 056 anchorHtmlDataList.add(getConfirmUrl(bo)); 057 anchorHtmlDataList.add(getDenyUrl(bo)); 058 return anchorHtmlDataList; 059 } 060 061 protected String getVendorInquiryUrl(DebarredVendorMatch match) { 062 Properties properties = new Properties(); 063 properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD); 064 properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, VendorDetail.class.getName()); 065 properties.put("vendorDetailAssignedIdentifier", new Integer(match.getVendorDetailAssignedIdentifier()).toString()); 066 properties.put("vendorHeaderGeneratedIdentifier", new Integer(match.getVendorHeaderGeneratedIdentifier()).toString()); 067 068 return UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, properties); 069 } 070 071 protected HtmlData getInquiryUrl(BusinessObject bo){ 072 Properties properties = new Properties(); 073 properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD); 074 properties.put("debarredVendorId", new Integer(((DebarredVendorMatch)bo).getDebarredVendorId()).toString()); 075 properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, DebarredVendorMatch.class.getName()); 076 077 String href = UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, properties); 078 AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, KRADConstants.START_METHOD, "Inquiry"); 079 anchorHtmlData.setTarget(OLEConstants.NEW_WINDOW_URL_TARGET); 080 return anchorHtmlData; 081 } 082 083 protected HtmlData getEditUrl(BusinessObject bo){ 084 String label = "edit"; 085 Integer vendorDetailAssignedIdentifier = ((DebarredVendorMatch)bo).getVendorDetailAssignedIdentifier(); 086 Integer vendorHeaderGeneratedIdentifier = ((DebarredVendorMatch)bo).getVendorHeaderGeneratedIdentifier(); 087 VendorDetail vendor = vendorService.getVendorDetail(vendorHeaderGeneratedIdentifier, vendorDetailAssignedIdentifier); 088 VendorDetail parent; 089 if (!vendor.isVendorParentIndicator()) { 090 label = "edit parent"; 091 parent = vendorService.getParentVendor(vendorHeaderGeneratedIdentifier); 092 vendorDetailAssignedIdentifier = parent.getVendorDetailAssignedIdentifier(); 093 vendorHeaderGeneratedIdentifier = parent.getVendorHeaderGeneratedIdentifier(); 094 } 095 096 Properties properties = new Properties(); 097 properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL); 098 properties.put(VendorPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorHeaderGeneratedIdentifier.toString()); 099 properties.put(VendorPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, vendorDetailAssignedIdentifier.toString()); 100 properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, VendorDetail.class.getName()); 101 String href = UrlFactory.parameterizeUrl(KRADConstants.MAINTENANCE_ACTION, properties); 102 AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, label); 103 anchorHtmlData.setTarget(OLEConstants.NEW_WINDOW_URL_TARGET); 104 return anchorHtmlData; 105 } 106 107 protected HtmlData getConfirmUrl(BusinessObject bo){ 108 Properties properties = new Properties(); 109 properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "confirmDebarredVendor"); 110 properties.put(DebarredVendorMatch.CONFIRM_STATUS, confirmStatusFieldValue); 111 properties.put(DebarredVendorMatch.DEBARRED_VENDOR_ID, String.valueOf(((DebarredVendorMatch)bo).getDebarredVendorId())); 112 properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, DebarredVendorMatch.class.getName()); 113 properties.put("returnLocation", kualiConfigurationService.getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY)+ "/kr/lookup.do"); 114 properties.put(DebarredVendorMatch.EXCLUSION_STATUS, ((DebarredVendorMatch)bo).getVendorExclusionStatus()); 115 116 String href = UrlFactory.parameterizeUrl("vendorExclusion.do", properties); 117 href = kualiConfigurationService.getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY)+"/"+ href; 118 AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, KRADConstants.START_METHOD, "confirm"); 119 return anchorHtmlData; 120 } 121 122 protected HtmlData getDenyUrl(BusinessObject bo){ 123 Properties properties = new Properties(); 124 properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "denyDebarredVendor"); 125 properties.put(DebarredVendorMatch.CONFIRM_STATUS, confirmStatusFieldValue); 126 properties.put(DebarredVendorMatch.DEBARRED_VENDOR_ID, String.valueOf(((DebarredVendorMatch)bo).getDebarredVendorId())); 127 properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, DebarredVendorMatch.class.getName()); 128 properties.put("returnLocation", kualiConfigurationService.getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY)+ "/kr/lookup.do"); 129 properties.put("formKey", "88888888"); 130 131 String href = UrlFactory.parameterizeUrl("vendorExclusion.do", properties); 132 href = kualiConfigurationService.getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY)+"/"+ href; 133 AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, KRADConstants.START_METHOD, "deny"); 134 return anchorHtmlData; 135 } 136 137 @Override 138 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) { 139 return getDebarredVendorSearchResults(fieldValues); 140 } 141 142 @Override 143 public List<? extends BusinessObject> getSearchResultsUnbounded(Map<String, String> fieldValues) { 144 return getDebarredVendorSearchResults(fieldValues); 145 } 146 147 protected List<? extends BusinessObject> getDebarredVendorSearchResults(Map<String, String> fieldValues) { 148 List<DebarredVendorMatch> vendorResultList = new ArrayList<DebarredVendorMatch>(); 149 String exclusionStatus = fieldValues.get(DebarredVendorMatch.EXCLUSION_STATUS); 150 confirmStatusFieldValue = fieldValues.get(DebarredVendorMatch.CONFIRM_STATUS); 151 fieldValues.remove(DebarredVendorMatch.EXCLUSION_STATUS); 152 List<DebarredVendorMatch> searchResults = (List<DebarredVendorMatch>) super.getSearchResults(fieldValues); 153 boolean status = exclusionStatus.equals(VendorConstants.EXCLUDED_MATCHED_VENDOR_STATUS) ? true : false; 154 boolean debarred; 155 for (DebarredVendorMatch match : searchResults) { 156 debarred = match.getVendorHeader().getVendorDebarredIndicator() == null ? false : match.getVendorHeader().getVendorDebarredIndicator(); 157 if ((status && debarred) || (!status && !debarred)) { 158 match.setConcatenatedId("<a href=\"" + getVendorInquiryUrl(match) + "\">" + match.getVendorDetail().getVendorNumber() + "</a> / " + 159 "<a href=\"http://www.epls.gov/epls/search.do?ssn=true&ssn_name=" + match.getName() + "&ssn_tin=" + 160 match.getVendorHeader().getVendorTaxNumber() + "\">" + match.getDebarredVendorId() + "</a>"); 161 match.setName(match.getVendorDetail().getVendorName() + " / " + match.getName()); 162 match.setCity(match.getVendorAddress().getVendorCityName() + " / " + match.getCity()); 163 match.setState(match.getVendorAddress().getVendorStateCode() == null ? match.getVendorAddress().getVendorCountryCode() : match.getVendorAddress().getVendorStateCode() + " / " + match.getState()); 164 match.setVendorExclusionStatus(exclusionStatus); 165 vendorResultList.add(match); 166 } 167 } 168 return vendorResultList; 169 } 170 171 /** 172 * Gets the vendorExcludeService attribute. 173 * @return Returns the vendorExcludeService. 174 */ 175 public VendorExcludeService getVendorExcludeService() { 176 return vendorExcludeService; 177 } 178 179 /** 180 * Sets the vendorExcludeService attribute value. 181 * @param vendorExcludeService The vendorExcludeService to set. 182 */ 183 public void setVendorExcludeService(VendorExcludeService vendorExcludeService) { 184 this.vendorExcludeService = vendorExcludeService; 185 } 186 187 /** 188 * Gets the vendorService attribute. 189 * @return Returns the vendorService. 190 */ 191 public VendorService getVendorService() { 192 return vendorService; 193 } 194 195 /** 196 * Sets the vendorService attribute value. 197 * @param vendorService The vendorService to set. 198 */ 199 public void setVendorService(VendorService vendorService) { 200 this.vendorService = vendorService; 201 } 202 203 /** 204 * Gets the kualiConfigurationService attribute. 205 * @return Returns the kualiConfigurationService. 206 */ 207 @Override 208 public ConfigurationService getKualiConfigurationService() { 209 return kualiConfigurationService; 210 } 211 212 /** 213 * Sets the kualiConfigurationService attribute value. 214 * @param kualiConfigurationService The kualiConfigurationService to set. 215 */ 216 public void setKualiConfigurationService(ConfigurationService kualiConfigurationService) { 217 this.kualiConfigurationService = kualiConfigurationService; 218 } 219}