Search in sources :

Example 1 with CompositeCommand

use of org.jbpm.services.task.commands.CompositeCommand in project jbpm by kiegroup.

the class AbstractTaskSerializationTest method taskCompositeCommandCanBeSerialized.

@Test
public void taskCompositeCommandCanBeSerialized() throws Exception {
    Assume.assumeTrue(TestType.JAXB.equals(getType()));
    addClassesToSerializationContext(CompositeCommand.class);
    addClassesToSerializationContext(StartTaskCommand.class);
    addClassesToSerializationContext(CancelDeadlineCommand.class);
    CompositeCommand<Void> cmd = new CompositeCommand<Void>(new StartTaskCommand(1, "john"), new CancelDeadlineCommand(1, true, false));
    CompositeCommand<?> returned = testRoundTrip(cmd);
    assertNotNull(returned);
    assertNotNull(returned.getMainCommand());
    assertTrue(returned.getMainCommand() instanceof StartTaskCommand);
    assertEquals(Long.valueOf(1), returned.getTaskId());
    assertNotNull(returned.getCommands());
    assertEquals(1, returned.getCommands().size());
}
Also used : StartTaskCommand(org.jbpm.services.task.commands.StartTaskCommand) CancelDeadlineCommand(org.jbpm.services.task.commands.CancelDeadlineCommand) CompositeCommand(org.jbpm.services.task.commands.CompositeCommand) Test(org.junit.Test)

Example 2 with CompositeCommand

use of org.jbpm.services.task.commands.CompositeCommand in project jbpm by kiegroup.

the class AbstractTaskSerializationTest method taskCompositeCommandMultipleCanBeSerialized.

@Test
public void taskCompositeCommandMultipleCanBeSerialized() throws Exception {
    Assume.assumeTrue(TestType.JAXB.equals(getType()));
    addClassesToSerializationContext(CompositeCommand.class);
    addClassesToSerializationContext(SkipTaskCommand.class);
    addClassesToSerializationContext(ProcessSubTaskCommand.class);
    addClassesToSerializationContext(CancelDeadlineCommand.class);
    CompositeCommand<Void> cmd = new CompositeCommand<Void>(new SkipTaskCommand(1, "john"), new ProcessSubTaskCommand(1, "john"), new CancelDeadlineCommand(1, true, true));
    CompositeCommand<?> returned = testRoundTrip(cmd);
    assertNotNull(returned);
    assertNotNull(returned.getMainCommand());
    assertTrue(returned.getMainCommand() instanceof SkipTaskCommand);
    assertEquals(Long.valueOf(1), returned.getTaskId());
    assertNotNull(returned.getCommands());
    assertEquals(2, returned.getCommands().size());
}
Also used : SkipTaskCommand(org.jbpm.services.task.commands.SkipTaskCommand) CancelDeadlineCommand(org.jbpm.services.task.commands.CancelDeadlineCommand) ProcessSubTaskCommand(org.jbpm.services.task.commands.ProcessSubTaskCommand) CompositeCommand(org.jbpm.services.task.commands.CompositeCommand) Test(org.junit.Test)

Example 3 with CompositeCommand

use of org.jbpm.services.task.commands.CompositeCommand in project jbpm by kiegroup.

the class JaxbTaskSerializationTest method compositeCommandXmlElementsAnnoTest.

