This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 3_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/3_0_X by this push:
new eb81536c69 Fixing ISNULL search condition with pgjsonb
eb81536c69 is described below
commit eb81536c696887d5442ccefab0020977c2534cfd
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Tue Nov 21 16:52:34 2023 +0100
Fixing ISNULL search condition with pgjsonb
---
.../core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java | 7 ++++---
.../core/persistence/jpa/inner/AnySearchTest.java | 17 +++++++++++++++++
.../java/org/apache/syncope/fit/core/SearchITCase.java | 8 ++++++++
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git
a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
index 1989bf5802..b8c7f3d603 100644
---
a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
+++
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
@@ -788,7 +788,7 @@ public class PGJPAJSONAnySearchDAO extends JPAAnySearchDAO {
switch (cond.getType()) {
case ISNULL:
- // shouldn't occour: processed before
+ query.append(column).append(" IS NULL");
break;
case ISNOTNULL:
@@ -816,8 +816,9 @@ public class PGJPAJSONAnySearchDAO extends JPAAnySearchDAO {
query.append(column);
query.append('=');
- if ((schema.getType() == AttrSchemaType.String
- || schema.getType() == AttrSchemaType.Enum) &&
lower) {
+ if (lower
+ && (schema.getType() == AttrSchemaType.String ||
schema.getType() == AttrSchemaType.Enum)) {
+
query.append("LOWER(?").append(setParameter(parameters,
attrValue.getValue())).append(')');
} else {
query.append('?').append(setParameter(parameters,
attrValue.getValue()));
diff --git
a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AnySearchTest.java
b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AnySearchTest.java
index 1fff8d5176..0ace0bd550 100644
---
a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AnySearchTest.java
+++
b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AnySearchTest.java
@@ -686,6 +686,23 @@ public class AnySearchTest extends AbstractTest {
}
}
+ @Test
+ public void changePwdDate() {
+ AnyCond statusCond = new AnyCond(AttrCond.Type.IEQ);
+ statusCond.setSchema("status");
+ statusCond.setExpression("suspended");
+
+ AnyCond changePwdDateCond = new AnyCond(AttrCond.Type.ISNULL);
+ changePwdDateCond.setSchema("changePwdDate");
+
+ SearchCond cond = SearchCond.getAnd(SearchCond.getNotLeaf(statusCond),
SearchCond.getLeaf(changePwdDateCond));
+ assertTrue(cond.isValid());
+
+ List<User> users = searchDAO.search(cond, AnyTypeKind.USER);
+ assertNotNull(users);
+ assertEquals(5, users.size());
+ }
+
@Test
public void issue202() {
ResourceCond ws2 = new ResourceCond();
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
index baee67fc90..c813105a87 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
@@ -614,6 +614,14 @@ public class SearchITCase extends AbstractITCase {
anyMatch(connObject ->
connObject.getAttr("homePhone").isEmpty()));
}
+ @Test
+ public void changePwdDate() {
+ int users = USER_SERVICE.search(new
AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
+ fiql("status!~suspended;changePwdDate==$null").build()).
+ getTotalCount();
+ assertTrue(users > 0);
+ }
+
@Test
public void issueSYNCOPE768() {
int usersWithNullable = USER_SERVICE.search(new
AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).