ilgrosso commented on code in PR #1566:
URL: https://github.com/apache/syncope/pull/1566#discussion_r4236650212


##########
core/persistence-common/src/main/java/org/apache/syncope/core/persistence/common/dao/AbstractAnyMatchDAO.java:
##########
@@ -439,6 +443,31 @@ protected boolean matches(final Any any, final AnyCond 
cond, final boolean not)
 
                 // Deal with any fields representing relationships to other 
entities
                 relationshipFieldMatches(pd, cond, schema);
+                if (!(anyAttrValue instanceof String)) {
+
+                    try {
+                        Method relMethod = null;
+                        if 
(!SyncopeConstants.UUID_PATTERN.matcher(cond.getExpression()).matches()) {
+                            Class<?> type = pd.getPropertyType();
+
+                            if (type == Realm.class) {

Review Comment:
   prefer `isAssignableFrom`



##########
core/persistence-common/src/main/java/org/apache/syncope/core/persistence/common/dao/AbstractAnyMatchDAO.java:
##########
@@ -439,6 +443,31 @@ protected boolean matches(final Any any, final AnyCond 
cond, final boolean not)
 
                 // Deal with any fields representing relationships to other 
entities
                 relationshipFieldMatches(pd, cond, schema);
+                if (!(anyAttrValue instanceof String)) {
+
+                    try {
+                        Method relMethod = null;
+                        if 
(!SyncopeConstants.UUID_PATTERN.matcher(cond.getExpression()).matches()) {
+                            Class<?> type = pd.getPropertyType();
+
+                            if (type == Realm.class) {
+                                relMethod = 
ClassUtils.getPublicMethod(pd.getPropertyType(), "getFullPath");
+                            } else if (type == User.class) {
+                                relMethod = 
ClassUtils.getPublicMethod(pd.getPropertyType(), "getUsername");
+                            } else if (type == Group.class) {
+                                relMethod = 
ClassUtils.getPublicMethod(pd.getPropertyType(), "getName");
+                            }
+                        } else {
+                            relMethod = 
ClassUtils.getPublicMethod(pd.getPropertyType(), "getKey", new Class<?>[0]);
+                        }
+
+                        if (relMethod != null && 
String.class.isAssignableFrom(relMethod.getReturnType())) {
+                            anyAttrValue = relMethod.invoke(anyAttrValue);
+                        }
+                    } catch (NoSuchMethodException | InvocationTargetException 
| IllegalAccessException e) {
+                        throw new RuntimeException(e);

Review Comment:
   Avoid throw unchecked exception with even no message.
   
   You could just log something like:
   
   ```
   LOG.error("Could not find ....", e);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to