Search in sources :

Example 6 with Attachment

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

the class TaskAttachmentBaseTest method testAttachmentWithStringInlineContent.

@Test
public void testAttachmentWithStringInlineContent() {
    // 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() ) { businessAdministrators = [new User('Bobba Fet')], }),";
    str += "name =  'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> tasks = taskService.getTasksAssignedAsBusinessAdministrator("Bobba Fet", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary taskSum = tasks.get(0);
    Attachment attach = TaskModelProvider.getFactory().newAttachment();
    ((InternalAttachment) attach).setAccessType(AccessType.Inline);
    ((InternalAttachment) attach).setAttachedAt(new Date());
    ((InternalAttachment) attach).setName("My first doc");
    ((InternalAttachment) attach).setContentType("String");
    Content content = TaskModelProvider.getFactory().newContent();
    ((InternalContent) content).setContent(ContentMarshallerHelper.marshallContent(task, "This is my first inline document", null));
    long attachId = taskService.addAttachment(taskSum.getId(), attach, content);
    Assert.assertNotEquals(0, attachId);
    Attachment attachmentById = taskService.getAttachmentById(attachId);
    Assert.assertNotNull(attachmentById);
    Attachment attach2 = TaskModelProvider.getFactory().newAttachment();
    ((InternalAttachment) attach2).setAccessType(AccessType.Inline);
    ((InternalAttachment) attach2).setAttachedAt(new Date());
    ((InternalAttachment) attach2).setName("My second doc");
    ((InternalAttachment) attach2).setContentType("String");
    Content content2 = TaskModelProvider.getFactory().newContent();
    ((InternalContent) content2).setContent(ContentMarshallerHelper.marshallContent(task, "This is my second inline document", null));
    attachId = taskService.addAttachment(taskSum.getId(), attach2, content2);
    Assert.assertNotEquals(0, attachId);
    attachmentById = taskService.getAttachmentById(attachId);
    Assert.assertNotNull(attachmentById);
    List<Attachment> allAttachmentsByTaskId = taskService.getAllAttachmentsByTaskId(taskSum.getId());
    assertEquals(2, allAttachmentsByTaskId.size());
    Attachment firstAttach = allAttachmentsByTaskId.get(0);
    long firstAttachContentId = firstAttach.getAttachmentContentId();
    Content firstAttachContent = taskService.getContentById(firstAttachContentId);
    String firstDocString = (String) ContentMarshallerHelper.unmarshall(firstAttachContent.getContent(), null);
    assertEquals("This is my first inline document", firstDocString);
    Attachment secondAttach = allAttachmentsByTaskId.get(1);
    long secondAttachContentId = secondAttach.getAttachmentContentId();
    Content secondAttachContent = taskService.getContentById(secondAttachContentId);
    String secondDocString = (String) ContentMarshallerHelper.unmarshall(secondAttachContent.getContent(), null);
    assertEquals("This is my second inline document", secondDocString);
}
Also used : Task(org.kie.api.task.model.Task) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) Attachment(org.kie.api.task.model.Attachment) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalContent(org.kie.internal.task.api.model.InternalContent) Date(java.util.Date) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) Test(org.junit.Test)

Example 7 with Attachment

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

the class TaskAttachmentServiceImpl method deleteAttachment.

public void deleteAttachment(long taskId, long attachmentId) {
    Task task = persistenceContext.findTask(taskId);
    Attachment attachment = persistenceContext.removeAttachmentFromTask(task, attachmentId);
    Content content = persistenceContext.findContent(attachment.getAttachmentContentId());
    persistenceContext.removeContent(content);
}
Also used : Task(org.kie.api.task.model.Task) Content(org.kie.api.task.model.Content) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) Attachment(org.kie.api.task.model.Attachment)

Example 8 with Attachment

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

the class JPATaskPersistenceContext method removeAttachmentFromTask.

