Search in sources :

Example 6 with Content

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

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

the class ParentChildMarshallingJpaTest method testProcess.

@Test
public void testProcess() throws Exception {
    emfDomain = Persistence.createEntityManagerFactory("org.jbpm.persistence.parent-child");
    addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new JPAPlaceholderResolverStrategy(emfDomain), new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
    RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "manager", "org/jbpm/test/functional/jpa/parent-child.bpmn");
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    // start a new process instance
    Map<String, Object> params = new HashMap<String, Object>();
    Application application = new Application();
    application.setType("A");
    params.put("application", application);
    ProcessInstance pi = ksession.startProcess("com.sample.bpmn.hello", params);
    System.out.println("A process instance started : pid = " + pi.getId());
    TaskService taskService = runtime.getTaskService();
    assertTrue(taskService instanceof CommandBasedTaskService);
    assertTrue(((CommandBasedTaskService) taskService).getEnvironment().get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES) != null);
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    for (TaskSummary taskSummary : list) {
        System.out.println("john starts a task : taskId = " + taskSummary.getId());
        Task task = taskService.getTaskById(taskSummary.getId());
        long documentContentId = task.getTaskData().getDocumentContentId();
        Content content = taskService.getContentById(documentContentId);
        HashMap<String, Object> contents = (HashMap<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), ksession.getEnvironment());
        Application outputApplication = (Application) contents.get("input1_application");
        Person person = new Person();
        person.setFullName("John Doe");
        outputApplication.setPerson(person);
        Map<String, Object> results = new LinkedHashMap<String, Object>();
        results.put("output1_application", outputApplication);
        taskService.start(taskSummary.getId(), "john");
        taskService.complete(taskSummary.getId(), "john", results);
    }
    list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    for (TaskSummary taskSummary : list) {
        System.out.println("mary starts a task : taskId = " + taskSummary.getId());
        taskService.start(taskSummary.getId(), "mary");
        taskService.complete(taskSummary.getId(), "mary", null);
    }
    manager.disposeRuntimeEngine(runtime);
    // Check!
    EntityManager em = emfDomain.createEntityManager();
    int size = em.createQuery("select i from Person i").getResultList().size();
    assertEquals(1, size);
}
Also used : SerializablePlaceholderResolverStrategy(org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy) JPAPlaceholderResolverStrategy(org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Task(org.kie.api.task.model.Task) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TaskService(org.kie.api.task.TaskService) CommandBasedTaskService(org.jbpm.services.task.impl.command.CommandBasedTaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) CommandBasedTaskService(org.jbpm.services.task.impl.command.CommandBasedTaskService) LinkedHashMap(java.util.LinkedHashMap) EntityManager(javax.persistence.EntityManager) Content(org.kie.api.task.model.Content) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Application(org.jbpm.test.entity.Application) Person(org.jbpm.test.entity.Person) Test(org.junit.Test)

Example 8 with Content

use of org.kie.api.task.model.Content 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)

Example 9 with Content

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

the class TaskInstanceServiceImpl method addTask.

public long addTask(Task task, Map<String, Object> params) {
    taskEventSupport.fireBeforeTaskAdded(task, context);
    persistenceContext.persistTask(task);
    resolveTaskDetailsForTaskProperties(task);
    if (params != null) {
        taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, Collections.emptyMap());
        resolveTaskDetails(params, task);
        ContentData contentData = ContentMarshallerHelper.marshal(task, params, TaskContentRegistry.get().getMarshallerContext(task).getEnvironment());
        Content content = TaskModelProvider.getFactory().newContent();
        ((InternalContent) content).setContent(contentData.getContent());
        persistenceContext.persistContent(content);
        persistenceContext.setDocumentToTask(content, contentData, task);
        taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, params);
    }
    taskEventSupport.fireAfterTaskAdded(task, context);
    return task.getId();
}
Also used : ContentData(org.kie.internal.task.api.model.ContentData) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalContent(org.kie.internal.task.api.model.InternalContent)

Example 10 with Content

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

the class TaskInstanceServiceImpl method getContentMapForUser.

@Override
public Map<String, Object> getContentMapForUser(Long taskId, String userId) {
    // check permissions
    this.lifeCycleManager.taskOperation(Operation.View, taskId, userId, null, null, toGroups(null));
    Task task = this.persistenceContext.findTask(taskId);
    if (task.getTaskData() != null && task.getTaskData().getOutputContentId() != null) {
        Content content = this.persistenceContext.findContent(task.getTaskData().getOutputContentId());
        ContentMarshallerContext mContext = TaskContentRegistry.get().getMarshallerContext(task);
        Object outputContent = ContentMarshallerHelper.unmarshall(content.getContent(), mContext.getEnvironment(), mContext.getClassloader());
        if (outputContent instanceof Map) {
            return (Map<String, Object>) outputContent;
        } else {
            throw new IllegalStateException("Output content for task " + taskId + " is not a Map<String, Object>!");
        }
    }
    return null;
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) HashMap(java.util.HashMap) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Aggregations

Content (org.kie.api.task.model.Content)40 Task (org.kie.api.task.model.Task)32 HashMap (java.util.HashMap)23 Map (java.util.Map)21 InternalContent (org.kie.internal.task.api.model.InternalContent)17 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)15 InternalTask (org.kie.internal.task.api.model.InternalTask)14 ContentData (org.kie.internal.task.api.model.ContentData)11 Test (org.junit.Test)10 JaxbContent (org.jbpm.services.task.impl.model.xml.JaxbContent)9 StringReader (java.io.StringReader)8 TaskService (org.kie.api.task.TaskService)6 TaskSummary (org.kie.api.task.model.TaskSummary)6 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)6 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 InternalTaskService (org.kie.internal.task.api.InternalTaskService)5 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)4 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)4 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)4 Attachment (org.kie.api.task.model.Attachment)4