Search in sources :

Example 21 with I18NText

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

the class UserTaskServiceImpl method setDescription.

@Override
public void setDescription(String deploymentId, Long taskId, String description) {
    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 {
        InternalI18NText text = (InternalI18NText) TaskModelProvider.getFactory().newI18NText();
        text.setLanguage("en-UK");
        text.setText(description);
        List<I18NText> names = new ArrayList<I18NText>();
        names.add(text);
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        ((InternalTaskService) taskService).setDescriptions(taskId, names);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) 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) ArrayList(java.util.ArrayList) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 22 with I18NText

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

the class AbstractTaskSerializationTest method jaxbTaskTest.

// TESTS ----------------------------------------------------------------------------------------------------------------------
@Test
public void jaxbTaskTest() throws Exception {
    // Yaml serialization requires major changes in order to be supported.. :/
    Assume.assumeTrue(!getType().equals(TestType.YAML));
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    InputStream stream = getClass().getResourceAsStream(MvelFilePath.FullTask);
    assertNotNull("Could not load file: " + MvelFilePath.FullTask, stream);
    Reader reader = new InputStreamReader(stream);
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    // fill task
    task.setFormName("Bruno's Form");
    task.setId(23L);
    task.setSubTaskStrategy(SubTasksStrategy.EndParentOnAllSubTasksEnd);
    for (I18NText text : task.getNames()) {
        ((InternalI18NText) text).setId((long) random.nextInt(1000));
    }
    for (I18NText text : task.getSubjects()) {
        ((InternalI18NText) text).setId((long) random.nextInt(1000));
    }
    for (I18NText text : task.getDescriptions()) {
        ((InternalI18NText) text).setId((long) random.nextInt(1000));
    }
    // fill task -> task data
    InternalTaskData taskData = (InternalTaskData) task.getTaskData();
    taskData.setOutputAccessType(AccessType.Inline);
    taskData.setFaultAccessType(AccessType.Unknown);
    taskData.setTaskInputVariables(new HashMap<String, Object>());
    taskData.setTaskOutputVariables(new HashMap<String, Object>());
    // fill task -> task data -> comment
    String payload = "brainwashArmitageRecruitCaseGetPasswordFromLady3JaneAscentToStraylightIcebreakerUniteWithNeuromancer";
    InternalComment comment = (InternalComment) TaskModelProvider.getFactory().newComment();
    comment.setId(42);
    comment.setText(payload);
    comment.setAddedAt(new Date());
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Case");
    comment.setAddedBy(user);
    taskData.addComment(comment);
    // fill task -> task data -> attachment
    InternalAttachment attach = (InternalAttachment) TaskModelProvider.getFactory().newAttachment();
    attach.setId(10);
    attach.setName("virus");
    attach.setContentType("ROM");
    attach.setAttachedAt(new Date());
    user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Wintermute");
    attach.setAttachedBy(user);
    attach.setSize(payload.getBytes().length);
    attach.setAttachmentContentId(comment.getId());
    taskData.addAttachment(attach);
    JaxbTask xmlTask = new JaxbTask(task);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask, InternalTask.class);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData(), TaskData.class);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData().getAttachments().get(0), Attachment.class);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData().getComments().get(0), Comment.class);
    assertNotNull(xmlTask.getNames());
    assertTrue(xmlTask.getNames().size() > 0);
    JaxbTask bornAgainTask = testRoundTrip(xmlTask);
    assertNotNull(bornAgainTask.getNames());
    assertTrue("Round-tripped task has empty 'names' list!", !bornAgainTask.getNames().isEmpty());
    Assertions.assertThat(xmlTask).isEqualToComparingFieldByFieldRecursively(bornAgainTask);
    assertNotNull(((InternalTask) xmlTask).getFormName());
    assertEquals(((InternalTask) xmlTask).getFormName(), ((InternalTask) bornAgainTask).getFormName());
    Task realTask = xmlTask.getTask();
    verifyThatXmlFieldsAreFilled(realTask, xmlTask, InternalTask.class, "deadlines");
    verifyThatXmlFieldsAreFilled(realTask.getTaskData(), xmlTask.getTaskData(), TaskData.class, "taskInputVariables", "taskOutputVariables");
}
Also used : I18NText(org.kie.api.task.model.I18NText) JaxbI18NText(org.jbpm.services.task.impl.model.xml.JaxbI18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) JaxbTask(org.jbpm.services.task.impl.model.xml.JaxbTask) User(org.kie.api.task.model.User) JaxbTask(org.jbpm.services.task.impl.model.xml.JaxbTask) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InputStream(java.io.InputStream) InternalComment(org.kie.internal.task.api.model.InternalComment) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) Test(org.junit.Test)

