View Javadoc

1   /*
2    * Copyright 2010 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.businessobject.PurApItem;
20  import org.kuali.ole.module.purap.document.PaymentRequestDocument;
21  import org.kuali.ole.sys.OLEPropertyConstants;
22  import org.kuali.ole.sys.document.validation.GenericValidation;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.rice.core.api.util.type.KualiDecimal;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  import java.util.List;
28  
29  public class LineItemQuantityNotZero extends GenericValidation {
30  
31      public boolean validate(AttributedDocumentEvent event) {
32          boolean valid = true;
33  
34          PaymentRequestDocument document = (PaymentRequestDocument) event.getDocument();
35          GlobalVariables.getMessageMap().clearErrorPath();
36          GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
37  
38          int i = 0;
39          for (PurApItem item : (List<PurApItem>) document.getItems()) {
40              KualiDecimal itemQuantity = item.getItemQuantity();
41              if (itemQuantity != null) {
42                  if (!itemQuantity.isNonZero()) {
43                      GlobalVariables.getMessageMap().putError("item[" + i + "].itemQuantity", PurapKeyConstants.ERROR_PAYMENT_REQUEST_LINE_ITEM_QUANTITY_ZERO);
44                      GlobalVariables.getMessageMap().clearErrorPath();
45  
46                      valid = false;
47                      break;
48                  }
49                  i++;
50              }
51          }
52  
53          return valid;
54      }
55  
56  }