Coverage Report - org.kuali.rice.kew.actiontaken.service.impl.ActionTakenServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionTakenServiceImpl
0%
0/72
0%
0/42
2.222
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.actiontaken.service.impl;
 18  
 
 19  
 import java.sql.Timestamp;
 20  
 import java.util.ArrayList;
 21  
 import java.util.Collection;
 22  
 import java.util.List;
 23  
 
 24  
 import org.apache.commons.lang.StringUtils;
 25  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 26  
 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
 27  
 import org.kuali.rice.kew.actiontaken.dao.ActionTakenDAO;
 28  
 import org.kuali.rice.kew.actiontaken.service.ActionTakenService;
 29  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
 30  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl;
 31  
 import org.kuali.rice.kew.routeheader.service.RouteHeaderService;
 32  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 33  
 import org.kuali.rice.kew.util.KEWConstants;
 34  
 import org.kuali.rice.kim.api.entity.principal.Principal;
 35  
 import org.kuali.rice.kim.api.services.IdentityManagementService;
 36  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 37  
 
 38  
 
 39  
 
 40  
 /**
 41  
  * Default implementation of the {@link ActionTakenService}.
 42  
  *
 43  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 44  
  */
 45  0
 public class ActionTakenServiceImpl implements ActionTakenService {
 46  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionTakenServiceImpl.class);
 47  
     private ActionTakenDAO actionTakenDAO;
 48  
 
 49  
     public ActionTakenValue load(Long id) {
 50  0
         return getActionTakenDAO().load(id);
 51  
     }
 52  
 
 53  
     public ActionTakenValue findByActionTakenId(Long actionTakenId) {
 54  0
         return getActionTakenDAO().findByActionTakenId(actionTakenId);
 55  
     }
 56  
 
 57  
     public ActionTakenValue getPreviousAction(ActionRequestValue actionRequest) {
 58  0
             return getPreviousAction(actionRequest, null);
 59  
     }
 60  
 
 61  
     public ActionTakenValue getPreviousAction(ActionRequestValue actionRequest, List<ActionTakenValue> simulatedActionsTaken)
 62  
     {
 63  0
         IdentityManagementService ims = KimApiServiceLocator.getIdentityManagementService();
 64  0
         ActionTakenValue foundActionTaken = null;
 65  0
         List<String> principalIds = new ArrayList<String>();
 66  0
         if (actionRequest.isGroupRequest()) {
 67  0
             principalIds.addAll( ims.getGroupMemberPrincipalIds(actionRequest.getGroup().getId()));
 68  0
         } else if (actionRequest.isUserRequest()) {
 69  0
             principalIds.add(actionRequest.getPrincipalId());
 70  
         }
 71  
 
 72  0
         for (String id : principalIds)
 73  
         {
 74  0
             List<ActionTakenValue> actionsTakenByUser =
 75  
                 getActionTakenDAO().findByDocumentIdWorkflowId(actionRequest.getDocumentId(), id );
 76  0
             if (simulatedActionsTaken != null) {
 77  0
                 for (ActionTakenValue simulatedAction : simulatedActionsTaken)
 78  
                 {
 79  0
                     if (id.equals(simulatedAction.getPrincipalId()))
 80  
                     {
 81  0
                         actionsTakenByUser.add(simulatedAction);
 82  
                     }
 83  
                 }
 84  
             }
 85  
 
 86  0
             for (ActionTakenValue actionTaken : actionsTakenByUser)
 87  
             {
 88  0
                 if (ActionRequestValue.compareActionCode(actionTaken.getActionTaken(),
 89  
                         actionRequest.getActionRequested(), true) >= 0)
 90  
                 {
 91  0
                   foundActionTaken = actionTaken;
 92  
                 }
 93  
             }
 94  0
         }
 95  
 
 96  0
         return foundActionTaken;
 97  
     }
 98  
 
 99  
     public Collection findByDocIdAndAction(String docId, String action) {
 100  0
         return getActionTakenDAO().findByDocIdAndAction(docId, action);
 101  
     }
 102  
 
 103  
     public Collection<ActionTakenValue> findByDocumentId(String documentId) {
 104  0
         return getActionTakenDAO().findByDocumentId(documentId);
 105  
     }
 106  
 
 107  
     public List findByDocumentIdWorkflowId(String documentId, String workflowId) {
 108  0
         return getActionTakenDAO().findByDocumentIdWorkflowId(documentId, workflowId);
 109  
     }
 110  
 
 111  
     public Collection getActionsTaken(String documentId) {
 112  0
         return getActionTakenDAO().findByDocumentId(documentId);
 113  
     }
 114  
 
 115  
     public List findByDocumentIdIgnoreCurrentInd(String documentId) {
 116  0
         return getActionTakenDAO().findByDocumentIdIgnoreCurrentInd(documentId);
 117  
     }
 118  
 
 119  
     public void saveActionTaken(ActionTakenValue actionTaken) {
 120  0
         this.getActionTakenDAO().saveActionTaken(actionTaken);
 121  0
     }
 122  
 
 123  
     public void delete(ActionTakenValue actionTaken) {
 124  0
         getActionTakenDAO().deleteActionTaken(actionTaken);
 125  0
     }
 126  
 
 127  
     public ActionTakenDAO getActionTakenDAO() {
 128  0
         return actionTakenDAO;
 129  
     }
 130  
 
 131  
     public void setActionTakenDAO(ActionTakenDAO actionTakenDAO) {
 132  0
         this.actionTakenDAO = actionTakenDAO;
 133  0
     }
 134  
 
 135  
     public void deleteByDocumentId(String documentId){
 136  0
         actionTakenDAO.deleteByDocumentId(documentId);
 137  0
     }
 138  
 
 139  
     public void validateActionTaken(ActionTakenValue actionTaken){
 140  0
         LOG.debug("Enter validateActionTaken(..)");
 141  0
         List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>();
 142  
 
 143  0
         String documentId = actionTaken.getDocumentId();
 144  0
         if(documentId == null){
 145  0
             errors.add(new WorkflowServiceErrorImpl("ActionTaken documentid null.", "actiontaken.documentid.empty", actionTaken.getActionTakenId().toString()));
 146  0
         } else if(getRouteHeaderService().getRouteHeader(documentId) == null){
 147  0
             errors.add(new WorkflowServiceErrorImpl("ActionTaken documentid invalid.", "actiontaken.documentid.invalid", actionTaken.getActionTakenId().toString()));
 148  
         }
 149  
 
 150  0
         String principalId = actionTaken.getPrincipalId();
 151  0
         if(StringUtils.isBlank(principalId)){
 152  0
             errors.add(new WorkflowServiceErrorImpl("ActionTaken personid null.", "actiontaken.personid.empty", actionTaken.getActionTakenId().toString()));
 153  
         } else {
 154  0
                 Principal principal = KimApiServiceLocator.getIdentityManagementService().getPrincipal(principalId);
 155  0
                 if (principal == null) {
 156  0
                 errors.add(new WorkflowServiceErrorImpl("ActionTaken personid invalid.", "actiontaken.personid.invalid", actionTaken.getActionTakenId().toString()));
 157  
             }
 158  
         }
 159  0
         String actionTakenCd = actionTaken.getActionTaken();
 160  0
         if(actionTakenCd == null || actionTakenCd.trim().equals("")){
 161  0
             errors.add(new WorkflowServiceErrorImpl("ActionTaken cd null.", "actiontaken.actiontaken.empty", actionTaken.getActionTakenId().toString()));
 162  0
         } else if(!KEWConstants.ACTION_TAKEN_CD.containsKey(actionTakenCd)){
 163  0
             errors.add(new WorkflowServiceErrorImpl("ActionTaken invalid.", "actiontaken.actiontaken.invalid", actionTaken.getActionTakenId().toString()));
 164  
         }
 165  0
         if(actionTaken.getActionDate() == null){
 166  0
             errors.add(new WorkflowServiceErrorImpl("ActionTaken actiondate null.", "actiontaken.actiondate.empty", actionTaken.getActionTakenId().toString()));
 167  
         }
 168  
 
 169  0
         if(actionTaken.getDocVersion() == null){
 170  0
             errors.add(new WorkflowServiceErrorImpl("ActionTaken docversion null.", "actiontaken.docverion.empty", actionTaken.getActionTakenId().toString()));
 171  
         }
 172  0
         LOG.debug("Exit validateActionRequest(..) ");
 173  0
         if (!errors.isEmpty()) {
 174  0
             throw new WorkflowServiceErrorException("ActionRequest Validation Error", errors);
 175  
         }
 176  0
     }
 177  
 
 178  
     public boolean hasUserTakenAction(String principalId, String documentId) {
 179  0
             return getActionTakenDAO().hasUserTakenAction(principalId, documentId);
 180  
     }
 181  
 
 182  
     private RouteHeaderService getRouteHeaderService() {
 183  0
         return (RouteHeaderService) KEWServiceLocator.getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV);
 184  
     }
 185  
 
 186  
     public Timestamp getLastApprovedDate(String documentId)
 187  
     {
 188  0
             Timestamp dateLastApproved = null;
 189  0
             Collection<ActionTakenValue> actionsTaken= getActionTakenDAO().findByDocIdAndAction(documentId, KEWConstants.ACTION_TAKEN_APPROVED_CD);
 190  0
         for (ActionTakenValue actionTaken : actionsTaken)
 191  
         {
 192  
             // search for the most recent approval action
 193  0
             if (dateLastApproved == null || dateLastApproved.compareTo(actionTaken.getActionDate()) <= -1)
 194  
             {
 195  0
                 dateLastApproved = actionTaken.getActionDate();
 196  
             }
 197  
         }
 198  0
             LOG.info("Exit getLastApprovedDate("+documentId+") "+dateLastApproved);
 199  0
             return dateLastApproved;
 200  
     }
 201  
 
 202  
 }