Example 23 with I18NText

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

the class JaxbTaskSerializationTest method setTaskPropertyCommandTest.

@Test
public void setTaskPropertyCommandTest() throws Exception {
    SetTaskPropertyCommand cmd;
    int taskId = 1;
    String userId = "user";
    FaultDataImpl faultData = new FaultDataImpl();
    faultData.setAccessType(AccessType.Inline);
    faultData.setContent("skinned shins".getBytes());
    faultData.setFaultName("Whoops!");
    faultData.setType("skates");
    List<I18NText> textList = new ArrayList<I18NText>();
    I18NText text = new I18NTextImpl("nl-NL", "Stroopwafel!");
    textList.add(text);
    Object[][] testData = { { FAULT_PROPERTY, faultData }, { OUTPUT_PROPERTY, new Object() }, { PRIORITY_PROPERTY, 23 }, { TASK_NAMES_PROPERTY, textList }, { EXPIRATION_DATE_PROPERTY, new Date() }, { DESCRIPTION_PROPERTY, new ArrayList<I18NText>() }, { SKIPPABLE_PROPERTY, false }, { SUB_TASK_STRATEGY_PROPERTY, SubTasksStrategy.EndParentOnAllSubTasksEnd } };
    TaskContext mockContext = mock(TaskContext.class);
    TaskInstanceService mockTaskService = mock(TaskInstanceService.class);
    UserGroupCallback mockUserGroupCallback = mock(UserGroupCallback.class);
    when(mockContext.getTaskInstanceService()).thenReturn(mockTaskService);
    when(mockContext.getUserGroupCallback()).thenReturn(mockUserGroupCallback);
    when(mockUserGroupCallback.existsUser(anyString())).thenReturn(false);
    for (Object[] data : testData) {
        int property = (Integer) data[0];
        cmd = new SetTaskPropertyCommand(taskId, userId, property, data[1]);
        try {
            cmd.execute(mockContext);
        } catch (IllegalArgumentException e) {
            // expected for fault and output
            assertTrue(e.getMessage().startsWith("User user was not found in callback "));
        }
    }
}
Also used : I18NText(org.kie.api.task.model.I18NText) TaskContext(org.jbpm.services.task.commands.TaskContext) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) UserGroupCallback(org.kie.internal.task.api.UserGroupCallback) Date(java.util.Date) FaultDataImpl(org.jbpm.services.task.impl.model.FaultDataImpl) TaskInstanceService(org.kie.internal.task.api.TaskInstanceService) SetTaskPropertyCommand(org.jbpm.services.task.commands.SetTaskPropertyCommand) I18NTextImpl(org.jbpm.services.task.impl.model.I18NTextImpl) Test(org.junit.Test)

Example 24 with I18NText

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

the class CollectionUtils method readI18NTextList.

public static List<I18NText> readI18NTextList(ObjectInput in) throws IOException, ClassNotFoundException {
    int size = in.readInt();
    List<I18NText> list = new ArrayList<I18NText>(size);
    for (int i = 0; i < size; i++) {
        I18NText item = new I18NTextImpl();
        item.readExternal(in);
        list.add(item);
    }
    return list;
}
Also used : I18NText(org.kie.api.task.model.I18NText) I18NTextImpl(org.jbpm.services.task.impl.model.I18NTextImpl) ArrayList(java.util.ArrayList)

Aggregations

I18NText (org.kie.api.task.model.I18NText)24 ArrayList (java.util.ArrayList)22 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)19 Task (org.kie.api.task.model.Task)8 InternalTask (org.kie.internal.task.api.model.InternalTask)8 Test (org.junit.Test)6 I18NTextImpl (org.jbpm.services.task.impl.model.I18NTextImpl)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)4 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)4 User (org.kie.api.task.model.User)4 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)4 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)4 StringReader (java.io.StringReader)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 JaxbI18NText (org.jbpm.services.task.impl.model.xml.JaxbI18NText)3 InternalTaskService (org.kie.internal.task.api.InternalTaskService)3 UserTaskService (org.jbpm.services.api.UserTaskService)2 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)2 TaskFluent (org.jbpm.services.task.utils.TaskFluent)2