Coverage Report - org.kuali.rice.kew.actionlist.service.impl.ActionListServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionListServiceImpl
0%
0/142
0%
0/78
2.355
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in
 6  
  * compliance with the License. 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 distributed under the License is distributed on an "AS
 11  
  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
 12  
  * language governing permissions and limitations under the License.
 13  
  */
 14  
 package org.kuali.rice.kew.actionlist.service.impl;
 15  
 
 16  
 import java.sql.Timestamp;
 17  
 import java.util.ArrayList;
 18  
 import java.util.Collection;
 19  
 import java.util.Date;
 20  
 import java.util.Iterator;
 21  
 import java.util.List;
 22  
 
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 import org.kuali.rice.core.config.ConfigContext;
 25  
 import org.kuali.rice.kew.actionitem.ActionItem;
 26  
 import org.kuali.rice.kew.actionitem.OutboxItemActionListExtension;
 27  
 import org.kuali.rice.kew.actionitem.dao.ActionItemDAO;
 28  
 import org.kuali.rice.kew.actionlist.ActionListFilter;
 29  
 import org.kuali.rice.kew.actionlist.dao.ActionListDAO;
 30  
 import org.kuali.rice.kew.actionlist.service.ActionListService;
 31  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 32  
 import org.kuali.rice.kew.actionrequest.Recipient;
 33  
 import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
 34  
 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
 35  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 36  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
 37  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl;
 38  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 39  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 40  
 import org.kuali.rice.kew.useroptions.UserOptions;
 41  
 import org.kuali.rice.kew.useroptions.UserOptionsService;
 42  
 import org.kuali.rice.kew.util.KEWConstants;
 43  
 import org.kuali.rice.kim.bo.entity.KimPrincipal;
 44  
 import org.kuali.rice.kim.service.GroupService;
 45  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 46  
 
 47  
 /**
 48  
  * Default implementation of the {@link ActionListService}.
 49  
  *
 50  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 51  
  */
 52  0
 public class ActionListServiceImpl implements ActionListService {
 53  
 
 54  0
     protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass());
 55  
 
 56  
     private ActionListDAO actionListDAO;
 57  
 
 58  
     private ActionItemDAO actionItemDAO;
 59  
 
 60  
     public Collection<Recipient> findUserSecondaryDelegators(String principalId) {
 61  0
         return getActionItemDAO().findSecondaryDelegators(principalId);
 62  
     }
 63  
 
 64  
     public Collection<Recipient> findUserPrimaryDelegations(String principalId) {
 65  0
         return getActionItemDAO().findPrimaryDelegationRecipients(principalId);
 66  
     }
 67  
 
 68  
     public Collection<ActionItem> getActionList(String principalId, ActionListFilter filter) {
 69  0
          return getActionListDAO().getActionList(principalId, filter);
 70  
     }
 71  
 
 72  
     public Collection<ActionItem> getActionListForSingleDocument(Long routeHeaderId) {
 73  0
          return getActionListDAO().getActionListForSingleDocument(routeHeaderId);
 74  
     }
 75  
 
 76  
     public void setActionListDAO(ActionListDAO actionListDAO) {
 77  0
         this.actionListDAO = actionListDAO;
 78  0
     }
 79  
 
 80  
     public ActionListDAO getActionListDAO() {
 81  0
         return actionListDAO;
 82  
     }
 83  
 
 84  
     public boolean refreshActionList(String principalId) {
 85  0
         return KEWServiceLocator.getUserOptionsService().refreshActionList(principalId);
 86  
     }
 87  
 
 88  
     public void deleteActionItem(ActionItem actionItem) {
 89  0
             deleteActionItem(actionItem, false);
 90  0
     }
 91  
     
 92  
     public void deleteActionItem(ActionItem actionItem, boolean forceIntoOutbox) {
 93  
         try {
 94  0
             KEWServiceLocator.getUserOptionsService().saveRefreshUserOption(actionItem.getPrincipalId());
 95  0
         } catch (Exception e) {
 96  0
             LOG.error("error saving refreshUserOption", e);
 97  0
         }
 98  0
         getActionItemDAO().deleteActionItem(actionItem);
 99  
         // remove notification from KCB
 100  0
         List<ActionItem> l = new ArrayList<ActionItem>(1);
 101  0
         l.add(actionItem);
 102  0
         KEWServiceLocator.getNotificationService().removeNotification(l);
 103  0
         this.saveOutboxItem(actionItem, forceIntoOutbox);
 104  0
     }
 105  
 
 106  
     public void deleteByRouteHeaderId(Long routeHeaderId) {
 107  0
         Collection<ActionItem> actionItems = findByRouteHeaderId(routeHeaderId);
 108  0
         for (Iterator<ActionItem> iter = actionItems.iterator(); iter.hasNext();) {
 109  0
             ActionItem actionItem = iter.next();
 110  
             try {
 111  0
                 KEWServiceLocator.getUserOptionsService().saveRefreshUserOption(actionItem.getPrincipalId());
 112  0
             } catch (Exception e) {
 113  0
                 LOG.error("error saving refreshUserOption", e);
 114  0
             }
 115  0
         }
 116  0
         getActionItemDAO().deleteByRouteHeaderId(routeHeaderId);
 117  0
     }
 118  
 
 119  
     public Collection<ActionItem> findByRouteHeaderId(Long routeHeaderId) {
 120  0
         return getActionItemDAO().findByRouteHeaderId(routeHeaderId);
 121  
     }
 122  
 
 123  
     public Collection<ActionItem> findByActionRequestId(Long actionRequestId) {
 124  0
         return getActionItemDAO().findByActionRequestId(actionRequestId);
 125  
     }
 126  
 
 127  
     public Collection<ActionItem> findByWorkflowUserRouteHeaderId(String workflowUserId, Long routeHeaderId) {
 128  0
         return getActionItemDAO().findByWorkflowUserRouteHeaderId(workflowUserId, routeHeaderId);
 129  
     }
 130  
 
 131  
     public Collection<ActionItem> findByDocumentTypeName(String documentTypeName) {
 132  0
         return getActionItemDAO().findByDocumentTypeName(documentTypeName);
 133  
     }
 134  
 
 135  
     public ActionItem createActionItemForActionRequest(ActionRequestValue actionRequest) {
 136  0
         ActionItem actionItem = new ActionItem();
 137  
 
 138  0
         DocumentRouteHeaderValue routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(
 139  
                 actionRequest.getRouteHeaderId());
 140  0
         DocumentType docType = routeHeader.getDocumentType();
 141  
 
 142  0
         actionItem.setActionRequestCd(actionRequest.getActionRequested());
 143  0
         actionItem.setActionRequestId(actionRequest.getActionRequestId());
 144  0
         actionItem.setDocName(docType.getName());
 145  0
         actionItem.setRoleName(actionRequest.getQualifiedRoleName());
 146  0
         actionItem.setPrincipalId(actionRequest.getPrincipalId());
 147  0
         actionItem.setRouteHeaderId(actionRequest.getRouteHeaderId());
 148  0
         actionItem.setRouteHeader(routeHeader);
 149  0
         actionItem.setDateAssigned(new Timestamp(new Date().getTime()));
 150  0
         actionItem.setDocHandlerURL(docType.getDocHandlerUrl());
 151  0
         actionItem.setDocLabel(docType.getLabel());
 152  0
         actionItem.setDocTitle(routeHeader.getDocTitle());
 153  0
         actionItem.setGroupId(actionRequest.getGroupId());
 154  0
         actionItem.setResponsibilityId(actionRequest.getResponsibilityId());
 155  0
         actionItem.setDelegationType(actionRequest.getDelegationType());
 156  0
         actionItem.setRequestLabel(actionRequest.getRequestLabel());
 157  
 
 158  0
         ActionRequestValue delegatorActionRequest = getActionRequestService().findDelegatorRequest(actionRequest);
 159  0
         if (delegatorActionRequest != null) {
 160  0
             actionItem.setDelegatorWorkflowId(delegatorActionRequest.getPrincipalId());
 161  0
             actionItem.setDelegatorGroupId(delegatorActionRequest.getGroupId());
 162  
         }
 163  
 
 164  0
         return actionItem;
 165  
     }
 166  
 
 167  
 
 168  
     public void updateActionItemsForTitleChange(Long routeHeaderId, String newTitle) {
 169  0
         Collection<ActionItem> items = getActionItemDAO().findByRouteHeaderId(routeHeaderId);
 170  0
         for (Iterator<ActionItem> iterator = items.iterator(); iterator.hasNext();) {
 171  0
             ActionItem item = iterator.next();
 172  0
             item.setDocTitle(newTitle);
 173  0
             saveActionItem(item);
 174  0
         }
 175  0
     }
 176  
 
 177  
     public void saveActionItem(ActionItem actionItem) {
 178  0
         KEWServiceLocator.getUserOptionsService().saveRefreshUserOption(actionItem.getPrincipalId());
 179  0
         getActionItemDAO().saveActionItem(actionItem);
 180  0
     }
 181  
 
 182  
     public ActionItemDAO getActionItemDAO() {
 183  0
         return actionItemDAO;
 184  
     }
 185  
 
 186  
     public ActionRequestService getActionRequestService() {
 187  0
         return (ActionRequestService) KEWServiceLocator.getActionRequestService();
 188  
     }
 189  
 
 190  
     public GroupService getGroupService(){
 191  0
             return KIMServiceLocator.getGroupService();
 192  
     }
 193  
 
 194  
     public void setActionItemDAO(ActionItemDAO actionItemDAO) {
 195  0
         this.actionItemDAO = actionItemDAO;
 196  0
     }
 197  
 
 198  
 
 199  
     public void validateActionItem(ActionItem actionItem) {
 200  0
         List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>();
 201  0
         String principalId = actionItem.getPrincipalId();
 202  0
         if (principalId == null || principalId.trim().equals("")) {
 203  0
             errors.add(new WorkflowServiceErrorImpl("ActionItem person null.", "actionitem.personid.empty", actionItem
 204  
                     .getActionItemId().toString()));
 205  
         } else {
 206  0
                 KimPrincipal principal = KIMServiceLocator.getIdentityManagementService().getPrincipal(principalId);
 207  0
                 if (principal == null) {
 208  0
                 errors.add(new WorkflowServiceErrorImpl("ActionItem person invalid.", "actionitem.personid.invalid",
 209  
                         actionItem.getActionItemId().toString()));
 210  
             }
 211  
         }
 212  
 
 213  0
         if (actionItem.getDateAssigned() == null) {
 214  0
             errors.add(new WorkflowServiceErrorImpl("ActionItem date assigned empty.", "actionitem.dateassigned.empty",
 215  
                     actionItem.getActionItemId().toString()));
 216  
         }
 217  
 
 218  0
         String actionRequestCd = actionItem.getActionRequestCd();
 219  0
         if (actionRequestCd == null || actionRequestCd.trim().equals("")) {
 220  0
             errors.add(new WorkflowServiceErrorImpl("ActionItem action request cd empty.",
 221  
                     "actionitem.actionrequestcd.empty", actionItem.getActionItemId().toString()));
 222  0
         } else if (!KEWConstants.ACTION_REQUEST_CD.containsKey(actionRequestCd)) {
 223  0
             errors.add(new WorkflowServiceErrorImpl("ActionItem action request cd invalid.",
 224  
                     "actionitem.actionrequestcd.invalid", actionItem.getActionItemId().toString()));
 225  
         }
 226  
 
 227  0
         if (actionItem.getActionRequestId() == null) {
 228  0
             errors.add(new WorkflowServiceErrorImpl("ActionItem action request id empty.",
 229  
                     "actionitem.actionrequestid.empty", actionItem.getActionItemId().toString()));
 230  
         }
 231  
 
 232  0
         if (actionItem.getRouteHeaderId() == null) {
 233  0
             errors.add(new WorkflowServiceErrorImpl("ActionItem Document id empty.", "actionitem.routeheaderid.empty",
 234  
                     actionItem.getActionItemId().toString()));
 235  0
         } else if (KEWServiceLocator.getRouteHeaderService().getRouteHeader(actionItem.getRouteHeaderId()) == null) {
 236  0
             errors.add(new WorkflowServiceErrorImpl("ActionItem Document id invalid.", "actionitem.routeheaderid.invalid",
 237  
                     actionItem.getActionItemId().toString()));
 238  
         }
 239  
 
 240  0
         String docTypeName = actionItem.getDocName();
 241  0
         DocumentType docType = null;
 242  0
         if (docTypeName == null || docTypeName.trim().equals("")) {
 243  0
             errors.add(new WorkflowServiceErrorImpl("ActionItem doctypename empty.", "actionitem.doctypename.empty",
 244  
                     actionItem.getActionItemId().toString()));
 245  
         } else {
 246  0
             docType = KEWServiceLocator.getDocumentTypeService().findByName(actionItem.getDocName());
 247  0
             if (docType == null) {
 248  0
                 errors.add(new WorkflowServiceErrorImpl("ActionItem doctypename invalid.", "actionitem.doctypename.invalid",
 249  
                         actionItem.getActionItemId().toString()));
 250  
             }
 251  
         }
 252  
 
 253  0
         if (actionItem.getDocLabel() == null || actionItem.getDocLabel().trim().equals("")) {
 254  0
             errors.add(new WorkflowServiceErrorImpl("ActionItem doctypelabel empty.", "actionitem.doctypelabel.empty",
 255  
                     actionItem.getActionItemId().toString()));
 256  0
         } else if (docType != null && !docType.getLabel().equals(actionItem.getDocLabel())) {
 257  0
             errors.add(new WorkflowServiceErrorImpl("ActionItem doctypelabel no match.", "actionitem.doctypelabel.nomatch",
 258  
                     actionItem.getActionItemId().toString()));
 259  
         }
 260  
 
 261  
         // first check to see if the document type has an empty document handler url
 262  0
         if (StringUtils.isNotBlank(docType.getDocHandlerUrl())) {
 263  0
             if (actionItem.getDocHandlerURL() == null || actionItem.getDocHandlerURL().trim().equals("")) {
 264  0
                 errors.add(new WorkflowServiceErrorImpl("ActionItem doc handler url empty.", "actionitem.dochdrurl.empty",
 265  
                         actionItem.getActionItemId().toString()));
 266  0
             } else if (docType != null && !docType.getDocHandlerUrl().equals(actionItem.getDocHandlerURL())) {
 267  0
                 errors.add(new WorkflowServiceErrorImpl("ActionItem doc handler url no match.", "actionitem.dochdrurl.nomatch",
 268  
                         actionItem.getActionItemId().toString()));
 269  
             }
 270  
         } else {
 271  
             // if the doc type doc handler url is blank, verify that the action item doc handler url is also blank
 272  0
             if (StringUtils.isNotBlank(actionItem.getDocHandlerURL())) {
 273  0
                 errors.add(new WorkflowServiceErrorImpl("ActionItem doc handler url not empty.", "actionitem.dochdrurl.not.empty", 
 274  
                         actionItem.getActionItemId().toString()));
 275  
             }
 276  
         }
 277  
 
 278  0
         if (!errors.isEmpty()) {
 279  0
             throw new WorkflowServiceErrorException("ActionItem Validation Error", errors);
 280  
         }
 281  0
     }
 282  
 
 283  
     public ActionItem findByActionItemId(Long actionItemId) {
 284  0
         return getActionItemDAO().findByActionItemId(actionItemId);
 285  
     }
 286  
 
 287  
     public int getCount(String principalId) {
 288  0
         return getActionListDAO().getCount(principalId);
 289  
     }
 290  
 
 291  
     public void saveRefreshUserOption(String principalId) {
 292  0
         KEWServiceLocator.getUserOptionsService().saveRefreshUserOption(principalId);
 293  0
     }
 294  
 
 295  
     /**
 296  
      *
 297  
      * This overridden method ...
 298  
      *
 299  
      * @see org.kuali.rice.kew.actionlist.service.ActionListService#getOutbox(java.lang.String, org.kuali.rice.kew.actionlist.ActionListFilter)
 300  
      */
 301  
     public Collection<ActionItem> getOutbox(String principalId, ActionListFilter filter) {
 302  0
         return this.getActionListDAO().getOutbox(principalId, filter);
 303  
     }
 304  
 
 305  
     public Collection<ActionItem> getOutboxItemsByDocumentType(String documentTypeName) {
 306  0
         return this.getActionItemDAO().getOutboxItemsByDocumentType(documentTypeName);
 307  
     }
 308  
 
 309  
     /**
 310  
      * This overridden method ...
 311  
      *
 312  
      * @see org.kuali.rice.kew.actionlist.service.ActionListService#removeOutboxItems(String, java.util.List)
 313  
      */
 314  
     public void removeOutboxItems(String principalId, List<String> outboxItems) {
 315  0
         this.getActionListDAO().removeOutboxItems(principalId, outboxItems);
 316  0
     }
 317  
 
 318  
     public void saveOutboxItem(ActionItem actionItem) {
 319  0
             saveOutboxItem(actionItem, false);
 320  0
     }
 321  
     
 322  
     /**
 323  
      *
 324  
      * save the ouboxitem unless the document is saved or the user already has the item in their outbox.
 325  
      *
 326  
      * @see org.kuali.rice.kew.actionlist.service.ActionListService#saveOutboxItem(org.kuali.rice.kew.actionitem.ActionItem, boolean)
 327  
      */
 328  
     public void saveOutboxItem(ActionItem actionItem, boolean forceIntoOutbox) {
 329  0
             UserOptionsService userOptionsService = KEWServiceLocator.getUserOptionsService();
 330  0
             Boolean isUsingOutBox = true;
 331  0
             List<UserOptions> options = userOptionsService.findByUserQualified(actionItem.getPrincipalId(), KEWConstants.USE_OUT_BOX);
 332  0
             if (options == null || options.isEmpty()){
 333  0
                     isUsingOutBox = true;
 334  
             } else {
 335  0
                         for (Iterator iter = options.iterator(); iter.hasNext();) {
 336  0
                                 UserOptions u = (UserOptions) iter.next();
 337  0
                                 if (u.getOptionVal() == null || !(u.getOptionVal().equals("yes"))){
 338  0
                                         isUsingOutBox = false;
 339  
                                 }
 340  0
                         }
 341  
             }
 342  
             
 343  0
             if (isUsingOutBox
 344  
             && ConfigContext.getCurrentContextConfig().getOutBoxOn()
 345  
             && getActionListDAO().getOutboxByDocumentIdUserId(actionItem.getRouteHeaderId(), actionItem.getPrincipalId()) == null
 346  
             && !KEWServiceLocator.getRouteHeaderService().getDocumentStatus(actionItem.getRouteHeaderId()).equals(KEWConstants.ROUTE_HEADER_SAVED_CD)) {
 347  
 
 348  
                     // only create an outbox item if this user has taken action on the document
 349  0
                     ActionRequestValue actionRequest = KEWServiceLocator.getActionRequestService().findByActionRequestId(
 350  
                                     actionItem.getActionRequestId());
 351  0
                     ActionTakenValue actionTaken = actionRequest.getActionTaken();
 352  
                     // if an action was taken...
 353  0
                     if (forceIntoOutbox || (actionTaken != null && actionTaken.getPrincipalId().equals(actionItem.getPrincipalId()))) {
 354  0
                             this.getActionListDAO().saveOutboxItem(new OutboxItemActionListExtension(actionItem));
 355  
                     }
 356  
        
 357  
             }
 358  0
     }
 359  
     
 360  
         public Collection<ActionItem> findByPrincipalId(String principalId) {
 361  0
                 return getActionItemDAO().findByPrincipalId(principalId);
 362  
         }
 363  
 
 364  
 }