1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actionlist;
17
18 import org.kuali.rice.kew.service.KEWServiceLocator;
19 import org.kuali.rice.kim.api.identity.Person;
20 import org.kuali.rice.kim.api.identity.principal.Principal;
21 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServlet;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27 import java.io.IOException;
28 import java.io.PrintWriter;
29
30
31
32 public class ActionListCountServlet extends HttpServlet {
33
34 private static final long serialVersionUID = 260649920715567145L;
35
36 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionListCountServlet.class);
37
38 @Override
39 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
40 response.setContentType("text/plain");
41 PrintWriter out = response.getWriter();
42 int count = getCount(request);
43 out.println(Integer.toString(count));
44 out.close();
45 }
46
47 private int getCount(HttpServletRequest request) {
48 try {
49 String id = request.getParameter("id");
50 if (id == null || id.equals("")) {
51 return 0;
52 }
53 String idType = request.getParameter("idType");
54 if (idType == null || idType.equals("")) {
55 idType = "a";
56 }
57 String principalId = null;
58 if ("emplId".equalsIgnoreCase(idType) || "e".equalsIgnoreCase(idType)) {
59 Person person = KimApiServiceLocator.getPersonService().getPersonByEmployeeId(id);
60 if (person != null) {
61 principalId = person.getPrincipalId();
62 }
63 } else if ("workflowId".equalsIgnoreCase(idType) || "w".equalsIgnoreCase(idType)) {
64 principalId = id;
65 } else if ("authenticationId".equalsIgnoreCase(idType) || "a".equalsIgnoreCase(idType)) {
66 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(id);
67 if (principal != null) {
68 principalId = principal.getPrincipalId();
69 }
70 }
71 if (principalId == null) {
72 return 0;
73 }
74 return KEWServiceLocator.getActionListService().getCount(principalId);
75 } catch (Throwable t) {
76 LOG.error("Fatal error when querying for Action List Count", t);
77 return 0;
78 }
79 }
80
81
82
83 }