Search in sources :

Example 46 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskFailed.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskFailed() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    taskService.start(taskId, "Administrator");
    taskService.fail(taskId, "Administrator", null);
    // emails should not be set yet
    assertEquals(0, getWiser().getMessages().size());
    countDownListener.waitTillCompleted();
    // no email should ne sent as task was completed before deadline was triggered
    assertEquals(0, getWiser().getMessages().size());
    task = (InternalTask) taskService.getTaskById(taskId);
    assertEquals(Status.Failed, task.getTaskData().getStatus());
    assertEquals(0, task.getDeadlines().getStartDeadlines().size());
    assertEquals(0, task.getDeadlines().getEndDeadlines().size());
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 47 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class AssignmentService method assignTask.

public void assignTask(Task task) {
    List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners();
    potentialOwners.clear();
    Group group = TaskModelProvider.getFactory().newGroup();
    ((InternalOrganizationalEntity) group).setId("Crusaders");
    potentialOwners.add(group);
}
Also used : Group(org.kie.api.task.model.Group) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity)

Example 48 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class MVELLifeCycleManager method taskOperation.

public void taskOperation(final Operation operation, final long taskId, final String userId, final String targetEntityId, final Map<String, Object> data, List<String> groupIds, OrganizationalEntity... entities) throws TaskException {
    try {
        final List<OperationCommand> commands = operations.get(operation);
        Task task = persistenceContext.findTask(taskId);
        if (task == null) {
            String errorMessage = "Task '" + taskId + "' not found";
            throw new PermissionDeniedException(errorMessage);
        }
        String deploymentId = (String) context.get(EnvironmentName.DEPLOYMENT_ID);
        if (deploymentId != null && !deploymentId.equals(task.getTaskData().getDeploymentId())) {
            throw new IllegalStateException("Task instance " + task.getId() + " is owned by another deployment expected " + task.getTaskData().getDeploymentId() + " found " + deploymentId);
        }
        // automatically load task variables on each operation if the event manager is activated
        if (EventManagerProvider.getInstance().isActive()) {
            taskContentService.loadTaskVariables(task);
        }
        User user = persistenceContext.findUser(userId);
        OrganizationalEntity targetEntity = null;
        if (targetEntityId != null && !targetEntityId.equals("")) {
            targetEntity = persistenceContext.findOrgEntity(targetEntityId);
        }
        getExecutionErrorHandler().processing(task);
        switch(operation) {
            case Activate:
                {
                    taskEventSupport.fireBeforeTaskActivated(task, context);
                    break;
                }
            case Claim:
                {
                    taskEventSupport.fireBeforeTaskClaimed(task, context);
                    break;
                }
            case Complete:
                {
                    taskEventSupport.fireBeforeTaskCompleted(task, context);
                    break;
                }
            case Delegate:
                {
                    taskEventSupport.fireBeforeTaskDelegated(task, context);
                    break;
                }
            case Exit:
                {
                    taskEventSupport.fireBeforeTaskExited(task, context);
                    break;
                }
            case Fail:
                {
                    if (data != null) {
                        FaultData faultData = ContentMarshallerHelper.marshalFault(task, data, null);
                        Content content = TaskModelProvider.getFactory().newContent();
                        ((InternalContent) content).setContent(faultData.getContent());
                        persistenceContext.persistContent(content);
                        persistenceContext.setFaultToTask(content, faultData, task);
                    }
                    taskEventSupport.fireBeforeTaskFailed(task, context);
                    break;
                }
            case Forward:
                {
                    taskEventSupport.fireBeforeTaskForwarded(task, context);
                    break;
                }
            case Nominate:
                {
                    taskEventSupport.fireBeforeTaskNominated(task, context);
                    break;
                }
            case Release:
                {
                    taskEventSupport.fireBeforeTaskReleased(task, context);
                    break;
                }
            case Resume:
                {
                    taskEventSupport.fireBeforeTaskResumed(task, context);
                    break;
                }
            case Skip:
                {
                    taskEventSupport.fireBeforeTaskSkipped(task, context);
                    break;
                }
            case Start:
                {
                    taskEventSupport.fireBeforeTaskStarted(task, context);
                    break;
                }
            case Stop:
                {
                    taskEventSupport.fireBeforeTaskStopped(task, context);
                    break;
                }
            case Suspend:
                {
                    taskEventSupport.fireBeforeTaskSuspended(task, context);
                    break;
                }
        }
        evalCommand(operation, commands, task, user, targetEntity, groupIds, entities);
        persistenceContext.updateTask(task);
        switch(operation) {
            case Activate:
                {
                    taskEventSupport.fireAfterTaskActivated(task, context);
                    break;
                }
            case Claim:
                {
                    taskEventSupport.fireAfterTaskClaimed(task, context);
                    break;
                }
            case Complete:
                {
                    if (data != null) {
                        taskContentService.addOutputContent(taskId, data);
                    }
                    taskEventSupport.fireAfterTaskCompleted(task, context);
                    break;
                }
            case Delegate:
                {
                    // This is a really bad hack to execut the correct behavior
                    ((InternalTaskData) task.getTaskData()).setStatus(Status.Reserved);
                    taskEventSupport.fireAfterTaskDelegated(task, context);
                    break;
                }
            case Exit:
                {
                    taskEventSupport.fireAfterTaskExited(task, context);
                    break;
                }
            case Fail:
                {
                    taskEventSupport.fireAfterTaskFailed(task, context);
                    break;
                }
            case Forward:
                {
                    invokeAssignmentService(task, context, userId);
                    taskEventSupport.fireAfterTaskForwarded(task, context);
                    break;
                }
            case Nominate:
                {
                    invokeAssignmentService(task, context, userId);
                    taskEventSupport.fireAfterTaskNominated(task, context);
                    break;
                }
            case Release:
                {
                    invokeAssignmentService(task, context, userId);
                    taskEventSupport.fireAfterTaskReleased(task, context);
                    break;
                }
            case Resume:
                {
                    taskEventSupport.fireAfterTaskResumed(task, context);
                    break;
                }
            case Start:
                {
                    taskEventSupport.fireAfterTaskStarted(task, context);
                    break;
                }
            case Skip:
                {
                    taskEventSupport.fireAfterTaskSkipped(task, context);
                    break;
                }
            case Stop:
                {
                    taskEventSupport.fireAfterTaskStopped(task, context);
                    break;
                }
            case Suspend:
                {
                    taskEventSupport.fireAfterTaskSuspended(task, context);
                    break;
                }
        }
        getExecutionErrorHandler().processed(task);
    } catch (RuntimeException re) {
        throw re;
    }
}
Also used : Task(org.kie.api.task.model.Task) User(org.kie.api.task.model.User) FaultData(org.kie.internal.task.api.model.FaultData) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException)

