Skip to content

Commit

Permalink
Implement process definition key attribute handling query
Browse files Browse the repository at this point in the history
  • Loading branch information
igdianov committed Nov 15, 2024
1 parent bc5faec commit 75dc504
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.activiti.api.process.model.ProcessDefinition;
Expand Down Expand Up @@ -52,8 +55,9 @@ public ProcessDefinitionsSyncService(

public List<String> syncProcessDefinitions(SyncCloudProcessDefinitionsPayload payload) {
List<String> excludedProcessDefinitionIds = payload.getExcludedProcessDefinitionIds();
var processDefinitionKeys = payload.getProcessDefinitionKeys();

return queryProcessDefinitionsStream(excludedProcessDefinitionIds)
return queryProcessDefinitionsStream(processDefinitionKeys, excludedProcessDefinitionIds)
.map(processDefinitions -> processDefinitions.stream().map(this::toProcessDeployedEvent).toList())
.map(ProcessDeployedEvents::new)
.peek(applicationEventPublisher::publishEvent)
Expand All @@ -62,11 +66,21 @@ public List<String> syncProcessDefinitions(SyncCloudProcessDefinitionsPayload pa
.toList();
}

private Stream<List<ProcessDefinition>> queryProcessDefinitionsStream(List<String> excludedProcessDefinitionIds) {
private Stream<List<ProcessDefinition>> queryProcessDefinitionsStream(
List<String> processDefinitionKeys,
List<String> excludedProcessDefinitionIds
) {
final AtomicInteger counter = new AtomicInteger();

return repositoryService
.createProcessDefinitionQuery()
var query = repositoryService.createProcessDefinitionQuery();

Optional
.ofNullable(processDefinitionKeys)
.filter(Predicate.not(Collection::isEmpty))
.map(Set::copyOf)
.ifPresent(query::processDefinitionKeys);

return query
.list()
.stream()
.filter(it ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ public class CommandEndpointIT {
@Autowired
private CommandEndPointITStreamHandler streamHandler;

private Map<String, String> processDefinitionIds = new HashMap<>();
private final Map<String, String> processDefinitionIds = new HashMap<>();

private static List<ProcessDeployedEvents> processDeployedEvents = new ArrayList<>();
private final Map<String, String> processDefinitionKeys = new HashMap<>();

private static final List<ProcessDeployedEvents> processDeployedEvents = new ArrayList<>();

@TestComponent
static class TestProcessDeployedEventsListener {
Expand Down Expand Up @@ -140,6 +142,7 @@ public void setUp() {

for (ProcessDefinition pd : processDefinitions.getBody().getContent()) {
processDefinitionIds.put(pd.getName(), pd.getId());
processDefinitionKeys.put(pd.getKey(), pd.getId());
}
}

Expand Down Expand Up @@ -273,6 +276,28 @@ public void syncCloudProcessDefinitionsExcludedTest() {
.doesNotContain(processDefinitionIds.values().toArray());
}

@Test
public void syncCloudProcessDefinitionsKeysTest() {
final var testProcessDefinitionKey = "SimpleProcess";
streamHandler.resetSyncProcessDefinitionsAck();

var payload = SyncCloudProcessDefinitionsPayload
.builder()
.processDefinitionKeys(List.of(testProcessDefinitionKey))
.excludedProcessDefinitionIds(List.of("foo", "bar"))
.build();

var result = doSyncCloudProcessDefinitions(payload);

assertThat(result).extracting(SyncCloudProcessDefinitionsResult::getPayload).isEqualTo(payload);

assertThat(result)
.extracting(SyncCloudProcessDefinitionsResult::getEntity)
.asInstanceOf(InstanceOfAssertFactories.LIST)
.isNotEmpty()
.containsOnly(processDefinitionKeys.get(testProcessDefinitionKey));
}

private void completeTask(Task task) {
Map<String, Object> variables = new HashMap<>();

Expand Down

0 comments on commit 75dc504

Please sign in to comment.