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.module.purap.document;
20  
21  import java.util.Map;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.kuali.kfs.module.purap.PurapKeyConstants;
25  import org.kuali.kfs.sys.document.FinancialSystemMaintainable;
26  import org.kuali.kfs.vnd.VendorUtils;
27  import org.kuali.rice.kns.document.MaintenanceDocument;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  import org.kuali.rice.krad.util.KRADConstants;
30  
31  /* 
32   * A special implementation of Maintainable specifically for PurchaseOrderQuoteLanguage
33   * maintenance page to override the behavior when the PurchaseOrderQuoteLanguage 
34   * maintenance document is copied.
35  */
36  public class PurchaseOrderQuoteListMaintainableImpl extends FinancialSystemMaintainable {
37      @Override
38      public Map<String, String> populateNewCollectionLines( Map<String, String> fieldValues, MaintenanceDocument maintenanceDocument, String methodToCall ) {
39          String collName = "quoteListVendors.vendorDetail.vendorNumber";
40          String vendorNumber = (String)fieldValues.get(collName);
41          if (StringUtils.isNotBlank(vendorNumber)) {
42              if (!VendorUtils.validVendorNumberFormat(vendorNumber)) {
43                  GlobalVariables.getMessageMap().putError(KRADConstants.MAINTENANCE_ADD_PREFIX + collName , PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_LIST_NON_EXISTENCE_VENDOR);
44                  return fieldValues;
45              }
46              else {
47                  Integer headerId = VendorUtils.getVendorHeaderId(vendorNumber);
48                  Integer detailId = VendorUtils.getVendorDetailId(vendorNumber);
49                  resetPreviousVendorInformationOnAddLine(fieldValues, headerId, detailId);
50              }
51          }
52          
53          return super.populateNewCollectionLines(fieldValues, maintenanceDocument, methodToCall);
54      }
55      
56      private void resetPreviousVendorInformationOnAddLine(Map fieldValues, Integer headerId, Integer detailId) {        
57          if (fieldValues.get("quoteListVendors.vendorHeaderGeneratedIdentifier") != null) {
58              fieldValues.put("quoteListVendors.vendorHeaderGeneratedIdentifier", headerId);
59          }
60          
61          if (fieldValues.get("quoteListVendors.vendorDetailAssignedIdentifier") != null) {
62              fieldValues.put("quoteListVendors.vendorDetailAssignedIdentifier", detailId);
63          }
64          
65      }
66  }