@Test
public void compositeCommandXmlElementsAnnoTest() throws Exception {
    Field[] comCmdFields = CompositeCommand.class.getDeclaredFields();
    for (Field field : comCmdFields) {
        XmlElements xmlElemsAnno = field.getAnnotation(XmlElements.class);
        if (xmlElemsAnno != null) {
            Set<Class<? extends TaskCommand>> taskCmdSubTypes = reflections.getSubTypesOf(TaskCommand.class).stream().filter(e -> !e.getName().contains("$")).collect(Collectors.toSet());
            Set<Class<? extends UserGroupCallbackTaskCommand>> userGrpTaskCmdSubTypes = reflections.getSubTypesOf(UserGroupCallbackTaskCommand.class);
            taskCmdSubTypes.addAll(userGrpTaskCmdSubTypes);
            Class[] exclTaskCmds = { UserGroupCallbackTaskCommand.class, CompositeCommand.class, GetCurrentTxTasksCommand.class };
            taskCmdSubTypes.removeAll(Arrays.asList(exclTaskCmds));
            for (XmlElement xmlElemAnno : xmlElemsAnno.value()) {
                Class xmlElemAnnoType = xmlElemAnno.type();
                assertTrue(xmlElemAnnoType.getName() + " does not extend the " + TaskCommand.class.getSimpleName() + " class!", taskCmdSubTypes.contains(xmlElemAnnoType));
            }
            for (XmlElement xmlElemAnno : xmlElemsAnno.value()) {
                Class xmlElemAnnoType = xmlElemAnno.type();
                taskCmdSubTypes.remove(xmlElemAnnoType);
            }
            if (!taskCmdSubTypes.isEmpty()) {
                System.out.println("##### " + taskCmdSubTypes.iterator().next().getCanonicalName());
                fail("(" + taskCmdSubTypes.iterator().next().getSimpleName() + ") Not all " + TaskCommand.class.getSimpleName() + " sub types have been added to the @XmlElements in the CompositeCommand." + field.getName() + " field.");
            }
        } else {
            assertFalse("TaskCommand fields need to be annotated with @XmlElements annotations!", TaskCommand.class.equals(field.getType()));
            if (field.getType().isArray()) {
                Class arrElemType = field.getType().getComponentType();
                if (arrElemType != null) {
                    assertFalse("TaskCommand fields (CompositeCommand." + field.getName() + ") need to be annotated with @XmlElements annotations!", TaskCommand.class.equals(arrElemType));
                }
            } else if (Collection.class.isAssignableFrom(field.getType())) {
                ParameterizedType fieldGenericType = (ParameterizedType) field.getGenericType();
                Type listType = fieldGenericType.getActualTypeArguments()[0];
                if (listType != null) {
                    assertFalse("TaskCommand fields (CompositeCommand." + field.getName() + ") need to be annotated with @XmlElements annotations!", TaskCommand.class.equals(listType));
                }
            }
        }
    }
}
Also used : Arrays(java.util.Arrays) SetTaskPropertyCommand(org.jbpm.services.task.commands.SetTaskPropertyCommand) Date(java.util.Date) I18NText(org.kie.api.task.model.I18NText) Reflections(org.reflections.Reflections) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) DESCRIPTION_PROPERTY(org.jbpm.services.task.commands.SetTaskPropertyCommand.DESCRIPTION_PROPERTY) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlElements(javax.xml.bind.annotation.XmlElements) SubTasksStrategy(org.kie.internal.task.api.model.SubTasksStrategy) Assert.fail(org.junit.Assert.fail) GetCurrentTxTasksCommand(org.jbpm.services.task.admin.listener.internal.GetCurrentTxTasksCommand) Collection(java.util.Collection) FAULT_PROPERTY(org.jbpm.services.task.commands.SetTaskPropertyCommand.FAULT_PROPERTY) TASK_NAMES_PROPERTY(org.jbpm.services.task.commands.SetTaskPropertyCommand.TASK_NAMES_PROPERTY) Set(java.util.Set) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) JaxbTask(org.jbpm.services.task.impl.model.xml.JaxbTask) ClasspathHelper(org.reflections.util.ClasspathHelper) SKIPPABLE_PROPERTY(org.jbpm.services.task.commands.SetTaskPropertyCommand.SKIPPABLE_PROPERTY) List(java.util.List) EXPIRATION_DATE_PROPERTY(org.jbpm.services.task.commands.SetTaskPropertyCommand.EXPIRATION_DATE_PROPERTY) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) Type(java.lang.reflect.Type) Assert.assertFalse(org.junit.Assert.assertFalse) Entry(java.util.Map.Entry) AddContentFromUserCommand(org.jbpm.services.task.commands.AddContentFromUserCommand) UserGroupCallback(org.kie.internal.task.api.UserGroupCallback) JaxbContent(org.jbpm.services.task.impl.model.xml.JaxbContent) Mockito.mock(org.mockito.Mockito.mock) AccessType(org.kie.internal.task.api.model.AccessType) CompositeCommand(org.jbpm.services.task.commands.CompositeCommand) TestType(org.jbpm.services.task.jaxb.AbstractTaskSerializationTest.TestType) Marshaller(javax.xml.bind.Marshaller) StreamSource(javax.xml.transform.stream.StreamSource) HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OUTPUT_PROPERTY(org.jbpm.services.task.commands.SetTaskPropertyCommand.OUTPUT_PROPERTY) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) Assume(org.junit.Assume) JAXBContext(javax.xml.bind.JAXBContext) FaultDataImpl(org.jbpm.services.task.impl.model.FaultDataImpl) Unmarshaller(javax.xml.bind.Unmarshaller) TaskInstanceService(org.kie.internal.task.api.TaskInstanceService) StringWriter(java.io.StringWriter) JAXBElement(javax.xml.bind.JAXBElement) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) PRIORITY_PROPERTY(org.jbpm.services.task.commands.SetTaskPropertyCommand.PRIORITY_PROPERTY) Field(java.lang.reflect.Field) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) SubTypesScanner(org.reflections.scanners.SubTypesScanner) ParameterizedType(java.lang.reflect.ParameterizedType) TaskCommand(org.jbpm.services.task.commands.TaskCommand) I18NTextImpl(org.jbpm.services.task.impl.model.I18NTextImpl) SUB_TASK_STRATEGY_PROPERTY(org.jbpm.services.task.commands.SetTaskPropertyCommand.SUB_TASK_STRATEGY_PROPERTY) TaskContext(org.jbpm.services.task.commands.TaskContext) Assert.assertEquals(org.junit.Assert.assertEquals) XmlElement(javax.xml.bind.annotation.XmlElement) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) ParameterizedType(java.lang.reflect.ParameterizedType) Field(java.lang.reflect.Field) XmlElements(javax.xml.bind.annotation.XmlElements) Type(java.lang.reflect.Type) AccessType(org.kie.internal.task.api.model.AccessType) TestType(org.jbpm.services.task.jaxb.AbstractTaskSerializationTest.TestType) ParameterizedType(java.lang.reflect.ParameterizedType) XmlElement(javax.xml.bind.annotation.XmlElement) Collection(java.util.Collection) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) TaskCommand(org.jbpm.services.task.commands.TaskCommand) Test(org.junit.Test)

