1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
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
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 }