View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.vnd.businessobject.lookup;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.Properties;
25  
26  import org.kuali.kfs.sys.KFSConstants;
27  import org.kuali.kfs.vnd.VendorConstants;
28  import org.kuali.kfs.vnd.VendorPropertyConstants;
29  import org.kuali.kfs.vnd.batch.service.VendorExcludeService;
30  import org.kuali.kfs.vnd.businessobject.DebarredVendorMatch;
31  import org.kuali.kfs.vnd.businessobject.VendorDetail;
32  import org.kuali.kfs.vnd.document.service.VendorService;
33  import org.kuali.rice.core.api.config.property.ConfigurationService;
34  import org.kuali.rice.kns.lookup.HtmlData;
35  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
36  import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
37  import org.kuali.rice.krad.bo.BusinessObject;
38  import org.kuali.rice.krad.util.KRADConstants;
39  import org.kuali.rice.krad.util.UrlFactory;
40  
41  public class VendorExclusionLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl{
42      VendorExcludeService vendorExcludeService;
43      VendorService vendorService;
44      ConfigurationService kualiConfigurationService;
45  
46      private String confirmStatusFieldValue="";
47  
48      /**
49       * Custom action urls for Asset.
50       *
51       * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject,
52       *      List pkNames)
53       */
54      @Override
55      public List<HtmlData> getCustomActionUrls(BusinessObject bo, List pkNames) {
56          List<HtmlData> anchorHtmlDataList = super.getCustomActionUrls(bo, pkNames);
57          anchorHtmlDataList.add(getInquiryUrl(bo));
58          anchorHtmlDataList.add(getEditUrl(bo));
59          anchorHtmlDataList.add(getConfirmUrl(bo));
60          anchorHtmlDataList.add(getDenyUrl(bo));
61          return anchorHtmlDataList;
62      }
63  
64      protected String getVendorInquiryUrl(DebarredVendorMatch match) {
65          Properties properties = new Properties();
66          properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD);
67          properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, VendorDetail.class.getName());
68          properties.put("vendorDetailAssignedIdentifier", new Integer(match.getVendorDetailAssignedIdentifier()).toString());
69          properties.put("vendorHeaderGeneratedIdentifier", new Integer(match.getVendorHeaderGeneratedIdentifier()).toString());
70  
71          return UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, properties);
72      }
73  
74      protected HtmlData getInquiryUrl(BusinessObject bo){
75          Properties properties = new Properties();
76          properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD);
77          properties.put("debarredVendorId", new Integer(((DebarredVendorMatch)bo).getDebarredVendorId()).toString());
78          properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, DebarredVendorMatch.class.getName());
79  
80          String href = UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, properties);
81          AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, KRADConstants.START_METHOD, "Inquiry");
82          anchorHtmlData.setTarget(KFSConstants.NEW_WINDOW_URL_TARGET);
83          return anchorHtmlData;
84      }
85  
86      protected HtmlData getEditUrl(BusinessObject bo){
87          String label = "edit";
88          Integer vendorDetailAssignedIdentifier = ((DebarredVendorMatch)bo).getVendorDetailAssignedIdentifier();
89          Integer vendorHeaderGeneratedIdentifier = ((DebarredVendorMatch)bo).getVendorHeaderGeneratedIdentifier();
90          VendorDetail vendor = vendorService.getVendorDetail(vendorHeaderGeneratedIdentifier, vendorDetailAssignedIdentifier);
91          VendorDetail parent;
92          if (!vendor.isVendorParentIndicator()) {
93              label = "edit parent";
94              parent = vendorService.getParentVendor(vendorHeaderGeneratedIdentifier);
95              vendorDetailAssignedIdentifier = parent.getVendorDetailAssignedIdentifier();
96              vendorHeaderGeneratedIdentifier = parent.getVendorHeaderGeneratedIdentifier();
97          }
98  
99          Properties properties = new Properties();
100         properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL);
101         properties.put(VendorPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorHeaderGeneratedIdentifier.toString());
102         properties.put(VendorPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, vendorDetailAssignedIdentifier.toString());
103         properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, VendorDetail.class.getName());
104         String href = UrlFactory.parameterizeUrl(KRADConstants.MAINTENANCE_ACTION, properties);
105         AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, label);
106         anchorHtmlData.setTarget(KFSConstants.NEW_WINDOW_URL_TARGET);
107         return anchorHtmlData;
108     }
109 
110     protected HtmlData getConfirmUrl(BusinessObject bo){
111         Properties properties = new Properties();
112         properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "confirmDebarredVendor");
113         properties.put(DebarredVendorMatch.CONFIRM_STATUS, confirmStatusFieldValue);
114         properties.put(DebarredVendorMatch.DEBARRED_VENDOR_ID, String.valueOf(((DebarredVendorMatch)bo).getDebarredVendorId()));
115         properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, DebarredVendorMatch.class.getName());
116         properties.put("returnLocation", kualiConfigurationService.getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY)+ "/kr/lookup.do");
117         properties.put(DebarredVendorMatch.EXCLUSION_STATUS, ((DebarredVendorMatch)bo).getVendorExclusionStatus());
118 
119         String href = UrlFactory.parameterizeUrl("vendorExclusion.do", properties);
120         href = kualiConfigurationService.getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY)+"/"+ href;
121         AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, KRADConstants.START_METHOD, "confirm");
122         return anchorHtmlData;
123     }
124 
125     protected HtmlData getDenyUrl(BusinessObject bo){
126         Properties properties = new Properties();
127         properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "denyDebarredVendor");
128         properties.put(DebarredVendorMatch.CONFIRM_STATUS, confirmStatusFieldValue);
129         properties.put(DebarredVendorMatch.DEBARRED_VENDOR_ID, String.valueOf(((DebarredVendorMatch)bo).getDebarredVendorId()));
130         properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, DebarredVendorMatch.class.getName());
131         properties.put("returnLocation", kualiConfigurationService.getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY)+ "/kr/lookup.do");
132         properties.put("formKey", "88888888");
133 
134         String href = UrlFactory.parameterizeUrl("vendorExclusion.do", properties);
135         href = kualiConfigurationService.getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY)+"/"+ href;
136         AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, KRADConstants.START_METHOD, "deny");
137         return anchorHtmlData;
138     }
139 
140     @Override
141     public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
142         return getDebarredVendorSearchResults(fieldValues);
143     }
144 
145     @Override
146     public List<? extends BusinessObject> getSearchResultsUnbounded(Map<String, String> fieldValues) {
147         return getDebarredVendorSearchResults(fieldValues);
148     }
149 
150     protected List<? extends BusinessObject> getDebarredVendorSearchResults(Map<String, String> fieldValues) {
151         List<DebarredVendorMatch> vendorResultList = new ArrayList<DebarredVendorMatch>();
152         String exclusionStatus = fieldValues.get(DebarredVendorMatch.EXCLUSION_STATUS);
153         confirmStatusFieldValue = fieldValues.get(DebarredVendorMatch.CONFIRM_STATUS);
154         fieldValues.remove(DebarredVendorMatch.EXCLUSION_STATUS);
155         List<DebarredVendorMatch> searchResults = (List<DebarredVendorMatch>) super.getSearchResults(fieldValues);
156         boolean status = exclusionStatus.equals(VendorConstants.EXCLUDED_MATCHED_VENDOR_STATUS) ? true : false;
157         boolean debarred;
158         for (DebarredVendorMatch match : searchResults) {
159             debarred = match.getVendorHeader().getVendorDebarredIndicator() == null ? false : match.getVendorHeader().getVendorDebarredIndicator();
160             if ((status && debarred) || (!status && !debarred)) {
161                 match.setConcatenatedId("<a href=\"" + getVendorInquiryUrl(match) + "\">" + match.getVendorDetail().getVendorNumber() + "</a> / " +
162                         "<a href=\"http://www.epls.gov/epls/search.do?ssn=true&ssn_name=" + match.getName() + "&ssn_tin=" +
163                         match.getVendorHeader().getVendorTaxNumber() + "\">" + match.getDebarredVendorId() + "</a>");
164                 match.setName(match.getVendorDetail().getVendorName() + " / " + match.getName());
165                 match.setCity(match.getVendorAddress().getVendorCityName() + " / " + match.getCity());
166                 match.setState(match.getVendorAddress().getVendorStateCode() == null ? match.getVendorAddress().getVendorCountryCode() : match.getVendorAddress().getVendorStateCode() + " / " + match.getState());
167                 match.setVendorExclusionStatus(exclusionStatus);
168                 vendorResultList.add(match);
169             }
170         }
171         return vendorResultList;
172     }
173 
174     /**
175      * Gets the vendorExcludeService attribute.
176      * @return Returns the vendorExcludeService.
177      */
178     public VendorExcludeService getVendorExcludeService() {
179         return vendorExcludeService;
180     }
181 
182     /**
183      * Sets the vendorExcludeService attribute value.
184      * @param vendorExcludeService The vendorExcludeService to set.
185      */
186     public void setVendorExcludeService(VendorExcludeService vendorExcludeService) {
187         this.vendorExcludeService = vendorExcludeService;
188     }
189 
190     /**
191      * Gets the vendorService attribute.
192      * @return Returns the vendorService.
193      */
194     public VendorService getVendorService() {
195         return vendorService;
196     }
197 
198     /**
199      * Sets the vendorService attribute value.
200      * @param vendorService The vendorService to set.
201      */
202     public void setVendorService(VendorService vendorService) {
203         this.vendorService = vendorService;
204     }
205 
206     /**
207      * Gets the kualiConfigurationService attribute.
208      * @return Returns the kualiConfigurationService.
209      */
210     @Override
211     public ConfigurationService getKualiConfigurationService() {
212         return kualiConfigurationService;
213     }
214 
215     /**
216      * Sets the kualiConfigurationService attribute value.
217      * @param kualiConfigurationService The kualiConfigurationService to set.
218      */
219     public void setKualiConfigurationService(ConfigurationService kualiConfigurationService) {
220         this.kualiConfigurationService = kualiConfigurationService;
221     }
222 }