Search in sources :

Example 21 with InternalContent

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

the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskExited.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskExited() 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.exit(taskId, "Administrator");
    // 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.Exited, 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 22 with InternalContent

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

the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskSkipped.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskSkipped() 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.skip(taskId, "Administrator");
    // 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.Obsolete, 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 23 with InternalContent

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

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

the class TaskContentServiceImpl method addOutputContent.

@SuppressWarnings("unchecked")
public long addOutputContent(long taskId, Map<String, Object> params) {
    Task task = persistenceContext.findTask(taskId);
    loadTaskVariables(task);
    long outputContentId = task.getTaskData().getOutputContentId();
    Content outputContent = persistenceContext.findContent(outputContentId);
    Map<String, Object> initialContent = new HashMap<>();
    long contentId = -1;
    if (outputContent == null) {
        ContentMarshallerContext context = getMarshallerContext(task);
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, params, context.getEnvironment());
        Content content = TaskModelProvider.getFactory().newContent();
        ((InternalContent) content).setContent(outputContentData.getContent());
        persistenceContext.persistContent(content);
        persistenceContext.setOutputToTask(content, outputContentData, task);
        contentId = content.getId();
    } else {
        // I need to merge it if it already exist
        ContentMarshallerContext context = getMarshallerContext(task);
        Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), context.getEnvironment(), context.getClassloader());
        if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
            // set initial content before updating with this params
            initialContent.putAll((Map<String, Object>) unmarshalledObject);
            ((Map<String, Object>) unmarshalledObject).putAll(params);
        }
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, context.getEnvironment());
        ((InternalContent) outputContent).setContent(outputContentData.getContent());
        persistenceContext.persistContent(outputContent);
        contentId = outputContentId;
    }
    taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, context, initialContent);
    ((InternalTaskData) task.getTaskData()).setTaskOutputVariables(params);
    taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, params);
    persistenceContext.updateTask(task);
    return contentId;
}
Also used : Task(org.kie.api.task.model.Task) ContentData(org.kie.internal.task.api.model.ContentData) HashMap(java.util.HashMap) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) InternalContent(org.kie.internal.task.api.model.InternalContent) HashMap(java.util.HashMap) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 25 with InternalContent

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

the class AddTaskInputsCommand method execute.

@SuppressWarnings("unchecked")
@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskEventSupport taskEventSupport = context.getTaskEventSupport();
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    Task task = persistenceContext.findTask(taskId);
    // security check
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    long inputContentId = task.getTaskData().getDocumentContentId();
    Content outputContent = persistenceContext.findContent(inputContentId);
    Map<String, Object> initialContent = new HashMap<String, Object>();
    Map<String, Object> mergedContent = values;
    if (outputContent == null) {
        ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, values, mcontext.getEnvironment());
        Content content = TaskModelProvider.getFactory().newContent();
        ((InternalContent) content).setContent(outputContentData.getContent());
        persistenceContext.persistContent(content);
        ((InternalTaskData) task.getTaskData()).setOutput(content.getId(), outputContentData);
    } else {
        ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
        Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
        if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
            // set initial content with data from storage before being altered by this values
            initialContent.putAll((Map<String, Object>) unmarshalledObject);
            ((Map<String, Object>) unmarshalledObject).putAll(values);
            mergedContent = ((Map<String, Object>) unmarshalledObject);
        }
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
        ((InternalContent) outputContent).setContent(outputContentData.getContent());
        persistenceContext.persistContent(outputContent);
    }
    taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, initialContent);
    ((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
    taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, mergedContent);
    return null;
}
Also used : Task(org.kie.api.task.model.Task) TaskContext(org.jbpm.services.task.commands.TaskContext) HashMap(java.util.HashMap) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) InternalContent(org.kie.internal.task.api.model.InternalContent) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) ContentData(org.kie.internal.task.api.model.ContentData) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport) HashMap(java.util.HashMap) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Aggregations

InternalContent (org.kie.internal.task.api.model.InternalContent)25 ContentData (org.kie.internal.task.api.model.ContentData)20 InternalTask (org.kie.internal.task.api.model.InternalTask)17 Test (org.junit.Test)15 InputStreamReader (java.io.InputStreamReader)14 Reader (java.io.Reader)14 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)14 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)14 Task (org.kie.api.task.model.Task)13 Content (org.kie.api.task.model.Content)11 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)11 User (org.kie.api.task.model.User)11 HashMap (java.util.HashMap)10 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)10 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)10 Date (java.util.Date)8 ArrayList (java.util.ArrayList)7 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)5 Map (java.util.Map)4 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)4