package com.example.demo;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class Binder {
private static List<ProcessInstance> instances = new ArrayList<>();
private static List<ProcessDefinition> definitions = new ArrayList<>();
private static List<ProjectResource> resources = new ArrayList<>();
private static String theProjectName = "THEPROJECT";
private static String channel = "CHANNEL";
private static String workline = "WL";
public void setup(){
definitions.add(new ProcessDefinition("foo"));
definitions.add(new ProcessDefinition("bar"));
definitions.add(new ProcessDefinition("baz"));
definitions.add(new ProcessDefinition("a123-THEPROJECT-CHANNEL-WL"));
for (ProcessDefinition def : definitions) {
ProcessInstance instance = new ProcessInstance();
instance.setId(UUID.randomUUID().toString());
instance.setDefinitionId(def.getId());
instances.add(instance);
if(def.getKey().equals("a123-THEPROJECT-CHANNEL-WL")){
System.out.println("Correct instance to retrieve has id " + instance.getId());
}
}
}
public static void main(String[] args) {
Binder bind = new Binder();
bind.setup();
String identifier = theProjectName + "-" + channel + "-" + workline;
List<String> matchingDefs = definitions.stream().filter(d -> d.getKey().endsWith(identifier)).map(d -> d.getId()).collect(Collectors.toList());
List<ProcessInstance> matchingInst = instances.stream().filter(i -> matchingDefs.contains(i.getDefinitionId())).collect(Collectors.toList());
for (ProcessInstance processInstance : matchingInst) {
System.out.println("Retrieved instance " + processInstance.getId() + " with def id: " + processInstance.getDefinitionId());
}
}
}