syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmarte...@apache.org
Subject [syncope] branch 2_0_X updated: [SYNCOPE-1424] changes the way to build the task search query and fixes some test weeknesses
Date Tue, 08 Jan 2019 14:58:14 GMT
This is an automated email from the ASF dual-hosted git repository.

fmartelli pushed a commit to branch 2_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/2_0_X by this push:
     new 5c5c0ab  [SYNCOPE-1424] changes the way to build the task search query and fixes
some test weeknesses
5c5c0ab is described below

commit 5c5c0ab1a6651e430b78f15460b23f681fa228ad
Author: fmartelli <fabio.martelli@gmail.com>
AuthorDate: Tue Jan 8 15:57:57 2019 +0100

    [SYNCOPE-1424] changes the way to build the task search query and fixes some test weeknesses
---
 .../core/persistence/jpa/dao/JPATaskDAO.java       | 91 +++++++++++-----------
 .../resources/mariadb/domains/Master.properties    |  2 +-
 .../main/resources/mysql/domains/Master.properties |  2 +-
 .../syncope/fit/core/PropagationTaskITCase.java    |  6 +-
 .../apache/syncope/fit/core/PullTaskITCase.java    |  3 +-
 5 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPATaskDAO.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPATaskDAO.java
index c79260a..497044d 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPATaskDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPATaskDAO.java
@@ -183,22 +183,28 @@ public class JPATaskDAO extends AbstractDAO<Task> implements TaskDAO
{
             throw new IllegalArgumentException(type + " is not related to notifications");
         }
 
