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.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapConstants;
20 import org.kuali.ole.module.purap.PurapKeyConstants;
21 import org.kuali.ole.module.purap.PurapPropertyConstants;
22 import org.kuali.ole.module.purap.document.BulkReceivingDocument;
23 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
24 import org.kuali.ole.module.purap.document.service.BulkReceivingService;
25 import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
26 import org.kuali.ole.sys.OLEPropertyConstants;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.ole.sys.document.validation.GenericValidation;
29 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
30 import org.kuali.rice.krad.util.GlobalVariables;
31 import org.kuali.rice.krad.util.ObjectUtils;
32
33 public class BulkReceivingPurchaseOrderIdValidation extends GenericValidation {
34
35 private PurchaseOrderService purchaseOrderService;
36
37 public boolean validate(AttributedDocumentEvent event) {
38
39 boolean valid = true;
40
41 BulkReceivingDocument bulkReceivingDocument = (BulkReceivingDocument) event.getDocument();
42
43 GlobalVariables.getMessageMap().clearErrorPath();
44 GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
45
46 return canCreateBulkReceivingDocument(bulkReceivingDocument);
47
48 }
49
50
51
52
53
54
55
56 protected boolean canCreateBulkReceivingDocument(BulkReceivingDocument bulkReceivingDocument) {
57
58 boolean valid = true;
59
60 if (bulkReceivingDocument.getPurchaseOrderIdentifier() != null) {
61 PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(bulkReceivingDocument.getPurchaseOrderIdentifier());
62
63 if (ObjectUtils.isNull(po)) {
64 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, PurapKeyConstants.ERROR_BULK_RECEIVING_DOCUMENT_INVALID_PO, bulkReceivingDocument.getDocumentNumber(), bulkReceivingDocument.getPurchaseOrderIdentifier().toString());
65 valid = false;
66 } else {
67 if (!(po.getApplicationDocumentStatus().equals(PurapConstants.PurchaseOrderStatuses.APPDOC_OPEN) ||
68 po.getApplicationDocumentStatus().equals(PurapConstants.PurchaseOrderStatuses.APPDOC_CLOSED))) {
69 valid &= false;
70 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, PurapKeyConstants.ERROR_BULK_RECEIVING_PO_NOT_OPEN, bulkReceivingDocument.getDocumentNumber(), bulkReceivingDocument.getPurchaseOrderIdentifier().toString());
71 } else {
72 String docNumberInProcess = SpringContext.getBean(BulkReceivingService.class).getBulkReceivingDocumentNumberInProcessForPurchaseOrder(po.getPurapDocumentIdentifier(), bulkReceivingDocument.getDocumentNumber());
73 if (StringUtils.isNotEmpty(docNumberInProcess)) {
74 valid &= false;
75 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, PurapKeyConstants.ERROR_BULK_RECEIVING_DOCUMENT_ACTIVE_FOR_PO, docNumberInProcess, bulkReceivingDocument.getPurchaseOrderIdentifier().toString());
76 }
77 }
78 }
79 }
80
81 return valid;
82 }
83
84 public PurchaseOrderService getPurchaseOrderService() {
85 return purchaseOrderService;
86 }
87
88 public void setPurchaseOrderService(PurchaseOrderService purchaseOrderService) {
89 this.purchaseOrderService = purchaseOrderService;
90 }
91
92 }