-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
6 changed files
with
163 additions
and
42 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/io/zeebe/monitor/querydsl/ProcessEntityPredicatesBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.zeebe.monitor.querydsl; | ||
|
||
import static org.apache.commons.lang3.StringUtils.isEmpty; | ||
|
||
import com.querydsl.core.types.Predicate; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.core.types.dsl.Expressions; | ||
import com.querydsl.core.types.dsl.PathBuilder; | ||
import io.zeebe.monitor.entity.QProcessEntity; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
public class ProcessEntityPredicatesBuilder { | ||
|
||
final PathBuilder<QProcessEntity> pathBuilder = | ||
new PathBuilder<>(QProcessEntity.class, QProcessEntity.processEntity.getMetadata()); | ||
|
||
private final List<Predicate> predicates = new ArrayList<>(); | ||
|
||
public ProcessEntityPredicatesBuilder withBpmnProcessId(String processId) { | ||
if (!isEmpty(processId)) { | ||
predicates.add(pathBuilder.getString("bpmnProcessId").containsIgnoreCase(processId)); | ||
} | ||
return this; | ||
} | ||
|
||
public ProcessEntityPredicatesBuilder withKeys(Collection<Long> keys) { | ||
if (!CollectionUtils.isEmpty(keys)) { | ||
predicates.add(pathBuilder.getNumber("key", Long.class).in(keys)); | ||
} | ||
return this; | ||
} | ||
|
||
public Predicate build() { | ||
BooleanExpression result = Expressions.asBoolean(true).isTrue(); | ||
for (Predicate predicate : predicates) { | ||
result = result.and(predicate); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/java/io/zeebe/monitor/repository/ProcessRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.zeebe.monitor.repository; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.zeebe.monitor.entity.ProcessEntity; | ||
import java.util.List; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class ProcessRepositoryTest extends ZeebeRepositoryTest { | ||
|
||
@Autowired private ProcessRepository processRepository; | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
processRepository.deleteAll(); | ||
} | ||
|
||
@Test | ||
public void when_process_exists_with_several_versions__then_loaded_only_latest() { | ||
// given | ||
ProcessEntity process1 = createProcess(101L, "A", 1); | ||
ProcessEntity process2 = createProcess(102L, "A", 2); | ||
|
||
// when | ||
processRepository.save(process1); | ||
processRepository.save(process2); | ||
|
||
// then | ||
List<Long> latestVersions = processRepository.findLatestVersions(); | ||
assertThat(latestVersions).containsExactlyInAnyOrder(102L); | ||
} | ||
|
||
private ProcessEntity createProcess(long key, String bpmnProcessId, int version) { | ||
ProcessEntity entity = new ProcessEntity(); | ||
entity.setKey(key); | ||
entity.setBpmnProcessId(bpmnProcessId); | ||
entity.setVersion(version); | ||
entity.setResource("123"); | ||
entity.setTimestamp(456L); | ||
return entity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters