View Javadoc
1   /*
2    * Copyright 2009 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.PurapConstants;
19  import org.kuali.ole.module.purap.PurapKeyConstants;
20  import org.kuali.ole.module.purap.document.PurchasingDocumentBase;
21  import org.kuali.ole.sys.businessobject.Building;
22  import org.kuali.ole.sys.businessobject.Room;
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.service.BusinessObjectService;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  import org.kuali.rice.krad.util.MessageMap;
28  
29  import java.util.HashMap;
30  import java.util.Map;
31  
32  //MSU Contribution OLEMI-8582 DTT-330 OLECNTRB-943
33  public class PurapRequisitionRoomBuildingInActiveValidation extends GenericValidation {
34  
35      private BusinessObjectService businessObjectService; //
36  
37  
38      public boolean validate(AttributedDocumentEvent event) {
39          boolean isActive = true;
40          PurchasingDocumentBase req = (PurchasingDocumentBase) event.getDocument();
41          MessageMap errorMap = GlobalVariables.getMessageMap();
42  
43          errorMap.clearErrorPath();
44  
45          Map primarykeys = new HashMap();
46          //Pass primary keys campusCode + buildingCode, to retrieve building object.        
47          primarykeys.put("campusCode", req.getDeliveryCampusCode());
48          primarykeys.put("buildingCode", req.getDeliveryBuildingCode());
49  
50          Building building = (Building) businessObjectService.findByPrimaryKey(Building.class, primarykeys);
51  
52          if (building != null) {
53              if (!building.isActive()) {
54                  errorMap.putError(PurapConstants.DELIVERY_BUILDING_NAME_INACTIVE_ERROR, PurapKeyConstants.ERROR_INACTIVE_BUILDING);
55                  isActive &= building.isActive();
56              }
57          }
58  
59          //Pass primary keys campusCode + buildingCode + buildingRoomNumber, to retrieve room object.        
60          primarykeys.put("buildingRoomNumber", req.getDeliveryBuildingRoomNumber());
61          Room room = (Room) businessObjectService.findByPrimaryKey(Room.class, primarykeys);
62  
63          if (room != null) {
64              if (!room.isActive()) {
65                  errorMap.putError(PurapConstants.DELIVERY_ROOM_NUMBER_INACTIVE_ERROR, PurapKeyConstants.ERROR_INACTIVE_ROOM);
66                  isActive &= room.isActive();
67              }
68          }
69          return isActive;
70      }
71  
72      public void setbusinessObjectService(BusinessObjectService businessObjectService) {
73          this.businessObjectService = businessObjectService;
74      }
75  }