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.PurapKeyConstants;
20 import org.kuali.ole.module.purap.businessobject.PurApItem;
21 import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
22 import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
23 import org.kuali.ole.sys.context.SpringContext;
24 import org.kuali.ole.sys.document.validation.GenericValidation;
25 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26 import org.kuali.rice.kew.api.doctype.DocumentTypeService;
27 import org.kuali.rice.krad.util.GlobalVariables;
28
29 import java.util.List;
30
31 public class PurchaseOrderAmendmentContainsAtLeastOneActiveItemValidation extends GenericValidation {
32
33
34
35
36
37
38
39 public boolean validate(AttributedDocumentEvent event) {
40 PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) event.getDocument();
41 List<PurApItem> items = purapDocument.getItems();
42 for (PurApItem item : items) {
43 if (((PurchaseOrderItem) item).isItemActiveIndicator() && (!((PurchaseOrderItem) item).isEmpty() && item.getItemType().isLineItemIndicator())) {
44 return true;
45 }
46 }
47 String documentType = getDocumentTypeLabel(purapDocument.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
48 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_REQUIRED, documentType);
49
50 return false;
51 }
52
53 protected String getDocumentTypeLabel(String documentTypeName) {
54 return SpringContext.getBean(DocumentTypeService.class).getDocumentTypeByName(documentTypeName).getLabel();
55
56 }
57
58 }