Search in sources :

Example 36 with InternalTaskService

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

the class UserTaskServiceImpl method getAttachmentContentById.

@Override
public Object getAttachmentContentById(String deploymentId, Long taskId, Long attachmentId) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return null;
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        // perform actual operation
        TaskService taskService = engine.getTaskService();
        Attachment attachment = ((InternalTaskService) taskService).getAttachmentById(attachmentId);
        long documentContentId = attachment.getAttachmentContentId();
        if (documentContentId > 0) {
            Content contentById = taskService.getContentById(documentContentId);
            if (contentById == null) {
                return null;
            }
            ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task.getDeploymentId());
            Object unmarshall = ContentMarshallerHelper.unmarshall(contentById.getContent(), ctx.getEnvironment(), ctx.getClassloader());
            return unmarshall;
        }
        return null;
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) Content(org.kie.api.task.model.Content) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) Attachment(org.kie.api.task.model.Attachment) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 37 with InternalTaskService

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

the class UserTaskServiceImpl method getAttachmentById.

@Override
public Attachment getAttachmentById(String deploymentId, Long taskId, Long attachmentId) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return null;
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        return ((InternalTaskService) taskService).getAttachmentById(attachmentId);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 38 with InternalTaskService

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

the class UserTaskServiceImpl method addAttachment.

@Override
public Long addAttachment(String deploymentId, Long taskId, String userId, String name, Object attachment) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return null;
    }
    if (manager instanceof InternalRuntimeManager) {
        attachment = process(attachment, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        InternalAttachment att = (InternalAttachment) TaskModelProvider.getFactory().newAttachment();
        att.setName(name);
        att.setAccessType(AccessType.Inline);
        att.setAttachedAt(new Date());
        att.setAttachedBy(TaskModelProvider.getFactory().newUser(userId));
        att.setContentType(attachment.getClass().getName());
        return ((InternalTaskService) taskService).execute(new AddAttachmentCommand(taskId, att, attachment));
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) AddAttachmentCommand(org.jbpm.services.task.commands.AddAttachmentCommand) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) Date(java.util.Date)

Example 39 with InternalTaskService

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

the class UserTaskServiceImpl method getTask.

@Override
public Task getTask(String deploymentId, Long taskId) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return null;
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        return ((InternalTaskService) taskService).getTaskById(taskId);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 40 with InternalTaskService

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

the class UserTaskServiceImpl method deleteComment.

@Override
public void deleteComment(String deploymentId, Long taskId, Long commentId) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return;
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        ((InternalTaskService) taskService).deleteComment(taskId, commentId);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Aggregations

InternalTaskService (org.kie.internal.task.api.InternalTaskService)44 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)35 TaskService (org.kie.api.task.TaskService)27 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)25 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)20 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)18 UserTaskService (org.jbpm.services.api.UserTaskService)17 TaskSummary (org.kie.api.task.model.TaskSummary)13 Test (org.junit.Test)12 KieSession (org.kie.api.runtime.KieSession)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)9 Task (org.kie.api.task.model.Task)5 TaskCleanUpProcessEventListener (org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener)4 AuditService (org.kie.api.runtime.manager.audit.AuditService)4 I18NText (org.kie.api.task.model.I18NText)4 Date (java.util.Date)3 EntityManager (javax.persistence.EntityManager)3 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)3