static JaxbCommandsRequest prepareCommandRequest( Command command, String userName, String deploymentId, Long processInstanceId, Collection<String> correlationKeyProps) { if (deploymentId == null && !(command instanceof TaskCommand || command instanceof AuditCommand)) { throw new MissingRequiredInfoException( "A deployment id is required when sending commands involving the KieSession."); } JaxbCommandsRequest req; if (command instanceof AuditCommand) { req = new JaxbCommandsRequest(command); } else { req = new JaxbCommandsRequest(deploymentId, command); } if (command instanceof TaskCommand) { TaskCommand taskCmd = (TaskCommand) command; if (taskCmd.getUserId() == null) { taskCmd.setUserId(userName); } } if (processInstanceId != null) { if (command instanceof ProcessInstanceIdCommand) { processInstanceId = ((ProcessInstanceIdCommand) command).getProcessInstanceId(); } } if (correlationKeyProps != null && !correlationKeyProps.isEmpty()) { StringBuffer correlationKeyString = new StringBuffer(); Iterator<String> iter = correlationKeyProps.iterator(); correlationKeyString.append(iter.next()); while (iter.hasNext()) { correlationKeyString.append(":").append(iter.next()); } req.setCorrelationKeyString(correlationKeyString.toString()); } req.setProcessInstanceId(processInstanceId); req.setUser(userName); req.setVersion(VERSION); return req; }
void preprocessCommand(Command cmd) { String cmdName = cmd.getClass().getSimpleName(); if (cmd instanceof TaskCommand && cmdName.startsWith("GetTask")) { TaskCommand taskCmd = (TaskCommand) cmd; String cmdUserId = taskCmd.getUserId(); String authUserId = config.getUserName(); if (cmdUserId == null) { taskCmd.setUserId(authUserId); logger.debug("Using user id '" + authUserId + "' for '" + cmdName + "'."); } else if (!cmdUserId.equals(authUserId)) { throw new RemoteApiException( "The user id used when retrieving task information (" + cmdUserId + ")" + " must match the authenticating user (" + authUserId + ")!"); } } }