View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.vnd.businessobject.lookup;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.Properties;
22  
23  import org.kuali.ole.sys.OLEConstants;
24  import org.kuali.ole.vnd.VendorConstants;
25  import org.kuali.ole.vnd.VendorPropertyConstants;
26  import org.kuali.ole.vnd.batch.service.VendorExcludeService;
27  import org.kuali.ole.vnd.businessobject.DebarredVendorMatch;
28  import org.kuali.ole.vnd.businessobject.VendorDetail;
29  import org.kuali.ole.vnd.document.service.VendorService;
30  import org.kuali.rice.core.api.config.property.ConfigurationService;
31  import org.kuali.rice.kns.lookup.HtmlData;
32  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
33  import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
34  import org.kuali.rice.krad.bo.BusinessObject;
35  import org.kuali.rice.krad.util.KRADConstants;
36  import org.kuali.rice.krad.util.UrlFactory;
37  
38  public class VendorExclusionLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl{
39      VendorExcludeService vendorExcludeService;
40      VendorService vendorService;
41      ConfigurationService kualiConfigurationService;
42  
43      private String confirmStatusFieldValue="";
44  
45      /**
46       * Custom action urls for Asset.
47       *
48       * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject,
49       *      List pkNames)
50       */
51      @Override
52      public List<HtmlData> getCustomActionUrls(BusinessObject bo, List pkNames) {
53          List<HtmlData> anchorHtmlDataList = super.getCustomActionUrls(bo, pkNames);
54          anchorHtmlDataList.add(getInquiryUrl(bo));
55          anchorHtmlDataList.add(getEditUrl(bo));
56          anchorHtmlDataList.add(getConfirmUrl(bo));
57          anchorHtmlDataList.add(getDenyUrl(bo));
58          return anchorHtmlDataList;
59      }
60  
61      protected String getVendorInquiryUrl(DebarredVendorMatch match) {
62          Properties properties = new Properties();
63          properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD);
64          properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, VendorDetail.class.getName());
65          properties.put("vendorDetailAssignedIdentifier", new Integer(match.getVendorDetailAssignedIdentifier()).toString());
66          properties.put("vendorHeaderGeneratedIdentifier", new Integer(match.getVendorHeaderGeneratedIdentifier()).toString());
67  
68          return UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, properties);
69      }
70  
71      protected HtmlData getInquiryUrl(BusinessObject bo){
72          Properties properties = new Properties();
73          properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD);
74          properties.put("debarredVendorId", new Integer(((DebarredVendorMatch)bo).getDebarredVendorId()).toString());
75          properties.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, DebarredVendorMatch.class.getName());
76  
77          String href = UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, properties);
78          AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, KRADConstants.START_METHOD, "Inquiry");
79          anchorHtmlData.setTarget(OLEConstants.NEW_WINDOW_URL_TARGET);
80          return anchorHtmlData;
81      }
82  
83      protected HtmlData getEditUrl(BusinessObject bo){
84          String label = "edit";
85          Integer vendorDetailAssignedIdentifier = ((DebarredVendorMatch)bo).getVendorDetailAssignedIdentifier();
86          Integer vendorHeaderGeneratedIdentifier = ((DebarredVendorMatch)bo).getVendorHeaderGeneratedIdentifier();
87          VendorDetail vendor = vendorService.getVendorDetail(vendorHeaderGeneratedIdentifier, vendorDetailAssignedIdentifier);
88          VendorDetail parent;
89          if (!vendor.isVendorParentIndicator()) {
90              label = "edit parent";
91              parent = vendorService.getParentVendor(vendorHeaderGeneratedIdentifier);
92              vendorDetailAssignedIdentifier = parent.getVendorDetailAssignedIdentifier();
93              vendorHeaderGeneratedIdentifier = parent.getVendorHeaderGeneratedIdentifier();
94          }
95  
96          Properties properties = new Properties();
97          properties.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL);
98          properties.put(VendorPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorHeaderGeneratedIdentifier.toString());
99          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 }