syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [2/2] syncope git commit: [SYNCOPE-1077] Applying some ES best practices
Date Wed, 17 May 2017 12:16:24 GMT
[SYNCOPE-1077] Applying some ES best practices


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/29b97d7f
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/29b97d7f
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/29b97d7f

Branch: refs/heads/master
Commit: 29b97d7f91a318d8c840350cf6cfc1dd8961cc0c
Parents: cbd1083
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Wed May 17 14:15:51 2017 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Wed May 17 14:16:09 2017 +0200

----------------------------------------------------------------------
 .../wicket/markup/html/form/ActionPanel.java    |  2 -
 .../client/console/widgets/JobWidget.java       |  2 -
 .../core/persistence/api/dao/AnyObjectDAO.java  |  2 +-
 .../persistence/jpa/dao/JPAAnyObjectDAO.java    |  4 +-
 .../core/persistence/jpa/dao/JPAGroupDAO.java   |  2 -
 .../core/persistence/jpa/dao/JPAUserDAO.java    |  2 -
 .../spring/event/AnyCreatedUpdatedEvent.java    |  8 +++
 .../core/spring/event/AnyDeletedEvent.java      |  9 ++++
 .../console/rest/CamelRoutesRestClient.java     |  2 -
 .../client/ElasticsearchIndexManager.java       | 10 ++--
 .../client/ElasticsearchUtils.java              | 38 ++++++++-----
 .../resources/elasticsearchClientContext.xml    |  1 +
 .../jpa/dao/ElasticsearchAnySearchDAO.java      | 57 ++++++++------------
 .../java/job/ElasticsearchReindex.java          | 37 ++++++++++++-
 .../client/console/panels/ImportMetadata.java   |  2 -
 .../validation/entity/SAML2IdPValidator.java    |  2 -
 .../syncope/fit/ElasticsearchDetector.java      | 29 ++++++++++
 .../syncope/fit/console/BulkActionITCase.java   |  1 -
 .../syncope/fit/console/GroupsITCase.java       |  1 -
 .../syncope/fit/console/PoliciesITCase.java     |  1 -
 .../syncope/fit/console/RealmsITCase.java       |  1 -
 .../fit/console/SecurityQuestionsITCase.java    |  1 -
 .../apache/syncope/fit/core/SearchITCase.java   | 25 +++++++++
 23 files changed, 162 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/ActionPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/ActionPanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/ActionPanel.java
index e7f2f04..4e39205 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/ActionPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/ActionPanel.java
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.client.console.wicket.markup.html.form;
 
-import static org.apache.wicket.Component.RENDER;
-
 import java.io.Serializable;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.client.console.SyncopeConsoleSession;

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/client/console/src/main/java/org/apache/syncope/client/console/widgets/JobWidget.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/widgets/JobWidget.java
b/client/console/src/main/java/org/apache/syncope/client/console/widgets/JobWidget.java
index aadd49c..c7839ca 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/widgets/JobWidget.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/widgets/JobWidget.java
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.client.console.widgets;
 
-import static org.apache.wicket.Component.ENABLE;
-
 import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
 import de.agilecoders.wicket.core.markup.html.bootstrap.tabs.AjaxBootstrapTabbedPanel;
 import java.io.Serializable;

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/AnyObjectDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/AnyObjectDAO.java
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/AnyObjectDAO.java
index 650130c..448aca6 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/AnyObjectDAO.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/AnyObjectDAO.java
@@ -45,7 +45,7 @@ public interface AnyObjectDAO extends AnyDAO<AnyObject> {
 
     List<Group> findDynGroups(AnyObject anyObject);
 
-    List<ARelationship> findAllARelationships(AnyObject anyObject);
+    List<ARelationship> findAllRelationships(AnyObject anyObject);
 
     Collection<Group> findAllGroups(AnyObject anyObject);
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
index 23234b3..c22112f 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.core.persistence.jpa.dao;
 
-import static org.apache.syncope.core.persistence.jpa.dao.AbstractDAO.LOG;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -179,7 +177,7 @@ public class JPAAnyObjectDAO extends AbstractAnyDAO<AnyObject> implements
AnyObj
     }
 
     @Override
