RemoteProcessVariablesServiceImpl extends AbstractKieServerService implements ProcessVariablesService { @Override public List<ProcessVariableSummary> getProcessVariables(QueryFilter filter) { Long processInstanceId = null; String processId = ""; String deploymentId = ""; String serverTemplateId = ""; if (filter.getParams() != null) { processInstanceId = Long.valueOf((String) filter.getParams().get("processInstanceId")); processId = (String) filter.getParams().get("processDefId"); deploymentId = (String) filter.getParams().get("deploymentId"); serverTemplateId = (String) filter.getParams().get("serverTemplateId"); } Map<String, String> properties = new HashMap<String, String>(); QueryServicesClient queryServicesClient = getClient(serverTemplateId, QueryServicesClient.class); ProcessServicesClient processClient = getClient(serverTemplateId, ProcessServicesClient.class); try { VariablesDefinition vars = processClient.getProcessVariableDefinitions(deploymentId, processId); properties.putAll(vars.getVariables()); } catch (KieServicesHttpException kieException) { } List<VariableInstance> variables = queryServicesClient.findVariablesCurrentState(processInstanceId); Collection<ProcessVariableSummary> processVariables = VariableHelper.adaptCollection(variables, properties, processInstanceId, deploymentId, serverTemplateId, filter.getOrderBy(), filter.isAscending()); List<ProcessVariableSummary> processVariablesSums = new ArrayList<ProcessVariableSummary>(processVariables.size()); for (ProcessVariableSummary pv : processVariables) { if (filter.getParams().get("textSearch") == null || ((String) filter.getParams().get("textSearch")).isEmpty()) { processVariablesSums.add(pv); } else if (pv.getVariableId().toLowerCase().contains((String) filter.getParams().get("textSearch"))) { processVariablesSums.add(pv); } } return processVariablesSums; }  @Override PageResponse<ProcessVariableSummary> getData(QueryFilter filter); @Override List<ProcessVariableSummary> getProcessVariables(QueryFilter filter); @Override List<ProcessVariableSummary> getVariableHistory(ProcessInstanceKey processInstance,
                                                           String variableName);  }
@Test public void getProcessVariablesTestWithContainerStarted() { HashMap processDefVars = new HashMap(); processDefVars.put(var1, ""); processDefVars.put(var2, ""); VariablesDefinition variablesDefinition = new VariablesDefinition(processDefVars); VariableInstance variableInstance = VariableInstance.builder() .name(var1) .value(var1_value) .processInstanceId(Long.valueOf(processInstanceId)) .date(new Date()) .build(); when(queryServicesClient.findVariablesCurrentState(any())).thenReturn(singletonList(variableInstance)); when(processServicesClient.getProcessVariableDefinitions(containerId, processId)).thenReturn(variablesDefinition); List<ProcessVariableSummary> processInstanceVariables = processVariablesService.getProcessVariables(queryFilter); verify(processServicesClient).getProcessVariableDefinitions(containerId, processId); verify(queryServicesClient).findVariablesCurrentState(Long.valueOf(processInstanceId)); assertEquals(2, processInstanceVariables.size()); assertEquals(var1, processInstanceVariables.get(0).getName()); assertEquals(var1_value, processInstanceVariables.get(0).getNewValue()); assertEquals(var2, processInstanceVariables.get(1).getName()); assertEquals("", processInstanceVariables.get(1).getNewValue()); }
@Test public void getProcessVariablesTestWithContainerStopped() { VariableInstance variableInstance = VariableInstance.builder() .name(var1) .value(var1_value) .processInstanceId(Long.valueOf(processInstanceId)) .date(new Date()) .build(); when(processServicesClient.getProcessVariableDefinitions(containerId, processId)).thenThrow(new KieServicesHttpException()); when(queryServicesClient.findVariablesCurrentState(any())).thenReturn(singletonList(variableInstance)); List<ProcessVariableSummary> processInstanceVariables = processVariablesService.getProcessVariables(queryFilter); verify(processServicesClient).getProcessVariableDefinitions(containerId, processId); verify(queryServicesClient).findVariablesCurrentState(Long.valueOf(processInstanceId)); assertEquals(1, processInstanceVariables.size()); assertEquals(var1, processInstanceVariables.get(0).getName()); assertEquals(var1_value, processInstanceVariables.get(0).getNewValue()); }