-        StringBuilder queryString = new StringBuilder("SELECT ").
-                append(AbstractTask.TABLE).
-                append(".id FROM ").
-                append(AbstractTask.TABLE);
+        StringBuilder queryString = new StringBuilder("SELECT ").append(AbstractTask.TABLE).append(".*");
+
         if (orderByTaskExecInfo) {
-            queryString.append(" LEFT OUTER JOIN ").
-                    append(JPATaskExec.TABLE).
-                    append(" ON ").
-                    append(AbstractTask.TABLE).
-                    append(".id = ").
-                    append(JPATaskExec.TABLE).
-                    append(".task_id");
+            queryString.append(",").append(JPATaskExec.TABLE).append(".startDate AS startDate").
+                    append(",").append(JPATaskExec.TABLE).append(".endDate AS endDate").
+                    append(",").append(JPATaskExec.TABLE).append(".status AS status").
+                    append(" FROM ").append(AbstractTask.TABLE).
+                    append(",").append(JPATaskExec.TABLE).append(",").append("(SELECT ").
+                    append(JPATaskExec.TABLE).append(".task_id, ").
+                    append("MAX(").append(JPATaskExec.TABLE).append(".startDate) AS startDate").
+                    append(" FROM ").append(JPATaskExec.TABLE).
+                    append(" GROUP BY ").append(JPATaskExec.TABLE).append(".task_id) GRP").
+                    append(" WHERE ").
+                    append(AbstractTask.TABLE).append(".id=").append(JPATaskExec.TABLE).append(".task_id").
+                    append(" AND ").append(AbstractTask.TABLE).append(".id=").append("GRP.task_id").
+                    append(" AND ").append(JPATaskExec.TABLE).append(".startDate=").append("GRP.startDate").
+                    append(" AND ").append(AbstractTask.TABLE).append(".DTYPE = ?1");
+        } else {
+            queryString.append(", null AS startDate, null AS endDate, null AS status FROM
").append(AbstractTask.TABLE).
+                    append(" WHERE ").append(AbstractTask.TABLE).append(".DTYPE = ?1");
         }
-        queryString.append(" WHERE ").
-                append(AbstractTask.TABLE).
-                append(".DTYPE = ?1");
+
         queryParameters.add(getEntityTableName(type));
         if (type == TaskType.SCHEDULED) {
             queryString.append(" AND ").
@@ -246,34 +252,15 @@ public class JPATaskDAO extends AbstractDAO<Task> implements TaskDAO
{
         return queryString;
     }
 
-    private String toOrderByStatement(
-            final Class<? extends Task> beanClass,
-            final List<OrderByClause> orderByClauses,
-            final boolean orderByTaskExecInfo) {
+    private String toOrderByStatement(final Class<? extends Task> beanClass, final
List<OrderByClause> orderByClauses) {
 
         StringBuilder statement = new StringBuilder();
 
-        if (orderByTaskExecInfo) {
-            statement.append(" AND (").
-                    append(JPATaskExec.TABLE).
-                    append(".startDate IS NULL OR ").
-                    append(JPATaskExec.TABLE).
-                    append(".startDate = (SELECT MAX(").
-                    append(JPATaskExec.TABLE).
-                    append(".startDate) FROM ").
-                    append(JPATaskExec.TABLE).
-                    append(" WHERE ").
-                    append(AbstractTask.TABLE).
-                    append(".id = ").
-                    append(JPATaskExec.TABLE).
-                    append(".task_id))");
-        }
         statement.append(" ORDER BY ");
 
         StringBuilder subStatement = new StringBuilder();
         for (OrderByClause clause : orderByClauses) {
             String field = clause.getField().trim();
-            String table = JPATaskExec.TABLE;
             switch (field) {
                 case "latestExecStatus":
                     field = "status";
@@ -294,19 +281,12 @@ public class JPATaskDAO extends AbstractDAO<Task> implements TaskDAO
{
                             || beanField.getAnnotation(OneToMany.class) != null)) {
                         field += "_id";
                     }
-                    table = AbstractTask.TABLE;
             }
-            subStatement.append(table).
-                    append(".").
-                    append(field).
-                    append(' ').
-                    append(clause.getDirection().name()).
-                    append(',');
+            subStatement.append(field).append(' ').append(clause.getDirection().name()).append(',');
         }
 
         if (subStatement.length() == 0) {
-            statement.append(AbstractTask.TABLE).
-                    append(".id DESC");
+            statement.append("id DESC");
         } else {
             subStatement.deleteCharAt(subStatement.length() - 1);
             statement.append(subStatement);
@@ -345,8 +325,27 @@ public class JPATaskDAO extends AbstractDAO<Task> implements TaskDAO
{
                 anyTypeKind,
                 entityKey,
                 orderByTaskExecInfo,
-                queryParameters).
-                append(toOrderByStatement(getEntityReference(type), orderByClauses, orderByTaskExecInfo));
+                queryParameters);
+
+        if (orderByTaskExecInfo) {
+            // UNION with tasks without executions...
+            queryString.insert(0, "SELECT T.id FROM ((").append(") UNION ALL (").
+                    append(buildFindAllQuery(
+                            type,
+                            resource,
+                            notification,
+                            anyTypeKind,
+                            entityKey,
+                            false,
+                            queryParameters)).
+                    append(" AND id NOT IN ").
+                    append("(SELECT task_id AS id FROM ").append(JPATaskExec.TABLE).append(")").
+                    append(")) T");
+        } else {
+            queryString.insert(0, "SELECT T.id FROM (").append(") T");
+        }
+
+        queryString.append(toOrderByStatement(getEntityReference(type), orderByClauses));
 
         Query query = entityManager().createNativeQuery(queryString.toString());
 
@@ -378,7 +377,7 @@ public class JPATaskDAO extends AbstractDAO<Task> implements TaskDAO
{
 
         Query query = entityManager().createNativeQuery(StringUtils.replaceOnce(
                 queryString.toString(),
-                "SELECT " + AbstractTask.TABLE + ".id",
+                "SELECT " + AbstractTask.TABLE + ".*, null AS startDate, null AS endDate,
null AS status",
                 "SELECT COUNT(" + AbstractTask.TABLE + ".id)"));
 
         for (int i = 1; i <= queryParameters.size(); i++) {
diff --git a/fit/core-reference/src/main/resources/mariadb/domains/Master.properties b/fit/core-reference/src/main/resources/mariadb/domains/Master.properties
index 5d3e2d3..c0dd90a 100644
--- a/fit/core-reference/src/main/resources/mariadb/domains/Master.properties
+++ b/fit/core-reference/src/main/resources/mariadb/domains/Master.properties
@@ -19,7 +19,7 @@ Master.url=jdbc:mariadb://localhost:3306/syncope?characterEncoding=UTF-8
 Master.schema=
 Master.username=syncope
 Master.password=syncope
-Master.databasePlatform=org.apache.openjpa.jdbc.sql.MariaDBDictionary(blobTypeName=LONGBLOB)
+Master.databasePlatform=org.apache.openjpa.jdbc.sql.MariaDBDictionary(blobTypeName=LONGBLOB,timestampTypeName=DATETIME(3))
 Master.orm=META-INF/spring-orm.xml
 
 Master.pool.maxActive=10
diff --git a/fit/core-reference/src/main/resources/mysql/domains/Master.properties b/fit/core-reference/src/main/resources/mysql/domains/Master.properties
index ce09eec..a4abb99 100644
--- a/fit/core-reference/src/main/resources/mysql/domains/Master.properties
+++ b/fit/core-reference/src/main/resources/mysql/domains/Master.properties
@@ -19,7 +19,7 @@ Master.url=jdbc:mysql://localhost:3306/syncope?characterEncoding=UTF-8&relaxAuto
 Master.schema=
 Master.username=syncope
 Master.password=syncope
-Master.databasePlatform=org.apache.openjpa.jdbc.sql.MySQLDictionary(blobTypeName=LONGBLOB)
+Master.databasePlatform=org.apache.openjpa.jdbc.sql.MySQLDictionary(blobTypeName=LONGBLOB,timestampTypeName=DATETIME(3))
 Master.orm=META-INF/spring-orm.xml
 
 Master.pool.maxActive=10
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PropagationTaskITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PropagationTaskITCase.java
index b1e650d..d17ecbe 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PropagationTaskITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PropagationTaskITCase.java
@@ -174,13 +174,15 @@ public class PropagationTaskITCase extends AbstractTaskITCase {
 
         // check list
         PagedResult<TaskTO> tasks = taskService.search(
-                new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(2).details(false).build());
+                new TaskQuery.Builder(TaskType.PROPAGATION).
+                        page(1).size(2).orderBy("operation DESC").details(false).build());
         for (TaskTO item : tasks.getResult()) {
             assertTrue(item.getExecutions().isEmpty());
         }
 
         tasks = taskService.search(
-                new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(2).details(true).build());
+                new TaskQuery.Builder(TaskType.PROPAGATION).
+                        page(1).size(2).orderBy("operation DESC").details(true).build());
         for (TaskTO item : tasks.getResult()) {
             assertFalse(item.getExecutions().isEmpty());
         }
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
index 5be82dc..ae9ab69 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
@@ -80,6 +80,7 @@ import org.apache.syncope.common.rest.api.beans.AnyQuery;
 import org.apache.syncope.common.rest.api.beans.TaskQuery;
 import org.apache.syncope.common.rest.api.service.ConnectorService;
 import org.apache.syncope.common.rest.api.service.TaskService;
+import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport;
 import org.apache.syncope.core.provisioning.java.pushpull.DBPasswordPullActions;
 import org.apache.syncope.core.provisioning.java.pushpull.LDAPPasswordPullActions;
 import org.apache.syncope.core.spring.security.Encryptor;
@@ -759,7 +760,7 @@ public class PullTaskITCase extends AbstractTaskITCase {
 
         // 1. populate the external table
         jdbcTemplate.execute("INSERT INTO testpull VALUES"
-                + "('" + id + "', 'issuesyncope230', 'Surname', false, 'syncope230@syncope.apache.org',
NULL)");
+                + "('" + id + "', 'issuesyncope230', 'Surname230', false, 'syncope230@syncope.apache.org',
NULL)");
 
         // 2. execute PullTask for resource-db-pull (table TESTPULL on external H2)
         execProvisioningTask(taskService, TaskType.PULL, "7c2242f4-14af-4ab5-af31-cdae23783655",
50, false);


Mime
View raw message