001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.module.ar.document.validation.impl;
017
018 import java.util.HashMap;
019 import java.util.Map;
020
021 import org.apache.commons.lang.StringUtils;
022 import org.kuali.kfs.module.ar.ArConstants;
023 import org.kuali.kfs.module.ar.ArKeyConstants;
024 import org.kuali.kfs.module.ar.ArPropertyConstants;
025 import org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail;
026 import org.kuali.kfs.sys.businessobject.UnitOfMeasure;
027 import org.kuali.kfs.sys.context.SpringContext;
028 import org.kuali.kfs.sys.document.validation.GenericValidation;
029 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
030 import org.kuali.rice.kns.service.BusinessObjectService;
031 import org.kuali.rice.kns.util.GlobalVariables;
032 import org.kuali.rice.kns.util.ObjectUtils;
033
034 public class CustomerInvoiceDetailUnitOfMeasureValidation extends GenericValidation {
035
036 private BusinessObjectService businessObjectService;
037 private CustomerInvoiceDetail customerInvoiceDetail;
038
039 public boolean validate(AttributedDocumentEvent event) {
040
041 if (StringUtils.isNotEmpty(customerInvoiceDetail.getInvoiceItemUnitOfMeasureCode())) {
042 Map<String,String> criteria = new HashMap<String,String>();
043 criteria.put("itemUnitOfMeasureCode", customerInvoiceDetail.getInvoiceItemUnitOfMeasureCode());
044 if (ObjectUtils.isNull(SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(UnitOfMeasure.class, criteria))) {
045 GlobalVariables.getMessageMap().putError(ArPropertyConstants.CustomerInvoiceDocumentFields.UNIT_OF_MEASURE_CODE, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DOCUMENT_INVALID_UNIT_OF_MEASURE_CD);
046 return false;
047 }
048 }
049 return true;
050 }
051
052 public BusinessObjectService getBusinessObjectService() {
053 return businessObjectService;
054 }
055
056 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
057 this.businessObjectService = businessObjectService;
058 }
059
060 public CustomerInvoiceDetail getCustomerInvoiceDetail() {
061 return customerInvoiceDetail;
062 }
063
064 public void setCustomerInvoiceDetail(CustomerInvoiceDetail customerInvoiceDetail) {
065 this.customerInvoiceDetail = customerInvoiceDetail;
066 }
067
068 }