1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
33
34 public class PurchaseOrderSplitValidation extends GenericValidation {
35
36 private PurchaseOrderService purchaseOrderService;
37 private PurchaseOrderDocument accountingDocumentForValidation;
38
39
40
41
42
43
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