1 package org.kuali.ole.deliver.util;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.deliver.bo.OlePatronDocument;
6 import org.kuali.ole.deliver.controller.checkout.CircUtilController;
7 import org.kuali.ole.deliver.drools.DroolsEngineLogger;
8 import org.kuali.rice.core.api.config.property.ConfigContext;
9 import org.kuali.rice.kim.api.permission.PermissionService;
10 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
11 import org.kuali.rice.krad.service.BusinessObjectService;
12 import org.kuali.rice.krad.service.KRADServiceLocator;
13 import org.kuali.rice.krad.util.GlobalVariables;
14
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19
20
21
22
23 public class OlePatronRecordUtil extends CircUtilController {
24 private static final Logger LOG = Logger.getLogger(OlePatronRecordUtil.class);
25 private BusinessObjectService businessObjectService;
26
27 public OlePatronDocument getPatronRecordByBarcode(String barcode) throws Exception {
28 LOG.debug("Inside the getPatronBarcodeRecord method");
29 StringBuffer values_StringBuffer = new StringBuffer();
30
31 try {
32 Map barMap = new HashMap();
33 barMap.put(OLEConstants.OlePatron.BARCODE, barcode);
34 List<OlePatronDocument> matching = (List<OlePatronDocument>) getBusinessObjectService().findMatching(OlePatronDocument.class, barMap);
35
36 if (matching != null && matching.size() > 0) {
37 OlePatronDocument olePatronDocument = matching.get(0);
38 if (GlobalVariables.getUserSession() != null) {
39 olePatronDocument.setPatronRecordURL(patronNameURL(GlobalVariables.getUserSession().getPrincipalId(), olePatronDocument.getOlePatronId()));
40 }
41 return olePatronDocument;
42 } else {
43 LOG.error(OLEConstants.PTRN_BARCD_NOT_EXT);
44 throw new Exception(OLEConstants.PTRN_BARCD_NOT_EXT);
45 }
46 } catch (Exception e) {
47 LOG.error(OLEConstants.PTRN_BARCD_NOT_EXT + e, e);
48 values_StringBuffer.append(OLEConstants.PTRN_BARCD_NOT_EXT + " " + OLEConstants.PTRN_START_LINK + ConfigContext.getCurrentContextConfig().getProperty("ole.fs.url.base") + OLEConstants.PTRN_END_LINK);
49 throw new Exception(values_StringBuffer.toString());
50 }
51
52 }
53
54 public String patronNameURL(String loginUser, String patronId) {
55 boolean canEdit = canEdit(loginUser);
56 String patronNameURL = "";
57 if (canEdit) {
58 patronNameURL = OLEConstants.ASSIGN_EDIT_PATRON_ID + patronId + OLEConstants.ASSIGN_PATRON_MAINTENANCE_EDIT;
59 } else {
60 patronNameURL = OLEConstants.ASSIGN_INQUIRY_PATRON_ID + patronId + OLEConstants.ASSIGN_PATRON_INQUIRY;
61 }
62 return patronNameURL;
63 }
64
65 public boolean canEdit(String principalId) {
66 PermissionService service = KimApiServiceLocator.getPermissionService();
67 return service.hasPermission(principalId, OLEConstants.OlePatron.PATRON_NAMESPACE, OLEConstants.EDIT_PATRON);
68 }
69
70 public DroolsResponse fireRules(OlePatronDocument olePatronDocument, String[] expectedRules) {
71 List facts = new ArrayList();
72 facts.add(olePatronDocument);
73 DroolsResponse droolsResponse = new DroolsResponse();
74 facts.add(droolsResponse);
75
76 fireRules(facts, expectedRules, "general-checks");
77
78 return droolsResponse;
79 }
80
81
82 public BusinessObjectService getBusinessObjectService() {
83 if (null == businessObjectService) {
84 businessObjectService = KRADServiceLocator.getBusinessObjectService();
85 }
86 return businessObjectService;
87 }
88
89 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
90 this.businessObjectService = businessObjectService;
91 }
92
93
94 }