Example 49 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class JaxbTask method copyOrganizationalEntityList.

private List<OrganizationalEntity> copyOrganizationalEntityList(List<OrganizationalEntity> jaxbOrgEntList) {
    if (jaxbOrgEntList == null) {
        return null;
    }
    List<OrganizationalEntity> orgEntList = new ArrayList<OrganizationalEntity>(jaxbOrgEntList.size());
    for (OrganizationalEntity jaxbOrgEnt : jaxbOrgEntList) {
        if (jaxbOrgEnt instanceof User) {
            User user = createUser(jaxbOrgEnt.getId());
            orgEntList.add(user);
        } else if (jaxbOrgEnt instanceof Group) {
            Group group = createGroup(jaxbOrgEnt.getId());
            orgEntList.add(group);
        }
    }
    return orgEntList;
}
Also used : Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) ArrayList(java.util.ArrayList)

Example 50 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class DBUserInfoImpl method getMembersForGroup.

@Override
public Iterator<OrganizationalEntity> getMembersForGroup(Group group) {
    List<OrganizationalEntity> roles = new ArrayList<OrganizationalEntity>();
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        conn = ds.getConnection();
        ps = conn.prepareStatement(this.config.getProperty(MEMBERS_QUERY));
        try {
            ps.setString(1, group.getId());
        } catch (ArrayIndexOutOfBoundsException ignore) {
        }
        rs = ps.executeQuery();
        while (rs.next()) {
            roles.add(TaskModelProvider.getFactory().newUser(rs.getString(1)));
        }
    } catch (Exception e) {
        logger.error("Error when fetching members of a group from db, groups id: ", group.getId(), e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
            }
        }
        if (ps != null) {
            try {
                ps.close();
            } catch (SQLException e) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception ex) {
            }
        }
    }
    return roles.iterator();
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Aggregations

OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)147 Test (org.junit.Test)94 HashMap (java.util.HashMap)69 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)55 ArrayList (java.util.ArrayList)54 User (org.kie.api.task.model.User)52 UserImpl (org.jbpm.services.task.impl.model.UserImpl)51 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)48 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)41 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)36 InternalTask (org.kie.internal.task.api.model.InternalTask)35 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)34 Task (org.kie.api.task.model.Task)33 QueryContext (org.kie.api.runtime.query.QueryContext)32 Group (org.kie.api.task.model.Group)29 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)26 TaskSummary (org.kie.api.task.model.TaskSummary)25 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)24 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)24 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)24