View Javadoc
1   /*
2    * Copyright 2008-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.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.document.PurchasingDocument;
22  import org.kuali.ole.sys.document.validation.GenericValidation;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.rice.krad.util.GlobalVariables;
25  
26  import java.util.List;
27  
28  public class PurchasingReceivingValidation extends GenericValidation {
29  
30      public boolean validate(AttributedDocumentEvent event) {
31          boolean valid = true;
32  
33          PurchasingDocument purDoc = (PurchasingDocument) event.getDocument();
34  
35          if (!purDoc.isReceivingDocumentRequiredIndicator()) {
36              return true;
37          }
38  
39          GlobalVariables.getMessageMap().clearErrorPath();
40          //GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
41  
42          List<PurApItem> items = purDoc.getItems();
43  
44          boolean containsQtyTypeItem = false;
45          for (PurApItem item : items) {
46              if (item.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
47                  containsQtyTypeItem = true;
48                  break;
49              }
50          }
51  
52          if (!containsQtyTypeItem) {
53              GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_RECEIVING_REQUIRED);
54              valid &= false;
55          }
56  
57          GlobalVariables.getMessageMap().clearErrorPath();
58  
59          return valid;
60      }
61  
62  }