@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()); }
public void fail(long taskId, String userId, Map<String, Object> faultData) { executor.execute(new CompositeCommand<Void>( new FailTaskCommand(taskId, userId, faultData), new CancelDeadlineCommand(taskId, true, true))); }
protected String getUserId(Command<?> command) { if (command instanceof CompositeCommand) { CompositeCommand<?> compCmd = (CompositeCommand<?>) command; String userId = getUserId(compCmd.getMainCommand()); if (userId != null) { return userId; } for (Command<?> cmd : compCmd.getCommands()) { userId = getUserId(cmd); if (userId != null) { return userId; } } } if (command instanceof TaskCommand) { return ((TaskCommand<?>) command).getUserId(); } return null; }
protected void addUserIdToContext(TaskCommand<?> command, RequestContext context) { if (context instanceof org.kie.internal.task.api.TaskContext) { org.kie.internal.task.api.TaskContext taskContext = (org.kie.internal.task.api.TaskContext) context; IdentityProvider identityProvider = (IdentityProvider) taskContext.get(EnvironmentName.IDENTITY_PROVIDER); String userId = command.getUserId(); if (command instanceof CompositeCommand) { userId = ((CompositeCommand<?>) command).getMainCommand().getUserId(); } if (userId == null && identityProvider != null) { userId = identityProvider.getName(); command.setUserId(userId); } taskContext.setUserId(userId); } } }
public void start(long taskId, String userId) { executor.execute(new CompositeCommand<Void>( new StartTaskCommand(taskId, userId), new CancelDeadlineCommand(taskId, true, false))); }
protected String getOperationName(Command<?> command) { Command<?> cmd = command; if (command instanceof CompositeCommand) { CompositeCommand<?> compCmd = (CompositeCommand<?>) command; cmd = compCmd.getMainCommand(); } return cmd.getClass().getSimpleName().replace("Command", ""); }
@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()); }
public void exit(long taskId, String userId) { executor.execute(new CompositeCommand<Void>( new ExitTaskCommand(taskId, userId), new CancelDeadlineCommand(taskId, true, true))); }
public void complete(long taskId, String userId, Map<String, Object> data) { executor.execute(new CompositeCommand<Void>( new CompleteTaskCommand(taskId, userId, data), new ProcessSubTaskCommand(taskId, userId, data), new CancelDeadlineCommand(taskId, true, true))); }
public void skip(long taskId, String userId) { executor.execute(new CompositeCommand<Void>( new SkipTaskCommand(taskId, userId), new ProcessSubTaskCommand(taskId, userId), new CancelDeadlineCommand(taskId, true, true))); }
@Override public void claim(long taskId, String user, String deploymentId) { taskService.execute(deploymentId, new CompositeCommand<Void>(new StartTaskCommand(taskId, user), new ClaimTaskCommand(taskId, user))); }