You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by an...@apache.org on 2019/11/21 16:46:59 UTC

[syncope] branch 2_1_X updated: fixed core upgrader: custom pull correlation rule migration now uses custom configuration

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/2_1_X by this push:
     new c327fce  fixed core upgrader: custom pull correlation rule migration now uses custom configuration
c327fce is described below

commit c327fce5e6dc4da384878d10496b12c6d6bc276f
Author: Andrea Patricelli <an...@apache.org>
AuthorDate: Thu Nov 21 17:45:43 2019 +0100

    fixed core upgrader: custom pull correlation rule migration now uses custom configuration
---
 .../syncope/core/upgrade/GenerateUpgradeSQL.java   | 13 +++++++----
 .../core/upgrade/GeneratedUpgradeSQLTest.java      | 26 +++++++++++++++++++---
 core/upgrade/src/test/resources/syncopedb20.sql    |  2 +-
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/core/upgrade/src/main/java/org/apache/syncope/core/upgrade/GenerateUpgradeSQL.java b/core/upgrade/src/main/java/org/apache/syncope/core/upgrade/GenerateUpgradeSQL.java
index 2c2c3a4..014b6ca 100644
--- a/core/upgrade/src/main/java/org/apache/syncope/core/upgrade/GenerateUpgradeSQL.java
+++ b/core/upgrade/src/main/java/org/apache/syncope/core/upgrade/GenerateUpgradeSQL.java
@@ -119,10 +119,15 @@ public final class GenerateUpgradeSQL {
                 if (specification.has("correlationRules")) {
                     specification.get("correlationRules").fields().forEachRemaining(entry -> {
                         ObjectNode body = MAPPER.createObjectNode();
-                        body.put("@class", "org.apache.syncope.common.lib.policy.DefaultPullCorrelationRuleConf");
-                        body.put("name", "org.apache.syncope.common.lib.policy.DefaultPullCorrelationRuleConf");
-                        body.set("schemas", entry.getValue());
-
+                        if ((entry.getValue().asText().contains("org.apache.syncope"))) {
+                            final String confClassName = entry.getValue().asText() + "Conf";
+                            body.put("@class", confClassName);
+                            body.put("name", confClassName);
+                        } else {
+                            body.put("@class", "org.apache.syncope.common.lib.policy.DefaultPullCorrelationRuleConf");
+                            body.put("name", "org.apache.syncope.common.lib.policy.DefaultPullCorrelationRuleConf");
+                            body.set("schemas", entry.getValue());
+                        }
                         try {
                             String implementationId = "PullCorrelationRule_" + entry.getKey() + "_" + id;
                             OUT.write("INSERT INTO Implementation(id,type,engine,body) VALUES("
diff --git a/core/upgrade/src/test/java/org/apache/syncope/core/upgrade/GeneratedUpgradeSQLTest.java b/core/upgrade/src/test/java/org/apache/syncope/core/upgrade/GeneratedUpgradeSQLTest.java
index 148797b..af16116 100644
--- a/core/upgrade/src/test/java/org/apache/syncope/core/upgrade/GeneratedUpgradeSQLTest.java
+++ b/core/upgrade/src/test/java/org/apache/syncope/core/upgrade/GeneratedUpgradeSQLTest.java
@@ -20,10 +20,16 @@ package org.apache.syncope.core.upgrade;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.AssertionsKt.fail;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import java.io.StringWriter;
 import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
 import javax.annotation.Resource;
 import javax.sql.DataSource;
 import org.junit.jupiter.api.Test;
@@ -54,6 +60,8 @@ public class GeneratedUpgradeSQLTest {
     @Autowired
     private DataSource syncope20DataSource;
 
+    private static final String TEST_PULL_RULE = "org.apache.syncope.fit.core.reference.TestPullRuleConf";
+
     @Test
     public void upgradefrom20() throws Exception {
         StringWriter out = new StringWriter();
@@ -76,9 +84,21 @@ public class GeneratedUpgradeSQLTest {
 
         JdbcTemplate jdbcTemplate = new JdbcTemplate(syncope20DataSource);
 
-        Integer implementations = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM Implementation", Integer.class);
+        // check that custom JAVA PullCorrelationRule(s) have been moved to correct implementation with PullCorrelationRuleConf
+        List<Map<String, Object>> implementations = jdbcTemplate.queryForList("SELECT * FROM Implementation");
         assertNotNull(implementations);
-        assertEquals(15, implementations.intValue());
+        assertEquals(16, implementations.size());
+        assertTrue(implementations.stream()
+                .anyMatch(impl -> {
+                    try {
+                        ObjectNode body = (ObjectNode) new ObjectMapper().readTree(impl.get("body").toString());
+                        return "PULL_CORRELATION_RULE".equals(impl.get("type"))
+                                && TEST_PULL_RULE.equals(body.get("@class").asText())
+                                && TEST_PULL_RULE.equals(body.get("name").asText());
+                    } catch (JsonProcessingException e) {
+                    }
+                    return false;
+                }));
 
         Integer pullTaskActions = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM PullTaskAction", Integer.class);
         assertNotNull(pullTaskActions);
@@ -110,7 +130,7 @@ public class GeneratedUpgradeSQLTest {
         Integer pullCorrelationRuleEntities = jdbcTemplate.queryForObject(
                 "SELECT COUNT(*) FROM PullCorrelationRuleEntity", Integer.class);
         assertNotNull(pullCorrelationRuleEntities);
-        assertEquals(1, pullCorrelationRuleEntities.intValue());
+        assertEquals(2, pullCorrelationRuleEntities.intValue());
 
         Integer pushCorrelationRuleEntities = jdbcTemplate.queryForObject(
                 "SELECT COUNT(*) FROM PushCorrelationRuleEntity", Integer.class);
diff --git a/core/upgrade/src/test/resources/syncopedb20.sql b/core/upgrade/src/test/resources/syncopedb20.sql
index 0ff3717..299f3f7 100644
--- a/core/upgrade/src/test/resources/syncopedb20.sql
+++ b/core/upgrade/src/test/resources/syncopedb20.sql
@@ -1182,7 +1182,7 @@ INSERT INTO PUBLIC.PULLPOLICY(ID, DESCRIPTION, SPECIFICATION) VALUES
 ('66691e96-285f-4464-bc19-e68384ea4c85', 'a pull policy', '{"conflictResolutionAction":"IGNORE"}'),
 ('880f8553-069b-4aed-9930-2cd53873f544', 'another pull policy', '{"conflictResolutionAction":"ALL","correlationRules":{"USER":["username","firstname"]}}'),
 ('4ad10d94-e002-4b3f-b771-16089cc71da9', 'pull policy 1', '{"conflictResolutionAction":"IGNORE"}'),
-('9454b0d7-2610-400a-be82-fc23cf553dd6', 'pull policy for java rule', '{"conflictResolutionAction":"IGNORE"}'); 
+('9454b0d7-2610-400a-be82-fc23cf553dd6', 'pull policy for java rule', '{"conflictResolutionAction":"IGNORE", "correlationRules":{"USER":"org.apache.syncope.fit.core.reference.TestPullRule"}}'); 
 CREATE MEMORY TABLE PUBLIC.PULLTASK_ACTIONSCLASSNAMES(
     PULLTASK_ID VARCHAR(36),
     ACTIONCLASSNAME VARCHAR(255)