Repository: syncope Updated Branches: refs/heads/master 37b70e661 -> d4ecdf6bd
[SYNCOPE-1112] provide available schema type to better build fiqul expression Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/d4ecdf6b Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/d4ecdf6b Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/d4ecdf6b Branch: refs/heads/master Commit: d4ecdf6bd7ee5a718b148c2b510bbf319b3b04a3 Parents: 37b70e6 Author: fmartelli <fabio.marte...@gmail.com> Authored: Mon Jun 19 15:55:04 2017 +0200 Committer: fmartelli <fabio.marte...@gmail.com> Committed: Mon Jun 19 15:55:04 2017 +0200 ---------------------------------------------------------------------- .../syncope/client/console/panels/AnyPanel.java | 9 ++++-- .../panels/search/AbstractSearchPanel.java | 26 +++++++++++------ .../panels/search/SearchClausePanel.java | 7 +++-- .../console/panels/search/SearchUtils.java | 30 ++++++++++++++------ 4 files changed, 50 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/d4ecdf6b/client/console/src/main/java/org/apache/syncope/client/console/panels/AnyPanel.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/AnyPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/AnyPanel.java index 4b8f9de..dd95128 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/panels/AnyPanel.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/AnyPanel.java @@ -163,19 +163,22 @@ public class AnyPanel extends Panel implements ModalPanel { UserDirectoryPanel.class.cast(AnyPanel.this.directoryPanel).search( precond + SearchUtils.buildFIQL( AnyPanel.this.searchPanel.getModel().getObject(), - SyncopeClient.getUserSearchConditionBuilder()), target); + SyncopeClient.getUserSearchConditionBuilder(), + AnyPanel.this.searchPanel.getAvailableSchemaTypes()), target); break; case GROUP: GroupDirectoryPanel.class.cast(AnyPanel.this.directoryPanel).search( precond + SearchUtils.buildFIQL( AnyPanel.this.searchPanel.getModel().getObject(), - SyncopeClient.getGroupSearchConditionBuilder()), target); + SyncopeClient.getGroupSearchConditionBuilder(), + AnyPanel.this.searchPanel.getAvailableSchemaTypes()), target); break; case ANY_OBJECT: AnyObjectDirectoryPanel.class.cast(AnyPanel.this.directoryPanel).search( precond + SearchUtils.buildFIQL( AnyPanel.this.searchPanel.getModel().getObject(), - SyncopeClient.getAnyObjectSearchConditionBuilder(anyTypeTO.getKey())), target); + SyncopeClient.getAnyObjectSearchConditionBuilder(anyTypeTO.getKey()), + AnyPanel.this.searchPanel.getAvailableSchemaTypes()), target); break; default: } http://git-wip-us.apache.org/repos/asf/syncope/blob/d4ecdf6b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/AbstractSearchPanel.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/search/AbstractSearchPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/AbstractSearchPanel.java index 93ed552..050896f 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/panels/search/AbstractSearchPanel.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/AbstractSearchPanel.java @@ -20,6 +20,7 @@ package org.apache.syncope.client.console.panels.search; import java.io.Serializable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.collections4.CollectionUtils; @@ -29,7 +30,7 @@ import org.apache.syncope.client.console.rest.SchemaRestClient; import org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel; import org.apache.syncope.common.lib.EntityTOUtils; import org.apache.syncope.common.lib.search.SearchableFields; -import org.apache.syncope.common.lib.to.AbstractSchemaTO; +import org.apache.syncope.common.lib.to.PlainSchemaTO; import org.apache.syncope.common.lib.to.ResourceTO; import org.apache.syncope.common.lib.types.AnyTypeKind; import org.apache.syncope.common.lib.types.SchemaType; @@ -56,7 +57,7 @@ public abstract class AbstractSearchPanel extends Panel { protected IModel<List<String>> dnames; - protected IModel<List<String>> anames; + protected IModel<Map<String, PlainSchemaTO>> anames; protected IModel<List<String>> resourceNames; @@ -167,16 +168,21 @@ public abstract class AbstractSearchPanel extends Panel { } }; - anames = new LoadableDetachableModel<List<String>>() { + anames = new LoadableDetachableModel<Map<String, PlainSchemaTO>>() { private static final long serialVersionUID = 5275935387613157437L; @Override - protected List<String> load() { - return CollectionUtils.collect( - schemaRestClient.getSchemas(SchemaType.PLAIN, anyTypeRestClient.read(type).getClasses(). - toArray(new String[] {})), - EntityTOUtils.<AbstractSchemaTO>keyTransformer(), new ArrayList<String>()); + protected Map<String, PlainSchemaTO> load() { + final List<PlainSchemaTO> schemas = schemaRestClient.<PlainSchemaTO>getSchemas( + SchemaType.PLAIN, + anyTypeRestClient.read(type).getClasses().toArray(new String[] {})); + + final Map<String, PlainSchemaTO> res = new HashMap<>(); + for (PlainSchemaTO schema : schemas) { + res.put(schema.getKey(), schema); + } + return res; } }; @@ -199,4 +205,8 @@ public abstract class AbstractSearchPanel extends Panel { public String getBackObjectType() { return this.type; } + + public Map<String, PlainSchemaTO> getAvailableSchemaTypes() { + return anames.getObject(); + } } http://git-wip-us.apache.org/repos/asf/syncope/blob/d4ecdf6b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchClausePanel.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchClausePanel.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchClausePanel.java index 12f9d86..28958ee 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchClausePanel.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchClausePanel.java @@ -40,6 +40,7 @@ import org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxFormCompo import org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel; import org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel; import org.apache.syncope.client.console.wicket.markup.html.form.FieldPanel; +import org.apache.syncope.common.lib.to.PlainSchemaTO; import org.apache.syncope.common.lib.to.RelationshipTypeTO; import org.apache.wicket.AttributeModifier; import org.apache.wicket.Component; @@ -71,7 +72,7 @@ public class SearchClausePanel extends FieldPanel<SearchClause> { private final IModel<List<SearchClause.Type>> types; - private final IModel<List<String>> anames; + private final IModel<Map<String, PlainSchemaTO>> anames; private final IModel<List<String>> dnames; @@ -101,7 +102,7 @@ public class SearchClausePanel extends FieldPanel<SearchClause> { final Model<SearchClause> clause, final boolean required, final IModel<List<SearchClause.Type>> types, - final IModel<List<String>> anames, + final IModel<Map<String, PlainSchemaTO>> anames, final IModel<List<String>> dnames, final IModel<Map<String, String>> groupNames, final IModel<List<String>> roleNames, @@ -194,7 +195,7 @@ public class SearchClausePanel extends FieldPanel<SearchClause> { case ATTRIBUTE: final List<String> names = new ArrayList<>(dnames.getObject()); if (anames != null && anames.getObject() != null && !anames.getObject().isEmpty()) { - names.addAll(anames.getObject()); + names.addAll(anames.getObject().keySet()); } Collections.sort(names); return names; http://git-wip-us.apache.org/repos/asf/syncope/blob/d4ecdf6b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchUtils.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchUtils.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchUtils.java index 4e5181a..4f42e2d 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchUtils.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchUtils.java @@ -20,6 +20,7 @@ package org.apache.syncope.client.console.panels.search; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -38,6 +39,8 @@ import org.apache.syncope.common.lib.search.SyncopeFiqlParser; import org.apache.syncope.common.lib.search.SyncopeFiqlSearchCondition; import org.apache.syncope.common.lib.search.SyncopeProperty; import org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder; +import org.apache.syncope.common.lib.to.PlainSchemaTO; +import org.apache.syncope.common.lib.types.AttrSchemaType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -195,6 +198,13 @@ public final class SearchUtils implements Serializable { } public static String buildFIQL(final List<SearchClause> clauses, final AbstractFiqlSearchConditionBuilder builder) { + return buildFIQL(clauses, builder, Collections.emptyMap()); + } + + public static String buildFIQL( + final List<SearchClause> clauses, + final AbstractFiqlSearchConditionBuilder builder, + final Map<String, PlainSchemaTO> availableSchemaTypes) { LOG.debug("Generating FIQL from List<SearchClause>: {}", clauses); CompleteCondition prevCondition; @@ -249,6 +259,10 @@ public final class SearchUtils implements Serializable { case ATTRIBUTE: if (StringUtils.isNotBlank(clause.getProperty())) { + boolean isLong = availableSchemaTypes.get(clause.getProperty()) != null + && availableSchemaTypes.get(clause.getProperty()).getType() + == AttrSchemaType.Long; + SyncopeProperty property = builder.is(clause.getProperty()); switch (clause.getComparator()) { case IS_NULL: @@ -260,26 +274,26 @@ public final class SearchUtils implements Serializable { break; case LESS_THAN: - condition = StringUtils.isNumeric(clause.getProperty()) - ? property.lessThan(NumberUtils.toDouble(clause.getValue())) + condition = isLong + ? property.lessThan(NumberUtils.toLong(clause.getValue())) : property.lexicalBefore(clause.getValue()); break; case LESS_OR_EQUALS: - condition = StringUtils.isNumeric(clause.getProperty()) - ? property.lessOrEqualTo(NumberUtils.toDouble(clause.getValue())) + condition = isLong + ? property.lessOrEqualTo(NumberUtils.toLong(clause.getValue())) : property.lexicalNotAfter(clause.getValue()); break; case GREATER_THAN: - condition = StringUtils.isNumeric(clause.getProperty()) - ? property.greaterThan(NumberUtils.toDouble(clause.getValue())) + condition = isLong + ? property.greaterThan(NumberUtils.toLong(clause.getValue())) : property.lexicalAfter(clause.getValue()); break; case GREATER_OR_EQUALS: - condition = StringUtils.isNumeric(clause.getProperty()) - ? property.greaterOrEqualTo(NumberUtils.toDouble(clause.getValue())) + condition = isLong + ? property.greaterOrEqualTo(NumberUtils.toLong(clause.getValue())) : property.lexicalNotBefore(clause.getValue()); break;