Example 4 with CompositeCommand

use of org.jbpm.services.task.commands.CompositeCommand in project droolsjbpm-integration by kiegroup.

the class TaskAssigningRuntimeServiceBase method executeContainerCommands.

private void executeContainerCommands(String containerId, List<PlanningCommand> commands) {
    LOGGER.debug("Executing planning commands for container: {}", containerId);
    List<DelegateAndSaveCommand> delegations = new ArrayList<>();
    List<SavePlanningItemCommand> saves = new ArrayList<>();
    List<DeletePlanningItemCommand> deletes = new ArrayList<>();
    validateContainer(containerId);
    for (PlanningCommand command : commands) {
        if (command instanceof DelegateAndSaveCommand) {
            delegations.add((DelegateAndSaveCommand) command);
        } else if (command instanceof SavePlanningItemCommand) {
            saves.add((SavePlanningItemCommand) command);
        } else if (command instanceof DeletePlanningItemCommand) {
            deletes.add((DeletePlanningItemCommand) command);
        }
    }
    bulkDelegate(containerId, delegations);
    List<PlanningCommand> onlyDBCommands = new ArrayList<>(saves);
    onlyDBCommands.addAll(deletes);
    if (!onlyDBCommands.isEmpty()) {
        CompositeCommand onlyDBCommand = new CompositeCommand<>(new TaskCommand<TaskCommand>() {

            @Override
            public TaskCommand execute(Context context) {
                return null;
            }
        }, onlyDBCommands.toArray(new TaskCommand[0]));
        userTaskService.execute(containerId, onlyDBCommand);
    }
    LOGGER.debug("Planning commands execution for container: {} finished successfully", containerId);
}
Also used : Context(org.kie.api.runtime.Context) ArrayList(java.util.ArrayList) DelegateAndSaveCommand(org.kie.server.services.taskassigning.runtime.command.DelegateAndSaveCommand) PlanningCommand(org.kie.server.services.taskassigning.runtime.command.PlanningCommand) SavePlanningItemCommand(org.kie.server.services.taskassigning.runtime.command.SavePlanningItemCommand) CompositeCommand(org.jbpm.services.task.commands.CompositeCommand) DeletePlanningItemCommand(org.kie.server.services.taskassigning.runtime.command.DeletePlanningItemCommand) TaskCommand(org.jbpm.services.task.commands.TaskCommand)

Example 5 with CompositeCommand

use of org.jbpm.services.task.commands.CompositeCommand in project droolsjbpm-integration by kiegroup.

the class TaskAssigningRuntimeServiceBaseTest method executePlanningWithTaskInInProgressOrSuspendedStatusWithActualOwnerUnChanged.

private void executePlanningWithTaskInInProgressOrSuspendedStatusWithActualOwnerUnChanged(Status status) {
    TaskData taskData = mockTaskData(TASK_ID, status, ASSIGNED_USER_ID, null);
    List<TaskData> taskDataList = Collections.singletonList(taskData);
    PlanningItem planningItem = mockPlanningItem(TASK_ID, CONTAINER_ID, ASSIGNED_USER_ID);
    PlanningItemList planningItemList = new PlanningItemList(Collections.singletonList(planningItem));
    prepareExecution(taskDataList, CONTAINER_ID);
    PlanningExecutionResult result = serviceBase.executePlanning(planningItemList, USER_ID);
    verify(userTaskService).execute(eq(CONTAINER_ID), planningCommandCaptor.capture());
    CompositeCommand compositeCommand = (CompositeCommand) planningCommandCaptor.getValue();
    assertSavePlanningItemCommand(compositeCommand.getCommands(), 0, planningItem);
    assertNoError(result);
}
Also used : PlanningItemList(org.kie.server.api.model.taskassigning.PlanningItemList) PlanningExecutionResult(org.kie.server.api.model.taskassigning.PlanningExecutionResult) PlanningItem(org.kie.server.api.model.taskassigning.PlanningItem) TaskData(org.kie.server.api.model.taskassigning.TaskData) CompositeCommand(org.jbpm.services.task.commands.CompositeCommand)

Aggregations

CompositeCommand (org.jbpm.services.task.commands.CompositeCommand)6 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 CancelDeadlineCommand (org.jbpm.services.task.commands.CancelDeadlineCommand)2 TaskCommand (org.jbpm.services.task.commands.TaskCommand)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringWriter (java.io.StringWriter)1 Constructor (java.lang.reflect.Constructor)1 Field (java.lang.reflect.Field)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1