-    public List<ARelationship> findAllARelationships(final AnyObject anyObject) {
+    public List<ARelationship> findAllRelationships(final AnyObject anyObject) {
         TypedQuery<ARelationship> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAARelationship.class.getSimpleName()
                 + " e WHERE e.rightEnd=:anyObject OR e.leftEnd=:anyObject", ARelationship.class);

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAGroupDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAGroupDAO.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAGroupDAO.java
index 93ceddc..f7da117 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAGroupDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAGroupDAO.java
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.core.persistence.jpa.dao;
 
-import static org.apache.syncope.core.persistence.jpa.dao.AbstractDAO.LOG;
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java
index 92b94fb..bea305a 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.core.persistence.jpa.dao;
 
-import static org.apache.syncope.core.persistence.jpa.dao.AbstractDAO.LOG;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/core/spring/src/main/java/org/apache/syncope/core/spring/event/AnyCreatedUpdatedEvent.java
----------------------------------------------------------------------
diff --git a/core/spring/src/main/java/org/apache/syncope/core/spring/event/AnyCreatedUpdatedEvent.java
b/core/spring/src/main/java/org/apache/syncope/core/spring/event/AnyCreatedUpdatedEvent.java
index c252744..f71e59c 100644
--- a/core/spring/src/main/java/org/apache/syncope/core/spring/event/AnyCreatedUpdatedEvent.java
+++ b/core/spring/src/main/java/org/apache/syncope/core/spring/event/AnyCreatedUpdatedEvent.java
@@ -19,6 +19,7 @@
 package org.apache.syncope.core.spring.event;
 
 import org.apache.syncope.core.persistence.api.entity.Any;
+import org.apache.syncope.core.spring.security.AuthContextUtils;
 import org.springframework.context.ApplicationEvent;
 
 public class AnyCreatedUpdatedEvent<A extends Any<?>> extends ApplicationEvent
{
@@ -27,13 +28,20 @@ public class AnyCreatedUpdatedEvent<A extends Any<?>> extends
ApplicationEvent {
 
     private final A any;
 
+    private final String domain;
+
     public AnyCreatedUpdatedEvent(final Object source, final A any) {
         super(source);
         this.any = any;
+        this.domain = AuthContextUtils.getDomain();
     }
 
     public A getAny() {
         return any;
     }
 
+    public String getDomain() {
+        return domain;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/core/spring/src/main/java/org/apache/syncope/core/spring/event/AnyDeletedEvent.java
----------------------------------------------------------------------
diff --git a/core/spring/src/main/java/org/apache/syncope/core/spring/event/AnyDeletedEvent.java
b/core/spring/src/main/java/org/apache/syncope/core/spring/event/AnyDeletedEvent.java
index bd180de..8d33609 100644
--- a/core/spring/src/main/java/org/apache/syncope/core/spring/event/AnyDeletedEvent.java
+++ b/core/spring/src/main/java/org/apache/syncope/core/spring/event/AnyDeletedEvent.java
@@ -19,18 +19,24 @@
 package org.apache.syncope.core.spring.event;
 
 import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.core.spring.security.AuthContextUtils;
 import org.springframework.context.ApplicationEvent;
 
 public class AnyDeletedEvent extends ApplicationEvent {
 
+    private static final long serialVersionUID = 6389886937942135639L;
+
     private final AnyTypeKind anyTypeKind;
 
     private final String anyKey;
 
+    private final String domain;
+
     public AnyDeletedEvent(final Object source, final AnyTypeKind anyTypeKind, final String
anyKey) {
         super(source);
         this.anyTypeKind = anyTypeKind;
         this.anyKey = anyKey;
+        this.domain = AuthContextUtils.getDomain();
     }
 
     public AnyTypeKind getAnyTypeKind() {
@@ -41,4 +47,7 @@ public class AnyDeletedEvent extends ApplicationEvent {
         return anyKey;
     }
 
+    public String getDomain() {
+        return domain;
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/rest/CamelRoutesRestClient.java
----------------------------------------------------------------------
diff --git a/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/rest/CamelRoutesRestClient.java
b/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/rest/CamelRoutesRestClient.java
index 70e523d..92d6118 100644
--- a/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/rest/CamelRoutesRestClient.java
+++ b/ext/camel/client-console/src/main/java/org/apache/syncope/client/console/rest/CamelRoutesRestClient.java
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.client.console.rest;
 
-import static org.apache.syncope.client.console.rest.BaseRestClient.getService;
-
 import java.util.Collections;
 import java.util.List;
 import org.apache.syncope.client.console.SyncopeConsoleSession;

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchIndexManager.java
----------------------------------------------------------------------
diff --git a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchIndexManager.java
b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchIndexManager.java
index 3e20acd..1352f9e 100644
--- a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchIndexManager.java
+++ b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchIndexManager.java
@@ -26,7 +26,6 @@ import org.apache.syncope.core.spring.security.AuthContextUtils;
 import org.elasticsearch.action.delete.DeleteResponse;
 import org.elasticsearch.action.get.GetResponse;
 import org.elasticsearch.action.index.IndexResponse;
-import org.elasticsearch.action.support.WriteRequest;
 import org.elasticsearch.action.update.UpdateResponse;
 import org.elasticsearch.client.Client;
 import org.slf4j.Logger;
@@ -35,7 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.event.TransactionalEventListener;
 
 /**
- * Listen to any create / update and delete in order to keep the Elastsicsearch indexes consistent.
+ * Listen to any create / update and delete in order to keep the Elasticsearch indexes consistent.
  */
 public class ElasticsearchIndexManager {
 
@@ -60,8 +59,8 @@ public class ElasticsearchIndexManager {
                     AuthContextUtils.getDomain().toLowerCase(),
                     event.getAny().getType().getKind().name(),
                     event.getAny().getKey()).
+                    setRetryOnConflict(elasticsearchUtils.getRetryOnConflict()).
                     setDoc(elasticsearchUtils.builder(event.getAny())).
-                    setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).
                     get();
             LOG.debug("Index successfully updated for {}: {}", event.getAny(), response);
         } else {
@@ -72,7 +71,6 @@ public class ElasticsearchIndexManager {
                     event.getAny().getType().getKind().name(),
                     event.getAny().getKey()).
                     setSource(elasticsearchUtils.builder(event.getAny())).
-                    setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).
                     get();
 
             LOG.debug("Index successfully created for {}: {}", event.getAny(), response);
@@ -87,9 +85,9 @@ public class ElasticsearchIndexManager {
                 AuthContextUtils.getDomain().toLowerCase(),
                 event.getAnyTypeKind().name(),
                 event.getAnyKey()).
-                setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).
                 get();
 
-        LOG.debug("Index successfully deleted for {}[{}]: {}", event.getAnyTypeKind(), event.getAnyKey(),
response);
+        LOG.debug("Index successfully deleted for {}[{}]: {}",
+                event.getAnyTypeKind(), event.getAnyKey(), response);
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
----------------------------------------------------------------------
diff --git a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
index 1d22a1e..1ff146e 100644
--- a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
+++ b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
@@ -61,6 +61,8 @@ public class ElasticsearchUtils {
 
     private int indexMaxResultWindow = 10000;
 
+    private int retryOnConflict = 5;
+
     public void setIndexMaxResultWindow(final int indexMaxResultWindow) {
         this.indexMaxResultWindow = indexMaxResultWindow;
     }
@@ -69,6 +71,14 @@ public class ElasticsearchUtils {
         return indexMaxResultWindow;
     }
 
+    public void setRetryOnConflict(final int retryOnConflict) {
+        this.retryOnConflict = retryOnConflict;
+    }
+
+    public int getRetryOnConflict() {
+        return retryOnConflict;
+    }
+
     /**
      * Returns the builder specialized with content from the provided any.
      *
@@ -104,7 +114,7 @@ public class ElasticsearchUtils {
 
             List<Object> relationships = new ArrayList<>();
             List<Object> relationshipTypes = new ArrayList<>();
-            for (ARelationship relationship : anyObjectDAO.findAllARelationships(anyObject))
{
+            for (ARelationship relationship : anyObjectDAO.findAllRelationships(anyObject))
{
                 relationships.add(relationship.getRightEnd().getKey());
                 relationshipTypes.add(relationship.getType().getKey());
             }
@@ -164,20 +174,22 @@ public class ElasticsearchUtils {
             builder = builder.field("relationshipTypes", relationshipTypes);
         }
 
-        for (PlainAttr<?> plainAttr : any.getPlainAttrs()) {
-            List<Object> values = CollectionUtils.collect(plainAttr.getValues(),
-                    new Transformer<PlainAttrValue, Object>() {
-
-                @Override
-                public Object transform(final PlainAttrValue input) {
-                    return input.getValue();
+        if (any.getPlainAttrs() != null) {
+            for (PlainAttr<?> plainAttr : any.getPlainAttrs()) {
+                List<Object> values = CollectionUtils.collect(plainAttr.getValues(),
+                        new Transformer<PlainAttrValue, Object>() {
+
+                    @Override
+                    public Object transform(final PlainAttrValue input) {
+                        return input.getValue();
+                    }
+                }, new ArrayList<>(plainAttr.getValues().size()));
+                if (plainAttr.getUniqueValue() != null) {
+                    values.add(plainAttr.getUniqueValue().getValue());
                 }
-            }, new ArrayList<>(plainAttr.getValues().size()));
-            if (plainAttr.getUniqueValue() != null) {
-                values.add(plainAttr.getUniqueValue().getValue());
-            }
 
-            builder = builder.field(plainAttr.getSchema().getKey(), values);
+                builder = builder.field(plainAttr.getSchema().getKey(), values);
+            }
         }
 
         builder = builder.endObject();

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/ext/elasticsearch/client-elasticsearch/src/main/resources/elasticsearchClientContext.xml
----------------------------------------------------------------------
diff --git a/ext/elasticsearch/client-elasticsearch/src/main/resources/elasticsearchClientContext.xml
b/ext/elasticsearch/client-elasticsearch/src/main/resources/elasticsearchClientContext.xml
index ed8a319..347e48d 100644
--- a/ext/elasticsearch/client-elasticsearch/src/main/resources/elasticsearchClientContext.xml
+++ b/ext/elasticsearch/client-elasticsearch/src/main/resources/elasticsearchClientContext.xml
@@ -44,6 +44,7 @@ under the License.
   
   <bean class="org.apache.syncope.ext.elasticsearch.client.ElasticsearchUtils">
     <property name="indexMaxResultWindow" value="10000"/>
+    <property name="retryOnConflict" value="5"/>
   </bean>
   <bean class="org.apache.syncope.ext.elasticsearch.client.ElasticsearchIndexManager"/>
   

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/ext/elasticsearch/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/ElasticsearchAnySearchDAO.java
----------------------------------------------------------------------
diff --git a/ext/elasticsearch/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/ElasticsearchAnySearchDAO.java
b/ext/elasticsearch/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/ElasticsearchAnySearchDAO.java
index 0675254..0318bc5 100644
--- a/ext/elasticsearch/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/ElasticsearchAnySearchDAO.java
+++ b/ext/elasticsearch/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/ElasticsearchAnySearchDAO.java
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.core.persistence.jpa.dao;
 
-import static org.apache.syncope.core.persistence.jpa.dao.AbstractDAO.LOG;
-
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -86,7 +84,7 @@ public class ElasticsearchAnySearchDAO extends AbstractAnySearchDAO {
                 LOG.warn("Ignoring invalid realm {}", realmPath);
             } else {
                 for (Realm descendant : realmDAO.findDescendants(realm)) {
-                    builder.add(QueryBuilders.termQuery("realm.keyword", descendant.getFullPath()));
+                    builder.add(QueryBuilders.termQuery("realm", descendant.getFullPath()));
                 }
             }
         }
@@ -134,15 +132,10 @@ public class ElasticsearchAnySearchDAO extends AbstractAnySearchDAO
{
             if (anyField == null) {
                 PlainSchema schema = schemaDAO.find(fieldName);
                 if (schema != null) {
-                    sortName = schema.getType() == AttrSchemaType.String
-                            || schema.getType() == AttrSchemaType.Enum
-                            ? fieldName + ".keyword"
-                            : fieldName;
+                    sortName = fieldName;
                 }
             } else {
-                sortName = anyField.getType().equals(String.class)
-                        ? fieldName + ".keyword"
-                        : fieldName;
+                sortName = fieldName;
             }
 
             if (sortName == null) {
@@ -240,11 +233,11 @@ public class ElasticsearchAnySearchDAO extends AbstractAnySearchDAO
{
     }
 
     private QueryBuilder getQueryBuilder(final AnyTypeCond cond) {
-        return QueryBuilders.termQuery("anyType.keyword", cond.getAnyTypeKey());
+        return QueryBuilders.termQuery("anyType", cond.getAnyTypeKey());
     }
 
     private QueryBuilder getQueryBuilder(final RelationshipTypeCond cond) {
-        return QueryBuilders.termQuery("relationshipTypes.keyword", cond.getRelationshipTypeKey());
+        return QueryBuilders.termQuery("relationshipTypes", cond.getRelationshipTypeKey());
     }
 
     private QueryBuilder getQueryBuilder(final RelationshipCond cond) {
@@ -255,7 +248,7 @@ public class ElasticsearchAnySearchDAO extends AbstractAnySearchDAO {
             return EMPTY_QUERY_BUILDER;
         }
 
-        return QueryBuilders.termQuery("relationships.keyword", rightAnyObjectKey);
+        return QueryBuilders.termQuery("relationships", rightAnyObjectKey);
     }
 
     private QueryBuilder getQueryBuilder(final MembershipCond cond) {
@@ -266,7 +259,7 @@ public class ElasticsearchAnySearchDAO extends AbstractAnySearchDAO {
             return EMPTY_QUERY_BUILDER;
         }
 
-        return QueryBuilders.termQuery("memberships.keyword", groupKey);
+        return QueryBuilders.termQuery("memberships", groupKey);
     }
 
     private QueryBuilder getQueryBuilder(final AssignableCond cond) {
@@ -280,12 +273,12 @@ public class ElasticsearchAnySearchDAO extends AbstractAnySearchDAO
{
         DisMaxQueryBuilder builder = QueryBuilders.disMaxQuery();
         if (cond.isFromGroup()) {
             for (Realm current = realm; current.getParent() != null; current = current.getParent())
{
-                builder.add(QueryBuilders.termQuery("realm.keyword", current.getFullPath()));
+                builder.add(QueryBuilders.termQuery("realm", current.getFullPath()));
             }
-            builder.add(QueryBuilders.termQuery("realm.keyword", realmDAO.getRoot().getFullPath()));
+            builder.add(QueryBuilders.termQuery("realm", realmDAO.getRoot().getFullPath()));
         } else {
             for (Realm current : realmDAO.findDescendants(realm)) {
-                builder.add(QueryBuilders.termQuery("realm.keyword", current.getFullPath()));
+                builder.add(QueryBuilders.termQuery("realm", current.getFullPath()));
             }
         }
 
@@ -293,7 +286,7 @@ public class ElasticsearchAnySearchDAO extends AbstractAnySearchDAO {
     }
 
     private QueryBuilder getQueryBuilder(final RoleCond cond) {
-        return QueryBuilders.termQuery("roles.keyword", cond.getRoleKey());
+        return QueryBuilders.termQuery("roles", cond.getRoleKey());
     }
 
     private QueryBuilder getQueryBuilder(final MemberCond cond) {
@@ -304,11 +297,11 @@ public class ElasticsearchAnySearchDAO extends AbstractAnySearchDAO
{
             return EMPTY_QUERY_BUILDER;
         }
 
-        return QueryBuilders.termQuery("members.keyword", memberKey);
+        return QueryBuilders.termQuery("members", memberKey);
     }
 
     private QueryBuilder getQueryBuilder(final ResourceCond cond) {
-        return QueryBuilders.termQuery("resources.keyword", cond.getResourceKey());
+        return QueryBuilders.termQuery("resources", cond.getResourceKey());
     }
 
     private QueryBuilder fillAttrQuery(
@@ -316,10 +309,6 @@ public class ElasticsearchAnySearchDAO extends AbstractAnySearchDAO {
             final PlainAttrValue attrValue,
             final AttributeCond cond) {
 
-        String name = schema.getType() == AttrSchemaType.String
-                || schema.getType() == AttrSchemaType.Enum
-                ? schema.getKey() + ".keyword"
-                : schema.getKey();
         Object value = schema.getType() == AttrSchemaType.Date && attrValue.getDateValue()
!= null
                 ? attrValue.getDateValue().getTime()
                 : attrValue.getValue();
@@ -328,44 +317,44 @@ public class ElasticsearchAnySearchDAO extends AbstractAnySearchDAO
{
 
         switch (cond.getType()) {
             case ISNOTNULL:
-                builder = QueryBuilders.existsQuery(name);
+                builder = QueryBuilders.existsQuery(schema.getKey());
                 break;
 
             case ISNULL:
-                builder = QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(name));
+                builder = QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(schema.getKey()));
                 break;
 
             case ILIKE:
                 builder = QueryBuilders.queryStringQuery(
-                        schema.getKey() + ":" + cond.getExpression().replace('%', '*'));
+                        schema.getKey() + ":" + cond.getExpression().replace('%', '*').toLowerCase());
                 break;
 
             case LIKE:
-                builder = QueryBuilders.wildcardQuery(name, cond.getExpression().replace('%',
'*'));
+                builder = QueryBuilders.wildcardQuery(schema.getKey(), cond.getExpression().replace('%',
'*'));
                 break;
 
             case IEQ:
-                builder = QueryBuilders.matchQuery(schema.getKey(), value);
+                builder = QueryBuilders.matchQuery(schema.getKey(), cond.getExpression().toLowerCase());
                 break;
 
             case EQ:
-                builder = QueryBuilders.termQuery(name, value);
+                builder = QueryBuilders.termQuery(schema.getKey(), value);
                 break;
 
             case GE:
-                builder = QueryBuilders.rangeQuery(name).gte(value);
+                builder = QueryBuilders.rangeQuery(schema.getKey()).gte(value);
                 break;
 
             case GT:
-                builder = QueryBuilders.rangeQuery(name).gt(value);
+                builder = QueryBuilders.rangeQuery(schema.getKey()).gt(value);
                 break;
 
             case LE:
-                builder = QueryBuilders.rangeQuery(name).lte(value);
+                builder = QueryBuilders.rangeQuery(schema.getKey()).lte(value);
                 break;
 
             case LT:
-                builder = QueryBuilders.rangeQuery(name).lt(value);
+                builder = QueryBuilders.rangeQuery(schema.getKey()).lt(value);
                 break;
 
             default:

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/ext/elasticsearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/ElasticsearchReindex.java
----------------------------------------------------------------------
diff --git a/ext/elasticsearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/ElasticsearchReindex.java
b/ext/elasticsearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/ElasticsearchReindex.java
index b9d8b15..d098a99 100644
--- a/ext/elasticsearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/ElasticsearchReindex.java
+++ b/ext/elasticsearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/ElasticsearchReindex.java
@@ -37,6 +37,8 @@ import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsReques
 import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
 import org.elasticsearch.action.index.IndexResponse;
 import org.elasticsearch.client.Client;
+import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentFactory;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -77,8 +79,41 @@ public class ElasticsearchReindex extends AbstractSchedTaskJobDelegate
{
                             AuthContextUtils.getDomain().toLowerCase(), deleteIndexResponse);
                 }
 
+                XContentBuilder settings = XContentFactory.jsonBuilder().
+                        startObject().
+                        startObject("analysis").
+                        startObject("analyzer").
+                        startObject("string_lowercase").
+                        field("type", "custom").
+                        field("tokenizer", "standard").
+                        field("filter").
+                        startArray().
+                        value("lowercase").
+                        endArray().
+                        endObject().
+                        endObject().
+                        endObject().
+                        endObject();
+                XContentBuilder mapping = XContentFactory.jsonBuilder().
+                        startObject().
+                        startArray("dynamic_templates").
+                        startObject().
+                        startObject("strings").
+                        field("match_mapping_type", "string").
+                        startObject("mapping").
+                        field("type", "keyword").
+                        field("analyzer", "string_lowercase").
+                        endObject().
+                        endObject().
+                        endObject().
+                        endArray().
+                        endObject();
                 CreateIndexResponse createIndexResponse = client.admin().indices().
-                        create(new CreateIndexRequest(AuthContextUtils.getDomain().toLowerCase())).
+                        create(new CreateIndexRequest(AuthContextUtils.getDomain().toLowerCase()).
+                                settings(settings).
+                                mapping(AnyTypeKind.USER.name(), mapping).
+                                mapping(AnyTypeKind.GROUP.name(), mapping).
+                                mapping(AnyTypeKind.ANY_OBJECT.name(), mapping)).
                         get();
                 LOG.debug("Successfully created {}: {}",
                         AuthContextUtils.getDomain().toLowerCase(), createIndexResponse);

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/ext/saml2sp/client-console/src/main/java/org/apache/syncope/client/console/panels/ImportMetadata.java
----------------------------------------------------------------------
diff --git a/ext/saml2sp/client-console/src/main/java/org/apache/syncope/client/console/panels/ImportMetadata.java
b/ext/saml2sp/client-console/src/main/java/org/apache/syncope/client/console/panels/ImportMetadata.java
index 52a05a6..61bd660 100644
--- a/ext/saml2sp/client-console/src/main/java/org/apache/syncope/client/console/panels/ImportMetadata.java
+++ b/ext/saml2sp/client-console/src/main/java/org/apache/syncope/client/console/panels/ImportMetadata.java
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.client.console.panels;
 
-import static org.apache.syncope.client.console.panels.TogglePanel.LOG;
-
 import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.BootstrapFileInputField;
 import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.FileInputConfig;
 import java.io.ByteArrayInputStream;

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/ext/saml2sp/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/SAML2IdPValidator.java
----------------------------------------------------------------------
diff --git a/ext/saml2sp/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/SAML2IdPValidator.java
b/ext/saml2sp/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/SAML2IdPValidator.java
index 3e5968c..9869500 100644
--- a/ext/saml2sp/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/SAML2IdPValidator.java
+++ b/ext/saml2sp/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/SAML2IdPValidator.java
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.core.persistence.jpa.validation.entity;
 
-import static org.apache.syncope.core.persistence.jpa.validation.entity.AbstractValidator.LOG;
-
 import javax.validation.ConstraintValidatorContext;
 import org.apache.commons.collections4.IterableUtils;
 import org.apache.commons.collections4.Predicate;

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/fit/core-reference/src/test/java/org/apache/syncope/fit/ElasticsearchDetector.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/ElasticsearchDetector.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/ElasticsearchDetector.java
new file mode 100644
index 0000000..5faa424
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/ElasticsearchDetector.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.fit;
+
+import org.apache.syncope.common.rest.api.service.SyncopeService;
+
+public class ElasticsearchDetector {
+
+    public static boolean isElasticSearchEnabled(final SyncopeService syncopeService) {
+        return syncopeService.platform().getAnySearchDAO().contains("Elasticsearch");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/fit/core-reference/src/test/java/org/apache/syncope/fit/console/BulkActionITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/BulkActionITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/BulkActionITCase.java
index d39ed71..1945320 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/BulkActionITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/BulkActionITCase.java
@@ -18,7 +18,6 @@
  */
 package org.apache.syncope.fit.console;
 
-import static org.apache.syncope.fit.console.AbstractConsoleITCase.TESTER;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/fit/core-reference/src/test/java/org/apache/syncope/fit/console/GroupsITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/GroupsITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/GroupsITCase.java
index a07dc2f..3f69966 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/GroupsITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/GroupsITCase.java
@@ -18,7 +18,6 @@
  */
 package org.apache.syncope.fit.console;
 
-import static org.apache.syncope.fit.console.AbstractConsoleITCase.TESTER;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/fit/core-reference/src/test/java/org/apache/syncope/fit/console/PoliciesITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/PoliciesITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/PoliciesITCase.java
index bdfd776..0db5e95 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/PoliciesITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/PoliciesITCase.java
@@ -18,7 +18,6 @@
  */
 package org.apache.syncope.fit.console;
 
-import static org.apache.syncope.fit.console.AbstractConsoleITCase.TESTER;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/fit/core-reference/src/test/java/org/apache/syncope/fit/console/RealmsITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/RealmsITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/RealmsITCase.java
index 1a59db4..0809a48 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/RealmsITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/RealmsITCase.java
@@ -18,7 +18,6 @@
  */
 package org.apache.syncope.fit.console;
 
-import static org.apache.syncope.fit.console.AbstractConsoleITCase.TESTER;
 import static org.junit.Assert.assertNotNull;
 
 import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/fit/core-reference/src/test/java/org/apache/syncope/fit/console/SecurityQuestionsITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/SecurityQuestionsITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/SecurityQuestionsITCase.java
index 664feeb..7efdd45 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/SecurityQuestionsITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/SecurityQuestionsITCase.java
@@ -18,7 +18,6 @@
  */
 package org.apache.syncope.fit.console;
 
-import static org.apache.syncope.fit.console.AbstractConsoleITCase.TESTER;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;

http://git-wip-us.apache.org/repos/asf/syncope/blob/29b97d7f/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
----------------------------------------------------------------------
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 976c11c..a0a37b2 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
@@ -44,6 +44,7 @@ import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.rest.api.beans.AnyQuery;
 import org.apache.syncope.common.rest.api.service.RoleService;
 import org.apache.syncope.fit.AbstractITCase;
+import org.apache.syncope.fit.ElasticsearchDetector;
 import org.junit.Test;
 
 public class SearchITCase extends AbstractITCase {
@@ -148,6 +149,14 @@ public class SearchITCase extends AbstractITCase {
         group = createGroup(group).getEntity();
         assertNotNull(group);
 
+        if (ElasticsearchDetector.isElasticSearchEnabled(syncopeService)) {
+            try {
+                Thread.sleep(2000);
+            } catch (InterruptedException ex) {
+                // ignore
+            }
+        }
+
         PagedResult<UserTO> matchingUsers = userService.search(
                 new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
                         fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups(group.getKey()).query()).
@@ -190,6 +199,14 @@ public class SearchITCase extends AbstractITCase {
         role = getObject(response.getLocation(), RoleService.class, RoleTO.class);
         assertNotNull(role);
 
+        if (ElasticsearchDetector.isElasticSearchEnabled(syncopeService)) {
+            try {
+                Thread.sleep(2000);
+            } catch (InterruptedException ex) {
+                // ignore
+            }
+        }
+
         PagedResult<UserTO> matchingUsers = userService.search(
                 new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
                         fiql(SyncopeClient.getUserSearchConditionBuilder().inRoles(role.getKey()).query()).
@@ -260,6 +277,14 @@ public class SearchITCase extends AbstractITCase {
     public void searchByDate() {
         clientFactory.create("bellini", "password").self();
 
+        if (ElasticsearchDetector.isElasticSearchEnabled(syncopeService)) {
+            try {
+                Thread.sleep(2000);
+            } catch (InterruptedException ex) {
+                // ignore
+            }
+        }
+
         PagedResult<UserTO> users = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
                 fiql(SyncopeClient.getUserSearchConditionBuilder().
                         is("lastLoginDate").lexicalNotBefore("2016-03-02 15:21:22").


Mime
View raw message