[SYNCOPE-1252] fix the search feature + improve autocompletion for property field
authorfmartelli <fabio.martelli@gmail.com>
Mon, 18 Dec 2017 19:21:37 +0000 (20:21 +0100)
committerfmartelli <fabio.martelli@gmail.com>
Mon, 18 Dec 2017 19:26:03 +0000 (20:26 +0100)
client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchClausePanel.java
client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchUtils.java

index 6b92e12..745688e 100644 (file)
@@ -389,52 +389,43 @@ public class SearchClausePanel extends FieldPanel<SearchClause> {
                 }
 
                 if (field.getModel().getObject().getType() == Type.GROUP_MEMBERSHIP) {
-                    target.focusComponent(null);
-                    property.getField().inputChanged();
-                    property.getField().validate();
-                    if (property.getField().isValid()) {
-                        property.getField().valid();
-                        property.getField().updateModel();
-                        String[] inputAsArray = property.getField().getInputAsArray();
-
-                        if (StringUtils.isBlank(property.getField().getInput())
-                                || inputAsArray.length == 0) {
-                            property.setChoices(properties.getObject());
-                        } else {
-                            String inputValue = (inputAsArray.length > 1 && inputAsArray[1] != null)
-                                    ? inputAsArray[1]
-                                    : property.getField().getInput();
-                            inputValue = (inputValue.startsWith("*") && !inputValue.endsWith("*"))
-                                    ? inputValue + "*"
-                                    : (!inputValue.startsWith("*") && inputValue.endsWith("*"))
-                                    ? "*" + inputValue
-                                    : (inputValue.startsWith("*") && inputValue.endsWith("*")
-                                    ? inputValue : "*" + inputValue + "*");
-
-                            if (groupInfo.getRight() > AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY) {
-                                List<GroupTO> filteredGroups =
-                                        groupRestClient.search("/",
-                                                SyncopeClient.getGroupSearchConditionBuilder().
-                                                        is("name").equalToIgnoreCase(inputValue).
-                                                        query(),
-                                                1,
-                                                AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY,
-                                                new SortParam<>("name", true),
-                                                null);
-                                Collection<String> newList =
-                                        CollectionUtils.collect(filteredGroups,
-                                                new Transformer<GroupTO, String>() {
-
-                                            @Override
-                                            public String transform(final GroupTO input) {
-                                                return input.getName();
-                                            }
-                                        });
-
-                                final List<String> names = new ArrayList<>(newList);
-                                Collections.sort(names);
-                                property.setChoices(names);
-                            }
+                    String[] inputAsArray = property.getField().getInputAsArray();
+
+                    if (StringUtils.isBlank(property.getField().getInput())
+                            || inputAsArray.length == 0) {
+                        property.setChoices(properties.getObject());
+                    } else {
+                        String inputValue = (inputAsArray.length > 1 && inputAsArray[1] != null)
+                                ? inputAsArray[1]
+                                : property.getField().getInput();
+                        inputValue = (inputValue.startsWith("*") && !inputValue.endsWith("*"))
+                                ? inputValue + "*"
+                                : (!inputValue.startsWith("*") && inputValue.endsWith("*"))
+                                ? "*" + inputValue
+                                : (inputValue.startsWith("*") && inputValue.endsWith("*")
+                                ? inputValue : "*" + inputValue + "*");
+
+                        if (groupInfo.getRight() > AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY) {
+                            List<GroupTO> filteredGroups = groupRestClient.search("/",
+                                    SyncopeClient.getGroupSearchConditionBuilder().
+                                            is("name").equalToIgnoreCase(inputValue).
+                                            query(),
+                                    1,
+                                    AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY,
+                                    new SortParam<>("name", true),
+                                    null);
+                            Collection<String> newList = CollectionUtils.collect(filteredGroups,
+                                    new Transformer<GroupTO, String>() {
+
+                                @Override
+                                public String transform(final GroupTO input) {
+                                    return input.getName();
+                                }
+                            });
+
+                            final List<String> names = new ArrayList<>(newList);
+                            Collections.sort(names);
+                            property.setChoices(names);
                         }
                     }
                 }
@@ -443,9 +434,16 @@ public class SearchClausePanel extends FieldPanel<SearchClause> {
             @Override
             protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
                 super.updateAjaxAttributes(attributes);
-
                 attributes.getAjaxCallListeners().clear();
             }
+        }, new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
+
+            private static final long serialVersionUID = -1107858522700306810L;
+
+            @Override
+            protected void onUpdate(final AjaxRequestTarget target) {
+
+            }
         });
 
         final AjaxDropDownChoicePanel<SearchClause.Comparator> comparator = new AjaxDropDownChoicePanel<>(
@@ -513,7 +511,11 @@ public class SearchClausePanel extends FieldPanel<SearchClause> {
                 SearchClausePanel.this.clause.setObject(searchClause);
 
                 setFieldAccess(searchClause.getType(), property, comparator, value);
+
+                // reset property value in case and just in case of change of type
+                property.setModelObject(StringUtils.EMPTY);
                 target.add(property);
+
                 target.add(comparator);
                 target.add(value);
             }
@@ -606,7 +608,7 @@ public class SearchClausePanel extends FieldPanel<SearchClause> {
                 case GROUP_MEMBER:
                     value.setEnabled(true);
                     property.setEnabled(false);
-                    property.setModelObject(null);
+                    property.setModelObject(StringUtils.EMPTY);
                     break;
 
                 case RESOURCE:
index 68ac17f..80fa692 100644 (file)
@@ -259,9 +259,14 @@ 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;
+                            boolean isLong = false;
+                            boolean isDouble = false;
+                            if (availableSchemaTypes.get(clause.getProperty()) != null) {
+                                isLong = availableSchemaTypes.get(clause.getProperty()).getType()
+                                        == AttrSchemaType.Long;
+                                isDouble = availableSchemaTypes.get(clause.getProperty()).getType()
+                                        == AttrSchemaType.Double;
+                            }
 
                             SyncopeProperty property = builder.is(clause.getProperty());
                             switch (clause.getComparator()) {
@@ -276,25 +281,33 @@ public final class SearchUtils implements Serializable {
                                 case LESS_THAN:
                                     condition = isLong
                                             ? property.lessThan(NumberUtils.toLong(value))
-                                            : property.lexicalBefore(value);
+                                            : isDouble
+                                                    ? property.lessThan(NumberUtils.toDouble(value))
+                                                    : property.lexicalBefore(value);
                                     break;
 
                                 case LESS_OR_EQUALS:
                                     condition = isLong
                                             ? property.lessOrEqualTo(NumberUtils.toLong(value))
-                                            : property.lexicalNotAfter(value);
+                                            : isDouble
+                                                    ? property.lessOrEqualTo(NumberUtils.toDouble(value))
+                                                    : property.lexicalNotAfter(value);
                                     break;
 
                                 case GREATER_THAN:
                                     condition = isLong
                                             ? property.greaterThan(NumberUtils.toLong(value))
-                                            : property.lexicalAfter(value);
+                                            : isDouble
+                                                    ? property.greaterThan(NumberUtils.toDouble(value))
+                                                    : property.lexicalAfter(value);
                                     break;
 
                                 case GREATER_OR_EQUALS:
                                     condition = isLong
                                             ? property.greaterOrEqualTo(NumberUtils.toLong(value))
-                                            : property.lexicalNotBefore(value);
+                                            : isDouble
+                                                    ? property.greaterOrEqualTo(NumberUtils.toDouble(value))
+                                                    : property.lexicalNotBefore(value);
                                     break;
 
                                 case NOT_EQUALS:
@@ -302,6 +315,12 @@ public final class SearchUtils implements Serializable {
                                     break;
 
                                 case EQUALS:
+                                    condition = isLong
+                                            ? property.equalTo(NumberUtils.toLong(value))
+                                            : isDouble
+                                                    ? property.equalTo(NumberUtils.toDouble(value))
+                                                    : property.equalToIgnoreCase(value);
+                                    break;
                                 default:
                                     condition = property.equalToIgnoreCase(value);
                                     break;