syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [1/2] syncope git commit: Fixing problems of DynRealms with Elasticsearch
Date Wed, 27 Sep 2017 15:09:51 GMT
Repository: syncope
Updated Branches:
  refs/heads/2_0_X af71cbbe6 -> ee7ddd4b9
  refs/heads/master 4fe8d084a -> c23c0d513


Fixing problems of DynRealms with Elasticsearch


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

Branch: refs/heads/2_0_X
Commit: ee7ddd4b925dd72f183a313edd4918f01138a87f
Parents: af71cbb
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Wed Sep 27 17:07:51 2017 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Wed Sep 27 17:07:51 2017 +0200

----------------------------------------------------------------------
 .../persistence/jpa/dao/JPADynRealmDAO.java     | 22 ++++++++++++++++++--
 .../apache/syncope/fit/core/DynRealmITCase.java |  9 ++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/ee7ddd4b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADynRealmDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADynRealmDAO.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADynRealmDAO.java
index dfb3d34..0ef29e6 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADynRealmDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPADynRealmDAO.java
@@ -31,7 +31,9 @@ import org.apache.syncope.core.persistence.jpa.entity.JPADynRealm;
 import org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent;
 import org.apache.syncope.core.spring.ApplicationContextProvider;
 import org.apache.syncope.core.spring.security.AuthContextUtils;
+import org.springframework.aop.support.AopUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
 import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.stereotype.Repository;
 import org.springframework.transaction.annotation.Transactional;
@@ -46,6 +48,8 @@ public class JPADynRealmDAO extends AbstractDAO<DynRealm> implements
DynRealmDAO
 
     private AnySearchDAO searchDAO;
 
+    private AnySearchDAO jpaAnySearchDAO;
+
     private AnySearchDAO searchDAO() {
         synchronized (this) {
             if (searchDAO == null) {
@@ -55,6 +59,20 @@ public class JPADynRealmDAO extends AbstractDAO<DynRealm> implements
DynRealmDAO
         return searchDAO;
     }
 
+    private AnySearchDAO jpaAnySearchDAO() {
+        synchronized (this) {
+            if (jpaAnySearchDAO == null) {
+                if (AopUtils.getTargetClass(searchDAO()).equals(JPAAnySearchDAO.class)) {
+                    jpaAnySearchDAO = searchDAO();
+                } else {
+                    jpaAnySearchDAO = (AnySearchDAO) ApplicationContextProvider.getBeanFactory().
+                            createBean(JPAAnySearchDAO.class, AbstractBeanDefinition.AUTOWIRE_BY_TYPE,
true);
+                }
+            }
+        }
+        return jpaAnySearchDAO;
+    }
+
     @Override
     public DynRealm find(final String key) {
         return entityManager().find(JPADynRealm.class, key);
@@ -75,7 +93,7 @@ public class JPADynRealmDAO extends AbstractDAO<DynRealm> implements
DynRealmDAO
         clearDynMembers(merged);
 
         for (DynRealmMembership memb : merged.getDynMemberships()) {
-            List<Any<?>> matching = searchDAO().search(
+            List<Any<?>> matching = jpaAnySearchDAO().search(
                     SearchCondConverter.convert(memb.getFIQLCond()), memb.getAnyType().getKind());
             for (Any<?> any : matching) {
                 Query insert = entityManager().createNativeQuery("INSERT INTO " + DYNMEMB_TABLE
+ " VALUES(?, ?)");
@@ -121,7 +139,7 @@ public class JPADynRealmDAO extends AbstractDAO<DynRealm> implements
DynRealmDAO
                 delete.setParameter(2, any.getKey());
                 delete.executeUpdate();
 
-                if (searchDAO().matches(any, SearchCondConverter.convert(memb.getFIQLCond())))
{
+                if (jpaAnySearchDAO().matches(any, SearchCondConverter.convert(memb.getFIQLCond())))
{
                     Query insert = entityManager().createNativeQuery("INSERT INTO " + DYNMEMB_TABLE
+ " VALUES(?, ?)");
                     insert.setParameter(1, any.getKey());
                     insert.setParameter(2, dynRealm.getKey());

http://git-wip-us.apache.org/repos/asf/syncope/blob/ee7ddd4b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/DynRealmITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/DynRealmITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/DynRealmITCase.java
index 91ac3c5..ee6be00 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/DynRealmITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/DynRealmITCase.java
@@ -49,6 +49,7 @@ import org.apache.syncope.common.rest.api.service.DynRealmService;
 import org.apache.syncope.common.rest.api.service.GroupService;
 import org.apache.syncope.common.rest.api.service.UserService;
 import org.apache.syncope.fit.AbstractITCase;
+import org.apache.syncope.fit.ElasticsearchDetector;
 import org.junit.Test;
 
 public class DynRealmITCase extends AbstractITCase {
@@ -140,6 +141,14 @@ public class DynRealmITCase extends AbstractITCase {
             assertNotNull(group);
             final String groupKey = group.getKey();
 
+            if (ElasticsearchDetector.isElasticSearchEnabled(syncopeService)) {
+                try {
+                    Thread.sleep(2000);
+                } catch (InterruptedException ex) {
+                    // ignore
+                }
+            }
+
             // 5. verify that the new user and group are found when searching by dynamic
realm
             PagedResult<UserTO> matchingUsers = userService.search(new AnyQuery.Builder().realm("/").fiql(
                     SyncopeClient.getUserSearchConditionBuilder().inDynRealms(dynRealm.getKey()).query()).build());


Mime
View raw message