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