Skip to content

Commit

Permalink
AAE-29004 Add processDefinitionName field to process instance search …
Browse files Browse the repository at this point in the history
…endpoint (#1628)

* AAE-29004 add missing field

* empty-commit
  • Loading branch information
tom-dal authored Dec 4, 2024
1 parent db597da commit b6f3298
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//prettier-ignore
public record ProcessInstanceSearchRequest(
Set<String> name,
Set<String> processDefinitionName,
Set<String> initiator,
Set<String> appVersion,
Set<ProcessInstance.ProcessInstanceStatus> status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public Predicate toPredicate(
query.distinct(distinct);
applyUserRestrictionFilter(root, criteriaBuilder);
applyNameFilter(root, criteriaBuilder);
applyProcessDefinitionNameFilter(root);
applyInitiatorFilter(root);
applyAppVersionFilter(root);
applyStatusFilter(root);
Expand Down Expand Up @@ -91,6 +92,14 @@ private void applyNameFilter(Root<ProcessInstanceEntity> root, CriteriaBuilder c
}
}

private void applyProcessDefinitionNameFilter(Root<ProcessInstanceEntity> root) {
if (!CollectionUtils.isEmpty(searchRequest.processDefinitionName())) {
predicates.add(
root.get(ProcessInstanceEntity_.processDefinitionName).in(searchRequest.processDefinitionName())
);
}
}

private void applyInitiatorFilter(Root<ProcessInstanceEntity> root) {
if (!CollectionUtils.isEmpty(searchRequest.initiator())) {
predicates.add(root.get(ProcessInstanceEntity_.initiator).in(searchRequest.initiator()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static io.restassured.module.mockmvc.RestAssuredMockMvc.postProcessors;
import static io.restassured.module.mockmvc.RestAssuredMockMvc.webAppContextSetup;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsInRelativeOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
Expand All @@ -32,10 +31,8 @@
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.IntStream;
import org.activiti.QueryRestTestApplication;
import org.activiti.api.process.model.ProcessInstance;
import org.activiti.api.task.model.Task;
import org.activiti.cloud.alfresco.config.AlfrescoWebAutoConfiguration;
import org.activiti.cloud.services.query.model.ProcessInstanceEntity;
import org.activiti.cloud.services.query.model.ProcessVariableKey;
Expand All @@ -44,11 +41,8 @@
import org.activiti.cloud.services.query.rest.filter.VariableType;
import org.activiti.cloud.services.query.rest.payload.CloudRuntimeEntitySort;
import org.activiti.cloud.services.query.rest.payload.ProcessInstanceSearchRequest;
import org.activiti.cloud.services.query.rest.payload.TaskSearchRequest;
import org.activiti.cloud.services.query.util.ProcessInstanceSearchRequestBuilder;
import org.activiti.cloud.services.query.util.QueryTestUtils;
import org.activiti.cloud.services.query.util.TaskBuilder;
import org.activiti.cloud.services.query.util.TaskSearchRequestBuilder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -118,6 +112,39 @@ void should_returnProcessInstances_filteredByNameLike() {
.body(PROCESS_INSTANCE_IDS_JSON_PATH, hasItem(processInstance2.getId()));
}

@Test
void should_returnProcessInstances_filteredByProcessDefinitionName() {
ProcessInstanceEntity processInstance1 = queryTestUtils
.buildProcessInstance()
.withInitiator(USER)
.withProcessDefinitionName("Process def name one")
.buildAndSave();
ProcessInstanceEntity processInstance2 = queryTestUtils
.buildProcessInstance()
.withInitiator(USER)
.withProcessDefinitionName("Process def name two")
.buildAndSave();
queryTestUtils
.buildProcessInstance()
.withInitiator(USER)
.withProcessDefinitionName("Process def name three")
.buildAndSave();

ProcessInstanceSearchRequestBuilder requestBuilder = new ProcessInstanceSearchRequestBuilder()
.withProcessDefinitionNames("Process def name one", "Process def name two");

given()
.contentType(MediaType.APPLICATION_JSON)
.body(requestBuilder.buildJson())
.when()
.post(getSearchEndpoint())
.then()
.statusCode(200)
.body(PROCESS_INSTANCES_JSON_PATH, hasSize(2))
.body(PROCESS_INSTANCE_IDS_JSON_PATH, hasItem(processInstance1.getId()))
.body(PROCESS_INSTANCE_IDS_JSON_PATH, hasItem(processInstance2.getId()));
}

@Test
void should_returnProcessInstances_filteredByAppVersion() {
ProcessInstanceEntity processInstance1 = queryTestUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public ProcessInstanceBuilder withName(String name) {
return this;
}

public ProcessInstanceBuilder withProcessDefinitionName(String processDefinitionName) {
process.setProcessDefinitionName(processDefinitionName);
return this;
}

public ProcessInstanceBuilder withAppName(String appName) {
process.setAppName(appName);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class ProcessInstanceSearchRequestBuilder {

private Set<String> names;
private Set<String> processDefinitionNames;
private Set<String> initiators;
private Set<String> appVersions;
private Set<ProcessInstance.ProcessInstanceStatus> statuses;
Expand All @@ -51,6 +52,11 @@ public ProcessInstanceSearchRequestBuilder withNames(String... names) {
return this;
}

public ProcessInstanceSearchRequestBuilder withProcessDefinitionNames(String... processDefinitionNames) {
this.processDefinitionNames = Set.of(processDefinitionNames);
return this;
}

public ProcessInstanceSearchRequestBuilder withInitiators(String... initiators) {
this.initiators = Set.of(initiators);
return this;
Expand Down Expand Up @@ -137,6 +143,7 @@ public ProcessInstanceSearchRequest build() {
}
return new ProcessInstanceSearchRequest(
names,
processDefinitionNames,
initiators,
appVersions,
statuses,
Expand Down
Loading

0 comments on commit b6f3298

Please sign in to comment.