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.coa.businessobject.Organization;
19  import org.kuali.ole.coa.service.OrganizationService;
20  import org.kuali.ole.module.purap.PurapConstants;
21  import org.kuali.ole.module.purap.PurapKeyConstants;
22  import org.kuali.ole.module.purap.document.RequisitionDocument;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  import org.kuali.rice.krad.util.MessageMap;
27  
28  //MSU Contribution OLEMI-8457 DTT-377 OLECNTRB-945
29  
30  public class RequisitionOrganizationValidation extends GenericValidation {
31      private OrganizationService organizationService;
32  
33      public boolean validate(AttributedDocumentEvent event) {
34          boolean valid = true;
35          boolean active;
36          RequisitionDocument purDocument = (RequisitionDocument) event.getDocument();
37          MessageMap errorMap = GlobalVariables.getMessageMap();
38          errorMap.clearErrorPath();
39          Organization org = organizationService.getByPrimaryId(purDocument.getChartOfAccountsCode(), purDocument.getOrganizationCode());
40          if (org != null) {
41              if (!org.isActive()) {
42                  errorMap.putError(PurapConstants.PURAP_REQS_ORG_CD, PurapKeyConstants.ERROR_INACTIVE_ORG);
43                  valid = false;
44              }
45          }
46          return valid;
47      }
48  
49      public void setOrganizationService(OrganizationService orgSer) {
50          this.organizationService = orgSer;
51      }
52  
53  }