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