Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAE-29004 Add processDefinitionName field to process instance search endpoint #1628

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading