View Javadoc
1   /*
2    * Copyright 2011 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.select.document.validation.impl;
17  
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.ole.module.purap.PurapPropertyConstants;
21  import org.kuali.ole.select.businessobject.OleRequisitionItem;
22  import org.kuali.ole.sys.OLEConstants;
23  import org.kuali.ole.sys.OLEKeyConstants;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.kns.service.DataDictionaryService;
26  import org.kuali.rice.krad.service.BusinessObjectService;
27  import org.kuali.rice.krad.util.GlobalVariables;
28  
29  public class PurchasingAddBibInfoValidation extends PurchasingBibInfoAddItemValidation {
30  
31      private BusinessObjectService businessObjectService;
32      private DataDictionaryService dataDictionaryService;
33  
34      public boolean validate(AttributedDocumentEvent event) {
35          boolean valid = true;
36          GlobalVariables.getMessageMap().addToErrorPath(PurapPropertyConstants.NEW_PURCHASING_ITEM_LINE);
37          OleRequisitionItem refreshedItem = getItemForValidation();
38          refreshedItem.refreshReferenceObject("itemType");
39          super.setItemForValidation(refreshedItem);
40  
41          valid &= super.validate(event);
42          //valid &= validateItemTitle(getItemForValidation());
43  
44          GlobalVariables.getMessageMap().removeFromErrorPath(PurapPropertyConstants.NEW_PURCHASING_ITEM_LINE);
45  
46          return valid;
47      }
48  
49      public boolean validateItemTitle(OleRequisitionItem item) {
50          boolean valid = true;
51          if (StringUtils.isEmpty(item.getBibInfoBean().getTitle())) {
52              valid = false;
53              String attributeLabel = dataDictionaryService.
54                      getDataDictionary().getBusinessObjectEntry(item.getBibInfoBean().getClass().getName()).
55                      getAttributeDefinition(OLEConstants.BibInfoBean.ITEM_TITLE).getLabel();
56              GlobalVariables.getMessageMap().putError(OLEConstants.BibInfoBean.ITEM_TITLE, OLEKeyConstants.ERROR_REQUIRED, attributeLabel + " in " + item.getItemIdentifierString());
57          }
58          return valid;
59      }
60  
61      public BusinessObjectService getBusinessObjectService() {
62          return businessObjectService;
63      }
64  
65      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
66          this.businessObjectService = businessObjectService;
67      }
68  
69      public DataDictionaryService getDataDictionaryService() {
70          return dataDictionaryService;
71      }
72  
73      public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
74          this.dataDictionaryService = dataDictionaryService;
75      }
76  
77  }
78