View Javadoc
1   /*
2    * Copyright 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.validation.impl;
17  
18  import org.kuali.ole.module.purap.PurapConstants;
19  import org.kuali.ole.module.purap.PurapConstants.PODocumentsStrings;
20  import org.kuali.ole.module.purap.PurapKeyConstants;
21  import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
22  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
23  import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
24  import org.kuali.ole.sys.document.validation.GenericValidation;
25  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  
28  import java.util.HashMap;
29  import java.util.List;
30  
31  /**
32   * A validation that checks whether the given accounting line is accessible to the given user or not
33   */
34  public class PurchaseOrderSplitValidation extends GenericValidation {
35  
36      private PurchaseOrderService purchaseOrderService;
37      private PurchaseOrderDocument accountingDocumentForValidation;
38  
39      /**
40       * Applies rules for validation of the Split of PO and PO child documents
41       *
42       * @param document A PurchaseOrderDocument (or one of its children)
43       * @return True if all relevant validation rules are passed.
44       */
45      public boolean validate(AttributedDocumentEvent event) {
46          boolean valid = true;
47          PurchaseOrderDocument po = (PurchaseOrderDocument) event.getDocument();
48          HashMap<String, List<PurchaseOrderItem>> categorizedItems = purchaseOrderService.categorizeItemsForSplit((List<PurchaseOrderItem>) po.getItems());
49          List<PurchaseOrderItem> movingPOItems = categorizedItems.get(PODocumentsStrings.ITEMS_MOVING_TO_SPLIT);
50          List<PurchaseOrderItem> remainingPOLineItems = categorizedItems.get(PODocumentsStrings.LINE_ITEMS_REMAINING);
51          if (movingPOItems.isEmpty()) {
52              GlobalVariables.getMessageMap().putError(PurapConstants.SPLIT_PURCHASE_ORDER_TAB_ERRORS, PurapKeyConstants.ERROR_PURCHASE_ORDER_SPLIT_ONE_ITEM_MUST_MOVE);
53              valid &= false;
54          } else if (remainingPOLineItems.isEmpty()) {
55              GlobalVariables.getMessageMap().putError(PurapConstants.SPLIT_PURCHASE_ORDER_TAB_ERRORS, PurapKeyConstants.ERROR_PURCHASE_ORDER_SPLIT_ONE_ITEM_MUST_REMAIN);
56              valid &= false;
57          }
58          return valid;
59      }
60  
61      public PurchaseOrderService getPurchaseOrderService() {
62          return purchaseOrderService;
63      }
64  
65      public void setPurchaseOrderService(PurchaseOrderService purchaseOrderService) {
66          this.purchaseOrderService = purchaseOrderService;
67      }
68  
69      public PurchaseOrderDocument getAccountingDocumentForValidation() {
70          return accountingDocumentForValidation;
71      }
72  
73      public void setAccountingDocumentForValidation(PurchaseOrderDocument accountingDocumentForValidation) {
74          this.accountingDocumentForValidation = accountingDocumentForValidation;
75      }
76  
77  }
78