View Javadoc
1   /*
2    * Copyright 2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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              // verify unit price is not negative
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  }