Skip to content

Commit 1e049d6

Browse files
committed
extended search and fixed '[' issue
1 parent b65261b commit 1e049d6

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

core/src/main/java/org/sterl/spring/persistent_tasks/shared/StringHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class StringHelper {
99
*/
1010
public static String applySearchWildCard(String value) {
1111
if (value == null || value.length() == 0) return null;
12-
return value.replace('*', '%');
12+
return value.replace('*', '%').replace('[', '_');
1313
}
1414

1515
/**

core/src/main/java/org/sterl/spring/persistent_tasks/shared/repository/TriggerDataRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
public interface TriggerDataRepository<T extends HasTriggerData> extends JpaRepository<T, Long> {
1919
@Query("""
2020
SELECT e FROM #{#entityName} e
21-
WHERE (e.data.key.id LIKE :id OR :id IS NULL)
22-
AND (e.data.key.taskName = :taskName OR :taskName IS NULL)
23-
AND (e.data.status = :status OR :status IS NULL)
21+
WHERE (:id IS NULL OR e.data.key.id LIKE :id)
22+
AND (:taskName IS NULL OR e.data.key.taskName = :taskName)
23+
AND (:status IS NULL OR e.data.status = :status)
2424
""")
2525
Page<T> findAll(@Param("id") String id,
2626
@Param("taskName") String taskName,

core/src/test/java/org/sterl/spring/persistent_tasks/trigger/api/TriggerResourceTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,24 @@ void testSearchById() {
7575

7676
// WHEN
7777
var response = template.exchange(
78-
baseUrl + "?id=" + key1.getId().substring(0, 30) + "*",
78+
baseUrl + "?id=*" + key2.getId().substring(5, 30) + "*",
7979
HttpMethod.GET,
8080
null,
8181
String.class);
82-
8382
// THEN
84-
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
85-
assertThat(response.getBody()).isNotNull();
86-
assertThat(response.getBody()).contains(key1.getId());
87-
assertThat(response.getBody()).doesNotContain(key2.getId());
83+
assertThat(response.getBody()).contains(key2.getId());
84+
assertThat(response.getBody()).doesNotContain(key1.getId());
8885

8986
// WHEN
9087
response = template.exchange(
91-
baseUrl + "?id=*" + key1.getId().substring(10, 30) + "*",
88+
baseUrl + "?id=" + key1.getId().substring(0, 30) + "*",
9289
HttpMethod.GET,
9390
null,
9491
String.class);
92+
93+
// THEN
94+
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
95+
assertThat(response.getBody()).isNotNull();
9596
assertThat(response.getBody()).contains(key1.getId());
9697
assertThat(response.getBody()).doesNotContain(key2.getId());
9798
}

core/src/test/resources/application-mssql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ spring:
88
maximum-pool-size: 100
99
jpa:
1010
hibernate:
11-
ddl-auto: none
11+
ddl-auto: none

0 commit comments

Comments
 (0)