@Override public String renderCaseForm(String containerId, String caseDefinitionId, String renderer) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(RestURI.CONTAINER_ID, containerId); valuesMap.put(RestURI.CASE_DEF_ID, caseDefinitionId); StringBuffer params = new StringBuffer(); if (renderer != null) { params.append("?renderer=").append(renderer); } Map<String, String> headers = new HashMap<String, String>(); headers.put("Accept", MediaType.TEXT_HTML); return makeHttpGetRequestAndCreateRawResponse( build(loadBalancer.getUrl(), FORM_URI + "/" + CASE_FORM_CONTENT_GET_URI + params.toString(), valuesMap), headers); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "FormRendererService", "getCaseRenderedForm", new Object[]{renderer, containerId, caseDefinitionId} )) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM-UI", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Test public void testStartProcessUseOfAsyncResponseHandler() throws Exception { ResponseCallback callback = new BlockingResponseCallback(null); testStartProcessResponseHandler(new AsyncResponseHandler(callback)); // now let's check if response has arrived ServiceResponsesList response = callback.get(); assertThat(response).isNotNull(); assertThat(response.getResponses()).isNotNull().hasSize(1); KieServerAssert.assertSuccess(response.getResponses().get(0)); ServiceResponse<? extends Object> serviceResponse = response.getResponses().get(0); Object result = serviceResponse.getResult(); assertThat(result).isNotNull(); }
@Test public void testCreateEmptyContainer() { KieContainerResource containerResource = new KieContainerResource(CONTAINER_ID, releaseId); ServiceResponse<KieContainerResource> createContainer = client.createContainer(CONTAINER_ID, containerResource); KieServerAssert.assertSuccess(createContainer); List<Message> messages = createContainer.getResult().getMessages(); assertThat(messages).hasSize(1); assertThat(messages.get(0).getSeverity()).isEqualTo(Severity.INFO); } }
@Override public TaskInstance getTaskInstance(String containerId, Long taskId, boolean withInputs, boolean withOutputs, boolean withAssignments) { TaskInstance result = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(TASK_INSTANCE_ID, taskId); StringBuilder queryString = new StringBuilder(); queryString.append("?withInputData").append("=").append(withInputs) .append("&withOutputData").append("=").append(withOutputs) .append("&withAssignments").append("=").append(withAssignments); result = makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_GET_URI, valuesMap) + queryString.toString(), TaskInstance.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "UserTaskService", "getTask", marshaller.getFormat().getType(), new Object[]{containerId, taskId, withInputs, withOutputs, withAssignments}) ) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = deserialize(response.getResult(), TaskInstance.class); } return result; }
@Override public ProcessDefinition findProcessByContainerIdProcessId(String containerId, String processId) { ProcessDefinition result = null; if (config.isRest()) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_ID, processId); result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_DEFINITIONS_BY_CONTAINER_ID_DEF_ID_GET_URI, valuesMap), ProcessDefinition.class); } else { CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessesByDeploymentIdProcessId", new Object[]{containerId, processId}))); ServiceResponse<ProcessDefinition> response = (ServiceResponse<ProcessDefinition>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = response.getResult(); } return result; }
@Override public SubProcessesDefinition getReusableSubProcessDefinitions(String containerId, String processId) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_ID, processId); return makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_DEF_URI + "/" + PROCESS_DEF_SUBPROCESS_GET_URI, valuesMap), SubProcessesDefinition.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "DefinitionService", "getReusableSubProcesses", new Object[]{containerId, processId}) ) ); ServiceResponse<SubProcessesDefinition> response = (ServiceResponse<SubProcessesDefinition>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public TaskInstance findTaskById(Long taskId) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(TASK_INSTANCE_ID, taskId); return makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), QUERY_URI + "/" + TASK_GET_URI, valuesMap), TaskInstance.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "QueryService", "getTaskById", new Object[]{taskId}) ) ); ServiceResponse<TaskInstance> response = (ServiceResponse<TaskInstance>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM" ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public String getProcessImage(String containerId, String processId) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(RestURI.CONTAINER_ID, containerId); valuesMap.put(RestURI.PROCESS_ID, processId); Map<String, String> headers = new HashMap<String, String>(); headers.put("Accept", MediaType.APPLICATION_SVG_XML); return makeHttpGetRequestAndCreateRawResponse( build(loadBalancer.getUrl(), IMAGE_URI + "/" + PROCESS_IMG_GET_URI, valuesMap), headers); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "ImageService", "getProcessImage", new Object[]{containerId, processId} )) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM-UI", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public String getProcessInstanceImage(String containerId, Long processInstanceId) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(RestURI.CONTAINER_ID, containerId); valuesMap.put(RestURI.PROCESS_INST_ID, processInstanceId); Map<String, String> headers = new HashMap<String, String>(); headers.put("Accept", MediaType.APPLICATION_SVG_XML); return makeHttpGetRequestAndCreateRawResponse( build(loadBalancer.getUrl(), IMAGE_URI + "/" + PROCESS_INST_IMG_GET_URI, valuesMap), headers); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "ImageService", "getActiveProcessImage", new Object[]{containerId, processInstanceId} )) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM-UI", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public VariablesDefinition getProcessVariableDefinitions(String containerId, String processId) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_ID, processId); return makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_DEF_URI + "/" + PROCESS_DEF_VARIABLES_GET_URI, valuesMap), VariablesDefinition.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "DefinitionService", "getProcessVariables", new Object[]{containerId, processId}) ) ); ServiceResponse<VariablesDefinition> response = (ServiceResponse<VariablesDefinition>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public ServiceTasksDefinition getServiceTaskDefinitions(String containerId, String processId) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_ID, processId); return makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_DEF_URI + "/" + PROCESS_DEF_SERVICE_TASKS_GET_URI, valuesMap), ServiceTasksDefinition.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "DefinitionService", "getServiceTasks", new Object[]{containerId, processId}) ) ); ServiceResponse<ServiceTasksDefinition> response = (ServiceResponse<ServiceTasksDefinition>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public UserTaskDefinitionList getUserTaskDefinitions(String containerId, String processId) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_ID, processId); return makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_DEF_URI + "/" + PROCESS_DEF_USER_TASKS_GET_URI, valuesMap), UserTaskDefinitionList.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "DefinitionService", "getTasksDefinitions", new Object[]{containerId, processId}) ) ); ServiceResponse<UserTaskDefinitionList> response = (ServiceResponse<UserTaskDefinitionList>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public TaskInstance findTaskByWorkItemId(Long workItemId) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(WORK_ITEM_ID, workItemId); return makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), QUERY_URI + "/" + TASK_BY_WORK_ITEM_ID_GET_URI, valuesMap), TaskInstance.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "QueryService", "getTaskByWorkItemId", new Object[]{workItemId}) ) ); ServiceResponse<TaskInstance> response = (ServiceResponse<TaskInstance>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM" ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public ProcessInstance findProcessInstanceById(Long processInstanceId, boolean withVars) { ProcessInstance result = null; if (config.isRest()) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(PROCESS_INST_ID, processInstanceId); result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCE_BY_INSTANCE_ID_GET_URI, valuesMap) + "?withVars=" + withVars, ProcessInstance.class); } else { CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstanceById", new Object[]{processInstanceId, withVars}))); ServiceResponse<ProcessInstance> response = (ServiceResponse<ProcessInstance>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = response.getResult(); } return result; }
@Override public ProcessInstance findProcessInstanceById(Long processInstanceId) { ProcessInstance result = null; if (config.isRest()) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(PROCESS_INST_ID, processInstanceId); result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCE_BY_INSTANCE_ID_GET_URI, valuesMap), ProcessInstance.class); } else { CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstanceById", new Object[]{processInstanceId}))); ServiceResponse<ProcessInstance> response = (ServiceResponse<ProcessInstance>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = response.getResult(); } return result; }
@Override public ServiceResponse<ExecutionResults> executeCommandsWithResults(String id, String payload) { if( config.isRest() ) { return makeHttpPostRequestAndCreateServiceResponse( loadBalancer.getUrl() + "/containers/instances/" + id, payload, (Class) ExecutionResultImpl.class); } else { CommandScript script = new CommandScript( Collections.singletonList((KieServerCommand) new CallContainerCommand(id, payload)) ); ServiceResponse response = executeJmsCommand( script, null, null, id ).getResponses().get( 0 ); if (shouldReturnWithNullResponse(response)) { return null; } if (response.getResult() instanceof String) { response.setResult(deserialize((String) response.getResult(), (Class) ExecutionResultImpl.class)); } return response; } }
@Override public TaskOutputsDefinition getUserTaskOutputDefinitions(String containerId, String processId, String taskName) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_ID, processId); valuesMap.put(TASK_NAME, encode(taskName)); return makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_DEF_URI + "/" + PROCESS_DEF_USER_TASK_OUTPUT_GET_URI, valuesMap), TaskOutputsDefinition.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "DefinitionService", "getTaskOutputMappings", new Object[]{containerId, processId, taskName}) ) ); ServiceResponse<TaskOutputsDefinition> response = (ServiceResponse<TaskOutputsDefinition>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public ProcessDefinition getProcessDefinition(String containerId, String processId) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_ID, processId); return makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_DEF_URI + "/" + PROCESS_DEF_GET_URI, valuesMap), ProcessDefinition.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "DefinitionService", "getProcessDefinition", new Object[]{containerId, processId}) ) ); ServiceResponse<ProcessDefinition> response = (ServiceResponse<ProcessDefinition>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public AssociatedEntitiesDefinition getAssociatedEntityDefinitions(String containerId, String processId) { if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_ID, processId); return makeHttpGetRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_DEF_URI + "/" + PROCESS_DEF_ASSOCIATED_ENTITIES_GET_URI, valuesMap), AssociatedEntitiesDefinition.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "DefinitionService", "getAssociatedEntities", new Object[]{containerId, processId}) ) ); ServiceResponse<AssociatedEntitiesDefinition> response = (ServiceResponse<AssociatedEntitiesDefinition>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } }
@Override public NodeInstance findNodeInstanceByWorkItemId(Long processInstanceId, Long workItemId) { NodeInstance result = null; if (config.isRest()) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(PROCESS_INST_ID, processInstanceId); valuesMap.put(WORK_ITEM_ID, workItemId); result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + NODE_INSTANCES_BY_WORK_ITEM_ID_GET_URI, valuesMap), NodeInstance.class); } else { CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getNodeInstanceForWorkItem", new Object[]{processInstanceId, workItemId}))); ServiceResponse<NodeInstance> response = (ServiceResponse<NodeInstance>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = response.getResult(); } return result; }