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