@Override
  public boolean isAllowed(final String key, final Map<String, Serializable> context)
      throws SExecutionException {
    long userId = getLoggedUserId(sessionAccessor, sessionService);
    Long processInstanceId = getLongParameter(context, URLAdapterConstants.ID_QUERY_PARAM);
    if (processInstanceId == null) {
      throw new IllegalArgumentException(
          "Parameter 'id' is mandatory to execute Page Authorization rule 'IsProcessInitiatorRule'");
    }

    // is user assigned or has pending tasks on this process instance:
    final QueryOptions queryOptions =
        new QueryOptions(
            0,
            1,
            Collections.EMPTY_LIST,
            Arrays.asList(
                new FilterOption(SHumanTaskInstance.class, "logicalGroup2", processInstanceId)),
            null);
    try {
      return activityInstanceService.getNumberOfPendingOrAssignedTasks(userId, queryOptions) > 0;
    } catch (SBonitaReadException e) {
      throw new SExecutionException(e);
    }
  }
 private void deleteFlowNodeInstances(
     final long processInstanceId, final SProcessDefinition processDefinition)
     throws SFlowNodeReadException, SProcessInstanceModificationException {
   List<SFlowNodeInstance> activityInstances;
   do {
     activityInstances = activityService.getFlowNodeInstances(processInstanceId, 0, BATCH_SIZE);
     for (final SFlowNodeInstance activityInstance : activityInstances) {
       deleteFlowNodeInstance(activityInstance, processDefinition);
     }
   } while (!activityInstances.isEmpty());
 }
 @Override
 public void deleteFlowNodeInstance(
     final SFlowNodeInstance flowNodeInstance, final SProcessDefinition processDefinition)
     throws SProcessInstanceModificationException {
   try {
     deleteFlowNodeInstanceElements(flowNodeInstance, processDefinition);
     activityService.deleteFlowNodeInstance(flowNodeInstance);
   } catch (final SBonitaException e) {
     throw new SProcessInstanceModificationException(e);
   }
 }
 private void deleteFlowNodeInstanceElements(
     final SFlowNodeInstance flowNodeInstance, final SProcessDefinition processDefinition)
     throws SBonitaException {
   if (flowNodeInstance.getType().equals(SFlowNodeType.INTERMEDIATE_CATCH_EVENT)) {
     bpmEventInstanceService.deleteWaitingEvents(flowNodeInstance);
   }
   if (flowNodeInstance instanceof SEventInstance) {
     bpmEventInstanceService.deleteEventTriggerInstances(flowNodeInstance.getId());
   } else if (flowNodeInstance instanceof SActivityInstance) {
     deleteDataInstancesIfNecessary(flowNodeInstance, processDefinition);
     deleteConnectorInstancesIfNecessary(flowNodeInstance, processDefinition);
     if (SFlowNodeType.USER_TASK.equals(flowNodeInstance.getType())
         || SFlowNodeType.MANUAL_TASK.equals(flowNodeInstance.getType())) {
       activityService.deleteHiddenTasksForActivity(flowNodeInstance.getId());
       try {
         activityService.deletePendingMappings(flowNodeInstance.getId());
       } catch (final SActivityModificationException e) {
         throw new SFlowNodeReadException(e);
       }
     } else if (SFlowNodeType.CALL_ACTIVITY.equals(flowNodeInstance.getType())
         || SFlowNodeType.SUB_PROCESS.equals(flowNodeInstance.getType())) {
       // in the case of a call activity or subprocess activity delete the child process instance
       try {
         deleteProcessInstance(getChildOfActivity(flowNodeInstance.getId()));
       } catch (final SProcessInstanceNotFoundException e) {
         final StringBuilder stb = new StringBuilder();
         stb.append("Can't find the process instance called by the activity [id: ");
         stb.append(flowNodeInstance.getId());
         stb.append(", name: ");
         stb.append(flowNodeInstance.getName());
         stb.append("]. This process may be already finished");
         // if the child process is not found, it's because it has already finished and archived or
         // it was not created
         if (logger.isLoggable(getClass(), TechnicalLogSeverity.DEBUG)) {
           logger.log(getClass(), TechnicalLogSeverity.DEBUG, stb.toString());
           logger.log(getClass(), TechnicalLogSeverity.DEBUG, e);
         }
       }
     }
   }
 }
 private void deleteArchivedFlowNodeInstances(final long processInstanceId)
     throws SFlowNodeReadException, SBonitaSearchException, SConnectorInstanceDeletionException,
         SFlowNodeDeletionException, SDataInstanceException {
   List<SAFlowNodeInstance> activityInstances;
   do {
     activityInstances =
         activityService.getArchivedFlowNodeInstances(processInstanceId, 0, BATCH_SIZE);
     final HashSet<Long> orgActivityIds = new HashSet<Long>();
     final ArrayList<SAFlowNodeInstance> orgActivities = new ArrayList<SAFlowNodeInstance>();
     for (final SAFlowNodeInstance activityInstance : activityInstances) {
       if (!orgActivityIds.contains(activityInstance.getSourceObjectId())) {
         orgActivityIds.add(activityInstance.getSourceObjectId());
         orgActivities.add(activityInstance);
       }
       activityService.deleteArchivedFlowNodeInstance(activityInstance);
     }
     for (final SAFlowNodeInstance orgActivity : orgActivities) {
       deleteArchivedFlowNodeInstanceElements(orgActivity);
     }
   } while (!activityInstances.isEmpty());
 }
 @Override
 public void execute() throws SBonitaException {
   final SActivityInstance activityInstance =
       activityInstanceService.getActivityInstance(userTaskId);
   if (userId == 0 && SFlowNodeType.MANUAL_TASK.equals(activityInstance.getType())) {
     throw new SUnreleasableTaskException(
         "The activity with id "
             + activityInstance.getId()
             + " can't be assigned because it is a manual sub task");
   }
   activityInstanceService.assignHumanTask(userTaskId, userId);
   if (userId > 0) {
     activityInstanceService.deleteHiddenTasksForActivity(activityInstance.getId());
     final SUser user = identityService.getUser(userId);
     if (commentService.isCommentEnabled(SystemCommentType.STATE_CHANGE)) {
       commentService.addSystemComment(
           activityInstance.getRootContainerId(),
           "The task \""
               + activityInstance.getDisplayName()
               + "\" is now assigned to "
               + user.getUserName());
     }
   }
 }
  @Test
  public void shouldBeAllowedIAnArchivedTaskIsAssignedToGivenUserWithPagination() throws Exception {

    Map<String, Serializable> context = buildContext(541L, null);
    final SAUserTaskInstance notMatchingArchivedTask = mock(SAUserTaskInstance.class);
    final SAUserTaskInstance userTaskInstance = mock(SAUserTaskInstance.class);
    doReturn(loggedUserId).when(userTaskInstance).getAssigneeId();
    when(activityInstanceService.searchArchivedTasks(any(QueryOptions.class)))
        .thenReturn(
            Arrays.<SAHumanTaskInstance>asList(notMatchingArchivedTask),
            Arrays.<SAHumanTaskInstance>asList(userTaskInstance));

    final boolean allowed = rule.isAllowed("someKey", context);

    assertThat(allowed).isTrue();
  }
 protected void checkIfCallerIsNotActive(final long callerId)
     throws SFlowNodeReadException, SProcessInstanceHierarchicalDeletionException {
   if (callerId > 0) {
     try {
       final SFlowNodeInstance flowNodeInstance = activityService.getFlowNodeInstance(callerId);
       throw new SProcessInstanceHierarchicalDeletionException(
           "Unable to delete the process instance because the parent is still active: activity "
               + flowNodeInstance.getName()
               + " with id "
               + flowNodeInstance.getId(),
           flowNodeInstance.getRootProcessInstanceId());
     } catch (final SFlowNodeNotFoundException e) {
       // ok the activity that called this process do not exists anymore
     }
   }
 }
 private void deleteArchivedFlowNodeInstanceElements(final SAFlowNodeInstance activityInstance)
     throws SFlowNodeReadException, SBonitaSearchException, SConnectorInstanceDeletionException,
         SDataInstanceException {
   if (activityInstance instanceof SAActivityInstance) {
     dataInstanceService.deleteLocalArchivedDataInstances(
         activityInstance.getSourceObjectId(), DataInstanceContainer.ACTIVITY_INSTANCE.toString());
     connectorInstanceService.deleteArchivedConnectorInstances(
         activityInstance.getSourceObjectId(), SConnectorInstance.FLOWNODE_TYPE);
     if (SFlowNodeType.USER_TASK.equals(activityInstance.getType())
         || SFlowNodeType.MANUAL_TASK.equals(activityInstance.getType())) {
       try {
         activityService.deleteArchivedPendingMappings(activityInstance.getSourceObjectId());
       } catch (final SActivityModificationException e) {
         throw new SFlowNodeReadException(e);
       }
     }
   }
 }
Esempio n. 10
0
 @Override
 public void execute() throws SBonitaException {
   isHidden = activityInstanceService.isTaskHidden(userId, activityInstanceId);
 }
 @Override
 public List<SActivityInstance> executeSearch(final QueryOptions searchOptions)
     throws SBonitaSearchException {
   return activityInstanceService.searchActivityInstances(getEntityClass(), searchOptions);
 }
 @Override
 public long executeCount(final QueryOptions searchOptions) throws SBonitaSearchException {
   return activityInstanceService.getNumberOfActivityInstances(getEntityClass(), searchOptions);
 }
 @Override
 public void execute() throws SBonitaException {
   humanTaskInstance = activityInstanceService.getHumanTaskInstance(activityInstanceId);
 }