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.PurApItem;
21  import org.kuali.ole.module.purap.businessobject.PurchasingItemBase;
22  import org.kuali.ole.sys.OLEKeyConstants;
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  import org.kuali.rice.krad.util.ObjectUtils;
28  
29  public class PurchasingItemQuantityValidation extends GenericValidation {
30  
31      private PurApItem itemForValidation;
32      private DataDictionaryService dataDictionaryService;
33  
34      /**
35       * Validates that if the item type is quantity based, the item quantity is required and if the item type is amount based, the
36       * quantity is not allowed.
37       */
38      public boolean validate(AttributedDocumentEvent event) {
39          boolean valid = true;
40          PurchasingItemBase purItem = (PurchasingItemBase) itemForValidation;
41          if (purItem.getItemType().isQuantityBasedGeneralLedgerIndicator() && (ObjectUtils.isNull(purItem.getItemQuantity()))) {
42              valid = false;
43              String attributeLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(purItem.getClass().getName()).
44                      getAttributeDefinition(PurapPropertyConstants.ITEM_QUANTITY).getLabel();
45              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.QUANTITY, OLEKeyConstants.ERROR_REQUIRED, attributeLabel + " in " + purItem.getItemIdentifierString());
46          } else if (purItem.getItemType().isAmountBasedGeneralLedgerIndicator() && ObjectUtils.isNotNull(purItem.getItemQuantity())) {
47              valid = false;
48              String attributeLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(purItem.getClass().getName()).
49                      getAttributeDefinition(PurapPropertyConstants.ITEM_QUANTITY).getLabel();
50              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.QUANTITY, PurapKeyConstants.ERROR_ITEM_QUANTITY_NOT_ALLOWED, attributeLabel + " in " + purItem.getItemIdentifierString());
51          }
52  
53          return valid;
54      }
55  
56      public PurApItem getItemForValidation() {
57          return itemForValidation;
58      }
59  
60      public void setItemForValidation(PurApItem itemForValidation) {
61          this.itemForValidation = itemForValidation;
62      }
63  
64      public DataDictionaryService getDataDictionaryService() {
65          return dataDictionaryService;
66      }
67  
68      public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
69          this.dataDictionaryService = dataDictionaryService;
70      }
71  
72  }