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 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  0
 public class ActionListCountServlet extends HttpServlet {
 33  
 
 34  
         private static final long serialVersionUID = 260649920715567145L;
 35  
 
 36  0
         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  0
                 response.setContentType("text/plain");
 41  0
             PrintWriter out = response.getWriter();
 42  0
             int count = getCount(request);
 43  0
             out.println(Integer.toString(count));
 44  0
             out.close();
 45  0
         }
 46  
 
 47  
         private int getCount(HttpServletRequest request) {
 48  
                 try {
 49  0
                         String id = request.getParameter("id");
 50  0
                         if (id == null || id.equals("")) {
 51  0
                                 return 0;
 52  
                         }
 53  0
                         String idType = request.getParameter("idType");
 54  0
                         if (idType == null || idType.equals("")) {
 55  0
                                 idType = "a";
 56  
                         }
 57  0
                         String principalId = null;
 58  0
                         if ("emplId".equalsIgnoreCase(idType) || "e".equalsIgnoreCase(idType)) {
 59  0
                                 Person person = KimApiServiceLocator.getPersonService().getPersonByEmployeeId(id);
 60  0
                                 if (person != null) {
 61  0
                                         principalId = person.getPrincipalId();
 62  
                                 }
 63  0
                         } else if ("workflowId".equalsIgnoreCase(idType) || "w".equalsIgnoreCase(idType)) {
 64  0
                                 principalId = id;
 65  0
                     } else if ("authenticationId".equalsIgnoreCase(idType) || "a".equalsIgnoreCase(idType)) {
 66  0
                             Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(id);
 67  0
                             if (principal != null) {
 68  0
                                     principalId = principal.getPrincipalId();
 69  
                             }
 70  
                     }
 71  0
                         if (principalId == null) {
 72  0
                                 return 0;
 73  
                         }
 74  0
                         return KEWServiceLocator.getActionListService().getCount(principalId);
 75  0
                 } catch (Throwable t) {
 76  0
                         LOG.error("Fatal error when querying for Action List Count", t);
 77  0
                         return 0;
 78  
                 }
 79  
         }
 80  
 
 81  
 
 82  
 
 83  
 }