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.PurchasingItemBase;
22 import org.kuali.ole.module.purap.document.PurchasingDocument;
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 public class PurchasingProcessContainsAtLeastOneItemValidation extends GenericValidation {
30
31
32
33
34
35
36
37 public boolean validate(AttributedDocumentEvent event) {
38 boolean valid = false;
39 PurchasingDocument purDocument = (PurchasingDocument) event.getDocument();
40 for (PurApItem item : purDocument.getItems()) {
41 if (!((PurchasingItemBase) item).isEmpty() && item.getItemType().isLineItemIndicator()) {
42
43 return true;
44 }
45 }
46 String documentType = getDocumentTypeLabel(purDocument.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
47
48 if (!valid) {
49 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_REQUIRED, documentType);
50 }
51
52 return valid;
53 }
54
55 protected String getDocumentTypeLabel(String documentTypeName) {
56 return SpringContext.getBean(DocumentTypeService.class).getDocumentTypeByName(documentTypeName).getLabel();
57 }
58
59 }