@Override
public Attachment removeAttachmentFromTask(Task task, long attachmentId) {
    Attachment removed = ((InternalTaskData) task.getTaskData()).removeAttachment(attachmentId);
    EventManagerProvider.getInstance().get().update(new TaskInstanceView(task));
    return removed;
}
Also used : TaskInstanceView(org.jbpm.persistence.api.integration.model.TaskInstanceView) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Attachment(org.kie.api.task.model.Attachment)

Example 9 with Attachment

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

the class JaxbTask method getTask.

/**
 * This is a convienence method that retrieves a TaskImpl instance. It's used
 * internally in the {@link AddTaskCommand#execute(org.kie.internal.command.Context)} method
 * because that command requires a persistable task representation.
 * </p>
 * Users who are looking for information from the task should <i>not</i> use this method:
 * all of the task information is already available via the normal methods
 * defined by the {@link Task} or {@link InternalTask} interfaces, both of which this class
 * implements: for example: {@link JaxbTask#getId()}, {@link JaxbTask#getTaskData()}
 * or {@link JaxbTask#getPeopleAssignments()}.
 * @return a TaskImpl instance
 */
public Task getTask() {
    InternalTask taskImpl = (InternalTask) TaskModelProvider.getFactory().newTask();
    if (this.getId() != null) {
        taskImpl.setId(this.getId());
    }
    if (this.priority != null) {
        taskImpl.setPriority(this.getPriority());
    }
    JaxbPeopleAssignments jaxbPeopleAssignments = this.peopleAssignments;
    InternalPeopleAssignments peopleAssignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    if (jaxbPeopleAssignments.getTaskInitiator() != null) {
        User user = createUser(this.getPeopleAssignments().getTaskInitiator().getId());
        peopleAssignments.setTaskInitiator(user);
    }
    List<OrganizationalEntity> potentialOwners = copyOrganizationalEntityList(jaxbPeopleAssignments.getPotentialOwners());
    peopleAssignments.setPotentialOwners(potentialOwners);
    List<OrganizationalEntity> businessAdmins = copyOrganizationalEntityList(jaxbPeopleAssignments.getBusinessAdministrators());
    peopleAssignments.setBusinessAdministrators(businessAdmins);
    List<OrganizationalEntity> exclOwners = copyOrganizationalEntityList(jaxbPeopleAssignments.getExcludedOwners());
    peopleAssignments.setExcludedOwners(exclOwners);
    List<OrganizationalEntity> taskStake = copyOrganizationalEntityList(jaxbPeopleAssignments.getTaskStakeholders());
    peopleAssignments.setTaskStakeholders(taskStake);
    List<OrganizationalEntity> recipients = copyOrganizationalEntityList(jaxbPeopleAssignments.getRecipients());
    peopleAssignments.setRecipients(recipients);
    taskImpl.setPeopleAssignments(peopleAssignments);
    taskImpl.setSubTaskStrategy(this.getSubTaskStrategy());
    {
        List<I18NText> names = new ArrayList<I18NText>();
        for (I18NText n : this.getNames()) {
            I18NText text = TaskModelProvider.getFactory().newI18NText();
            ((InternalI18NText) text).setId(n.getId());
            ((InternalI18NText) text).setLanguage(n.getLanguage());
            ((InternalI18NText) text).setText(n.getText());
            names.add(text);
        }
        taskImpl.setNames(names);
    }
    if (this.getName() != null) {
        taskImpl.setName(this.getName());
    } else if (!this.getNames().isEmpty()) {
        taskImpl.setName(this.getNames().get(0).getText());
    }
    {
        List<I18NText> subjects = new ArrayList<I18NText>();
        for (I18NText s : this.getSubjects()) {
            I18NText text = TaskModelProvider.getFactory().newI18NText();
            ((InternalI18NText) text).setId(s.getId());
            ((InternalI18NText) text).setLanguage(s.getLanguage());
            ((InternalI18NText) text).setText(s.getText());
            subjects.add(text);
        }
        taskImpl.setSubjects(subjects);
    }
    if (this.getSubject() != null) {
        taskImpl.setSubject(this.getSubject());
    } else if (!this.getSubjects().isEmpty()) {
        taskImpl.setSubject(this.getSubjects().get(0).getText());
    }
    {
        List<I18NText> descriptions = new ArrayList<I18NText>();
        for (I18NText d : this.getDescriptions()) {
            I18NText text = TaskModelProvider.getFactory().newI18NText();
            ((InternalI18NText) text).setId(d.getId());
            ((InternalI18NText) text).setLanguage(d.getLanguage());
            ((InternalI18NText) text).setText(d.getText());
            descriptions.add(text);
        }
        taskImpl.setDescriptions(descriptions);
    }
    if (this.getDescription() != null) {
        taskImpl.setDescription(this.getDescription());
    } else if (!this.getDescriptions().isEmpty()) {
        taskImpl.setDescription(this.getDescriptions().get(0).getText());
    }
    taskImpl.setTaskType(this.getTaskType());
    taskImpl.setFormName(this.getFormName());
    // task data
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    JaxbTaskData jaxbTaskData = (JaxbTaskData) this.getTaskData();
    taskData.setStatus(jaxbTaskData.getStatus());
    taskData.setPreviousStatus(jaxbTaskData.getPreviousStatus());
    taskData.setActualOwner(createUser(jaxbTaskData.getActualOwnerId()));
    taskData.setCreatedBy(createUser(jaxbTaskData.getCreatedById()));
    taskData.setCreatedOn(jaxbTaskData.getCreatedOn());
    taskData.setActivationTime(jaxbTaskData.getActivationTime());
    taskData.setExpirationTime(jaxbTaskData.getExpirationTime());
    taskData.setSkipable(jaxbTaskData.isSkipable());
    taskData.setWorkItemId(jaxbTaskData.getWorkItemId());
    taskData.setProcessInstanceId(jaxbTaskData.getProcessInstanceId());
    taskData.setDocumentContentId(jaxbTaskData.getDocumentContentId());
    taskData.setDocumentAccessType(jaxbTaskData.getDocumentAccessType());
    taskData.setDocumentType(jaxbTaskData.getDocumentType());
    taskData.setOutputAccessType(jaxbTaskData.getOutputAccessType());
    taskData.setOutputType(jaxbTaskData.getOutputType());
    taskData.setOutputContentId(jaxbTaskData.getOutputContentId());
    taskData.setFaultName(jaxbTaskData.getFaultName());
    taskData.setFaultAccessType(jaxbTaskData.getFaultAccessType());
    taskData.setFaultType(jaxbTaskData.getFaultType());
    taskData.setFaultContentId(jaxbTaskData.getFaultContentId());
    taskData.setParentId(jaxbTaskData.getParentId());
    taskData.setProcessId(jaxbTaskData.getProcessId());
    taskData.setProcessSessionId(jaxbTaskData.getProcessSessionId());
    List<Comment> jaxbComments = jaxbTaskData.getComments();
    if (jaxbComments != null) {
        List<Comment> comments = new ArrayList<Comment>(jaxbComments.size());
        for (Comment jaxbComment : jaxbComments) {
            InternalComment comment = (InternalComment) TaskModelProvider.getFactory().newComment();
            if (jaxbComment.getId() != null) {
                comment.setId(jaxbComment.getId());
            }
            comment.setAddedAt(jaxbComment.getAddedAt());
            comment.setAddedBy(createUser(((JaxbComment) jaxbComment).getAddedById()));
            comment.setText(jaxbComment.getText());
            comments.add(comment);
        }
        taskData.setComments(comments);
    }
    List<Attachment> jaxbAttachments = jaxbTaskData.getAttachments();
    if (jaxbAttachments != null) {
        List<Attachment> attachments = new ArrayList<Attachment>(jaxbAttachments.size());
        for (Attachment jaxbAttach : jaxbAttachments) {
            InternalAttachment attach = (InternalAttachment) TaskModelProvider.getFactory().newAttachment();
            if (jaxbAttach.getId() != null) {
                attach.setId(jaxbAttach.getId());
            }
            attach.setName(jaxbAttach.getName());
            attach.setContentType(jaxbAttach.getContentType());
            attach.setAttachedAt(jaxbAttach.getAttachedAt());
            attach.setAttachedBy(createUser(((JaxbAttachment) jaxbAttach).getAttachedById()));
            attach.setSize(jaxbAttach.getSize());
            attach.setAttachmentContentId(jaxbAttach.getAttachmentContentId());
            attachments.add(attach);
        }
        taskData.setAttachments(attachments);
    }
    taskData.setDeploymentId(jaxbTaskData.getDeploymentId());
    ((InternalTask) taskImpl).setTaskData(taskData);
    return taskImpl;
}
Also used : InternalComment(org.kie.internal.task.api.model.InternalComment) Comment(org.kie.api.task.model.Comment) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalComment(org.kie.internal.task.api.model.InternalComment) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) Attachment(org.kie.api.task.model.Attachment) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with Attachment

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

