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());
}
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());
}
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));
}
}
}
}
}
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);
}
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);
}
Aggregations