You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by fm...@apache.org on 2016/09/07 10:56:03 UTC
syncope git commit: [SYNCOPE-935] provides fix for all attributes
referring to JPA entities + hides realm,
type and udynMembershipCond attributes among the available ones to be used to
create search queries
Repository: syncope
Updated Branches:
refs/heads/master ef5784b1e -> bbee3af76
[SYNCOPE-935] provides fix for all attributes referring to JPA entities + hides realm, type and udynMembershipCond attributes among the available ones to be used to create search queries
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/bbee3af7
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/bbee3af7
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/bbee3af7
Branch: refs/heads/master
Commit: bbee3af7676bf566554bfb429191002890d1b577
Parents: ef5784b
Author: fmartelli <fa...@gmail.com>
Authored: Wed Sep 7 12:55:45 2016 +0200
Committer: fmartelli <fa...@gmail.com>
Committed: Wed Sep 7 12:55:45 2016 +0200
----------------------------------------------------------------------
.../common/lib/search/SearchableFields.java | 2 +-
.../persistence/jpa/dao/JPAAnySearchDAO.java | 35 +++++++++-----------
2 files changed, 17 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/bbee3af7/common/lib/src/main/java/org/apache/syncope/common/lib/search/SearchableFields.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/search/SearchableFields.java b/common/lib/src/main/java/org/apache/syncope/common/lib/search/SearchableFields.java
index 9f67cee..b4facfe 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/search/SearchableFields.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/search/SearchableFields.java
@@ -36,7 +36,7 @@ import org.apache.syncope.common.lib.types.AnyTypeKind;
public final class SearchableFields {
private static final String[] ATTRIBUTES_NOTINCLUDED = {
- "serialVersionUID", "password"
+ "serialVersionUID", "password", "type", "realm", "udynMembershipCond"
};
private static final Set<String> ANY_FIELDS = new HashSet<>();
http://git-wip-us.apache.org/repos/asf/syncope/blob/bbee3af7/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
index cc73bd4..745d82a 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
@@ -35,6 +35,7 @@ import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ClassUtils;
+import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.types.AnyTypeKind;
@@ -885,16 +886,18 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?>> implements AnySearchDAO
private String getQuery(final AnyCond cond, final boolean not, final List<Object> parameters,
final SearchSupport svs) {
+ AnyCond condClone = SerializationUtils.clone(cond);
+
AnyUtils attrUtils = anyUtilsFactory.getInstance(svs.anyTypeKind());
// Keeps track of difference between entity's getKey() and JPA @Id fields
- if ("key".equals(cond.getSchema())) {
- cond.setSchema("id");
+ if ("key".equals(condClone.getSchema())) {
+ condClone.setSchema("id");
}
- Field anyField = ReflectionUtils.findField(attrUtils.anyClass(), cond.getSchema());
+ Field anyField = ReflectionUtils.findField(attrUtils.anyClass(), condClone.getSchema());
if (anyField == null) {
- LOG.warn("Ignoring invalid schema '{}'", cond.getSchema());
+ LOG.warn("Ignoring invalid schema '{}'", condClone.getSchema());
return EMPTY_QUERY;
}
@@ -931,27 +934,21 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?>> implements AnySearchDAO
LOG.error("Could not find {}#getKey", anyField.getType(), e);
}
- if (relMethod != null) {
- if (Long.class.isAssignableFrom(relMethod.getReturnType())) {
- cond.setSchema(cond.getSchema() + "_id");
- schema.setType(AttrSchemaType.Long);
- }
- if (String.class.isAssignableFrom(relMethod.getReturnType())) {
- cond.setSchema(cond.getSchema() + "_id");
- schema.setType(AttrSchemaType.String);
- }
+ if (relMethod != null && String.class.isAssignableFrom(relMethod.getReturnType())) {
+ condClone.setSchema(condClone.getSchema() + "_id");
+ schema.setType(AttrSchemaType.String);
}
}
PlainAttrValue attrValue = attrUtils.newPlainAttrValue();
- if (cond.getType() != AttributeCond.Type.LIKE
- && cond.getType() != AttributeCond.Type.ISNULL
- && cond.getType() != AttributeCond.Type.ISNOTNULL) {
+ if (condClone.getType() != AttributeCond.Type.LIKE
+ && condClone.getType() != AttributeCond.Type.ISNULL
+ && condClone.getType() != AttributeCond.Type.ISNOTNULL) {
try {
- schema.getValidator().validate(cond.getExpression(), attrValue);
+ schema.getValidator().validate(condClone.getExpression(), attrValue);
} catch (ValidationException e) {
- LOG.error("Could not validate expression '" + cond.getExpression() + "'", e);
+ LOG.error("Could not validate expression '" + condClone.getExpression() + "'", e);
return EMPTY_QUERY;
}
}
@@ -959,7 +956,7 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?>> implements AnySearchDAO
StringBuilder query = new StringBuilder("SELECT DISTINCT any_id FROM ").
append(svs.field().name).append(" WHERE ");
- fillAttributeQuery(query, attrValue, schema, cond, not, parameters, svs);
+ fillAttributeQuery(query, attrValue, schema, condClone, not, parameters, svs);
return query.toString();
}