the class UserTaskServiceImplTest method testAttachmentOperations.

@Test
public void testAttachmentOperations() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    List<Long> taskIds = runtimeDataService.getTasksByProcessInstanceId(processInstanceId);
    assertNotNull(taskIds);
    assertEquals(1, taskIds.size());
    Long taskId = taskIds.get(0);
    List<Attachment> attachments = userTaskService.getAttachmentsByTaskId(taskId);
    assertNotNull(attachments);
    assertEquals(0, attachments.size());
    Long attId = userTaskService.addAttachment(taskId, "john", "my attachment", "String attachment");
    assertNotNull(attId);
    attachments = userTaskService.getAttachmentsByTaskId(taskId);
    assertNotNull(attachments);
    assertEquals(1, attachments.size());
    String content = (String) userTaskService.getAttachmentContentById(taskId, attId);
    assertNotNull(content);
    assertEquals("String attachment", content);
    Attachment attachment = userTaskService.getAttachmentById(taskId, attId);
    assertNotNull(attachment);
    assertEquals("john", attachment.getAttachedBy().getId());
    assertEquals("my attachment", attachment.getName());
    assertNotNull(attachment.getAttachmentContentId());
    assertEquals("java.lang.String", attachment.getContentType());
    userTaskService.deleteAttachment(taskId, attId);
    attachments = userTaskService.getAttachmentsByTaskId(taskId);
    assertNotNull(attachments);
    assertEquals(0, attachments.size());
}
Also used : Attachment(org.kie.api.task.model.Attachment) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

Attachment (org.kie.api.task.model.Attachment)12 Test (org.junit.Test)5 InternalAttachment (org.kie.internal.task.api.model.InternalAttachment)5 Content (org.kie.api.task.model.Content)4 Task (org.kie.api.task.model.Task)3 TaskSummary (org.kie.api.task.model.TaskSummary)3 ArrayList (java.util.ArrayList)2 RemoteEjbTest (org.jbpm.remote.ejb.test.RemoteEjbTest)2 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)2 InternalContent (org.kie.internal.task.api.model.InternalContent)2 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)2 StringReader (java.io.StringReader)1 Date (java.util.Date)1 List (java.util.List)1 Person (org.jboss.qa.bpms.remote.ejb.domain.Person)1 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)1 TaskInstanceView (org.jbpm.persistence.api.integration.model.TaskInstanceView)1 UserTaskService (org.jbpm.services.api.UserTaskService)1 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)1 AttachmentImpl (org.jbpm.services.task.impl.model.AttachmentImpl)1