View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.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/ecl2.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.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  }