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.PurapKeyConstants;
19 import org.kuali.ole.module.purap.PurapPropertyConstants;
20 import org.kuali.ole.module.purap.businessobject.CreditMemoItem;
21 import org.kuali.ole.select.document.OleVendorCreditMemoDocument;
22 import org.kuali.ole.sys.OLEPropertyConstants;
23 import org.kuali.ole.sys.document.validation.GenericValidation;
24 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25 import org.kuali.rice.kns.service.DataDictionaryService;
26 import org.kuali.rice.krad.util.GlobalVariables;
27
28 public class VendorCreditMemoItemUnitPriceValidation extends GenericValidation {
29
30 private DataDictionaryService dataDictionaryService;
31 private CreditMemoItem itemForValidation;
32
33 public boolean validate(AttributedDocumentEvent event) {
34 boolean valid = true;
35 String errorKeyPrefix = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "[" + (itemForValidation.getItemLineNumber() - 1) + "].";
36 String errorKey = errorKeyPrefix + PurapPropertyConstants.ITEM_UNIT_PRICE;
37 OleVendorCreditMemoDocument cmDocument = (OleVendorCreditMemoDocument) event.getDocument();
38 if (itemForValidation.getItemUnitPrice() != null) {
39
40 if (itemForValidation.getItemUnitPrice().signum() == -1 && cmDocument.getInvoiceIdentifier() == null) {
41 String label = dataDictionaryService.getAttributeErrorLabel(CreditMemoItem.class, PurapPropertyConstants.ITEM_UNIT_PRICE);
42 GlobalVariables.getMessageMap().putError(errorKey, PurapKeyConstants.ERROR_CREDIT_MEMO_ITEM_AMOUNT_NONPOSITIVE, label);
43 valid = false;
44 }
45 }
46
47 return valid;
48 }
49
50 public DataDictionaryService getDataDictionaryService() {
51 return dataDictionaryService;
52 }
53
54 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
55 this.dataDictionaryService = dataDictionaryService;
56 }
57
58 public CreditMemoItem getItemForValidation() {
59 return itemForValidation;
60 }
61
62 public void setItemForValidation(CreditMemoItem itemForValidation) {
63 this.itemForValidation = itemForValidation;
64 }
65
66 }