Search in sources :

Example 1 with FaultData

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

the class LifeCycleBaseTest method testFailWithContent.

@Test
public void testFailWithContent() {
    // One potential owner, should go straight to state Reserved
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ], businessAdministrators = [ new User('Administrator') ],}),";
    str += "name =  'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    // Go straight from Ready to Inprogress
    taskService.start(taskId, "Darth Vader");
    taskService.getTaskById(taskId);
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(Status.InProgress, task1.getTaskData().getStatus());
    assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
    Map<String, Object> faultData = new HashMap<String, Object>();
    faultData.put("faultType", "type");
    faultData.put("faultName", "faultName");
    faultData.put("content", "content");
    taskService.fail(taskId, "Darth Vader", faultData);
    List<Content> allContent = taskService.getAllContentByTaskId(taskId);
    assertNotNull(allContent);
    assertEquals(3, allContent.size());
    // only input(0) and fault(2) is present
    assertNotNull(allContent.get(0));
    assertNull(allContent.get(1));
    assertNotNull(allContent.get(2));
    Task task2 = taskService.getTaskById(taskId);
    assertEquals(Status.Failed, task2.getTaskData().getStatus());
    assertEquals(AccessType.Inline, ((InternalTaskData) task2.getTaskData()).getFaultAccessType());
    assertEquals("type", task2.getTaskData().getFaultType());
    assertEquals("faultName", task2.getTaskData().getFaultName());
    long contentId = task2.getTaskData().getFaultContentId();
    assertTrue(contentId != -1);
    Content content = taskService.getContentById(contentId);
    Map<String, Object> unmarshalledContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), null);
    assertEquals("content", unmarshalledContent.get("content"));
    xmlRoundTripContent(content);
    // update fault
    FaultData data = TaskModelProvider.getFactory().newFaultData();
    data.setAccessType(AccessType.Inline);
    data.setType("type");
    data.setFaultName("faultName");
    data.setContent("updated content".getBytes());
    taskService.setFault(taskId, "Darth Vader", data);
    task = taskService.getTaskById(taskId);
    contentId = task.getTaskData().getFaultContentId();
    content = taskService.getContentById(contentId);
    String updated = new String(content.getContent());
    assertEquals("updated content", updated);
    // delete fault
    taskService.deleteFault(taskId, "Darth Vader");
    content = taskService.getContentById(contentId);
    assertNull(content);
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) FaultData(org.kie.internal.task.api.model.FaultData) HashMap(java.util.HashMap) Content(org.kie.api.task.model.Content) JaxbContent(org.jbpm.services.task.impl.model.xml.JaxbContent) StringReader(java.io.StringReader) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with FaultData

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

the class ContentMarshallerHelper method marshalFault.

public static FaultData marshalFault(Task task, Map<String, Object> fault, Environment env) {
    FaultData content = null;
    byte[] toByteArray = marshallContent(task, fault, env);
    content = TaskModelProvider.getFactory().newFaultData();
    content.setContent(toByteArray);
    content.setType(fault.getClass().getCanonicalName());
    content.setAccessType(AccessType.Inline);
    content.setFaultName((String) fault.get("faultName"));
    content.setType((String) fault.get("faultType"));
    return content;
}
Also used : FaultData(org.kie.internal.task.api.model.FaultData)

Example 3 with FaultData

use of org.kie.internal.task.api.model.FaultData 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 4 with FaultData

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

the class TaskInstanceServiceImpl method deleteFault.

public void deleteFault(long taskId, String userId) {
    Task task = persistenceContext.findTask(taskId);
    long contentId = task.getTaskData().getFaultContentId();
    Content content = persistenceContext.findContent(contentId);
    FaultData data = TaskModelProvider.getFactory().newFaultData();
    persistenceContext.removeContent(content);
    persistenceContext.setFaultToTask(null, data, task);
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) FaultData(org.kie.internal.task.api.model.FaultData) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent)

Aggregations

FaultData (org.kie.internal.task.api.model.FaultData)4 Content (org.kie.api.task.model.Content)3 Task (org.kie.api.task.model.Task)3 InternalContent (org.kie.internal.task.api.model.InternalContent)2 InternalTask (org.kie.internal.task.api.model.InternalTask)2 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)1 JaxbContent (org.jbpm.services.task.impl.model.xml.JaxbContent)1 Test (org.junit.Test)1 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)1 User (org.kie.api.task.model.User)1