VariableHelper { public static List<ProcessVariableSummary> adaptCollection(List<VariableInstance> variables, Map<String, String> properties, long processInstanceId, String deploymentId, String serverTemplateId, String sortBy, boolean asc) { List<VariableInstance> filteredVariables = variables.stream() .filter(variable -> !excludedVariables.contains(variable.getVariableName())) .collect(Collectors.toList()); List<ProcessVariableSummary> variablesSummary = new ArrayList<>(); properties.forEach((key, value) -> { VariableProcessor processor = processors.getOrDefault(value, new DefaultVariableProcessor()); processor.process(processInstanceId, key, value, filteredVariables, deploymentId, serverTemplateId, variableSummary -> variablesSummary.add(variableSummary)); }); variablesSummary.addAll(ofNullable(filteredVariables).orElse(emptyList()) .stream() .map(new ProcessInstanceVariableMapper(deploymentId, serverTemplateId, "")) .collect(Collectors.toList())); Comparator<ProcessVariableSummary> comparator; switch (ofNullable(sortBy).orElse(COL_PROCESS_INSTANCE_VAR_ID)) { case COL_PROCESS_INSTANCE_VAR_ID: comparator = comparing(ProcessVariableSummary::getVariableId); break; case COL_PROCESS_INSTANCE_VAR_VALUE: comparator = comparing(ProcessVariableSummary::getNewValue); break; case COL_PROCESS_INSTANCE_VAR_TYPE: comparator = comparing(ProcessVariableSummary::getType); break; case COL_PROCESS_INSTANCE_VAR_LASTMOD: comparator = comparing(ProcessVariableSummary::getTimestamp); break; default: comparator = comparing(ProcessVariableSummary::getName); } variablesSummary.sort(asc ? comparator : comparator.reversed()); return variablesSummary; }  static void registerProcessor(VariableProcessor processor); static List<ProcessVariableSummary> adaptCollection(List<VariableInstance> variables,
                                                               Map<String, String> properties,
                                                               long processInstanceId,
                                                               String deploymentId,
                                                               String serverTemplateId,
                                                               String sortBy,
                                                               boolean asc); static final Collection<String> DOCUMENT_TYPES; static final String JBPM_DOCUMENT; static final String DOCUMENT_COLLECTION; static final String DOCUMENT_COLLECTION_IMPL; static final String LEGACY_DOCUMENTS; }
@Test public void addDeploymentIdServerTemplateToAllProcessInstancesVarsTest() { List<ProcessVariableSummary> varList = VariableHelper.adaptCollection(variables, properties, processInstanceId, deploymentId, serverTemplateId, null, true); varList.stream().forEach(processVariableSummary -> { assertEquals(deploymentId, processVariableSummary.getDeploymentId()); assertEquals(serverTemplateId, processVariableSummary.getServerTemplateId()); }); assertEquals(4, varList.size()); assertEquals(processDefaultVar_name, varList.get(0).getName()); assertEquals(processDefinitionVar1Name, varList.get(1).getName()); assertEquals(processDefinitionVar2Name, varList.get(2).getName()); assertEquals(processDefinitionVar3Name, varList.get(3).getName()); assertEquals(processDefaultVarValue, varList.get(0).getNewValue()); assertEquals(processDefinitionVar1Value, varList.get(1).getNewValue()); assertEquals("", varList.get(2).getNewValue()); assertEquals("", varList.get(3).getNewValue()); }
@Test public void sortProcessInstancesVarsByNameTest() { List<ProcessVariableSummary> varList = VariableHelper.adaptCollection(variables, properties, processInstanceId, deploymentId, serverTemplateId, COL_PROCESS_INSTANCE_VAR_ID, true); assertEquals(4, varList.size()); assertEquals(processDefaultVar_name, varList.get(0).getName()); assertEquals(processDefinitionVar1Name, varList.get(1).getName()); assertEquals(processDefinitionVar2Name, varList.get(2).getName()); assertEquals(processDefinitionVar3Name, varList.get(3).getName()); varList = VariableHelper.adaptCollection(variables, properties, processInstanceId, deploymentId, serverTemplateId, COL_PROCESS_INSTANCE_VAR_ID, false); assertEquals(processDefaultVar_name, varList.get(3).getName()); assertEquals(processDefinitionVar1Name, varList.get(2).getName()); assertEquals(processDefinitionVar2Name, varList.get(1).getName()); assertEquals(processDefinitionVar3Name, varList.get(0).getName()); }