001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.actionlist;
017
018 import org.kuali.rice.kew.service.KEWServiceLocator;
019 import org.kuali.rice.kim.api.identity.Person;
020 import org.kuali.rice.kim.api.identity.principal.Principal;
021 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
022
023 import javax.servlet.ServletException;
024 import javax.servlet.http.HttpServlet;
025 import javax.servlet.http.HttpServletRequest;
026 import javax.servlet.http.HttpServletResponse;
027 import java.io.IOException;
028 import java.io.PrintWriter;
029
030
031
032 public class ActionListCountServlet extends HttpServlet {
033
034 private static final long serialVersionUID = 260649920715567145L;
035
036 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionListCountServlet.class);
037
038 @Override
039 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
040 response.setContentType("text/plain");
041 PrintWriter out = response.getWriter();
042 int count = getCount(request);
043 out.println(Integer.toString(count));
044 out.close();
045 }
046
047 private int getCount(HttpServletRequest request) {
048 try {
049 String id = request.getParameter("id");
050 if (id == null || id.equals("")) {
051 return 0;
052 }
053 String idType = request.getParameter("idType");
054 if (idType == null || idType.equals("")) {
055 idType = "a";
056 }
057 String principalId = null;
058 if ("emplId".equalsIgnoreCase(idType) || "e".equalsIgnoreCase(idType)) {
059 Person person = KimApiServiceLocator.getPersonService().getPersonByEmployeeId(id);
060 if (person != null) {
061 principalId = person.getPrincipalId();
062 }
063 } else if ("workflowId".equalsIgnoreCase(idType) || "w".equalsIgnoreCase(idType)) {
064 principalId = id;
065 } else if ("authenticationId".equalsIgnoreCase(idType) || "a".equalsIgnoreCase(idType)) {
066 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(id);
067 if (principal != null) {
068 principalId = principal.getPrincipalId();
069 }
070 }
071 if (principalId == null) {
072 return 0;
073 }
074 return KEWServiceLocator.getActionListService().getCount(principalId);
075 } catch (Throwable t) {
076 LOG.error("Fatal error when querying for Action List Count", t);
077 return 0;
078 }
079 }
080
081
082
083 }