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.apache.commons.lang.StringUtils;
19  import org.kuali.ole.module.purap.PurapPropertyConstants;
20  import org.kuali.ole.module.purap.businessobject.PurApItem;
21  import org.kuali.ole.sys.OLEKeyConstants;
22  import org.kuali.ole.sys.document.validation.GenericValidation;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.rice.kns.service.DataDictionaryService;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  public class PurchasingItemDescriptionValidation extends GenericValidation {
28  
29      private PurApItem itemForValidation;
30      private DataDictionaryService dataDictionaryService;
31  
32      /**
33       * Checks that a description was entered for the item.
34       */
35      public boolean validate(AttributedDocumentEvent event) {
36          boolean valid = true;
37          if (StringUtils.isEmpty(itemForValidation.getItemDescription())) {
38              valid = false;
39              String attributeLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(itemForValidation.getClass().getName()).
40                      getAttributeDefinition(PurapPropertyConstants.ITEM_DESCRIPTION).getLabel();
41              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ITEM_DESCRIPTION, OLEKeyConstants.ERROR_REQUIRED, attributeLabel + " in " + itemForValidation.getItemIdentifierString());
42          }
43          return valid;
44      }
45  
46      public PurApItem getItemForValidation() {
47          return itemForValidation;
48      }
49  
50      public void setItemForValidation(PurApItem itemForValidation) {
51          this.itemForValidation = itemForValidation;
52      }
53  
54      public DataDictionaryService getDataDictionaryService() {
55          return dataDictionaryService;
56      }
57  
58      public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
59          this.dataDictionaryService = dataDictionaryService;
60      }
61  
62  }