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

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


The following commit(s) were added to refs/heads/4_0_X by this push:
     new 0d5f03c719 Upgrading ConnId Okta bundle
0d5f03c719 is described below

commit 0d5f03c719c1004a6759ecb7e5de9d4e72109703
Author: Francesco Chicchiriccò <ilgro...@apache.org>
AuthorDate: Wed Jul 9 09:32:18 2025 +0200

    Upgrading ConnId Okta bundle
---
 .../jpa/upgrade/GenerateUpgradeSQL.java            | 111 +++++++++++++++++----
 .../persistence/jpa/upgrade/WiserSchemaTool.java   |   5 +
 .../src/main/resources/schema.xml                  |   2 +-
 pom.xml                                            |   2 +-
 4 files changed, 101 insertions(+), 19 deletions(-)

diff --git 
a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/GenerateUpgradeSQL.java
 
b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/GenerateUpgradeSQL.java
index 1122fe4693..df88a1872b 100644
--- 
a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/GenerateUpgradeSQL.java
+++ 
b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/GenerateUpgradeSQL.java
@@ -37,11 +37,18 @@ public class GenerateUpgradeSQL {
 
     private static final JsonMapper MAPPER = 
JsonMapper.builder().findAndAddModules().build();
 
-    private static final List<String> INIT_SQL_STATEMENTS = List.of(
-            "ALTER TABLE PullPolicy RENAME TO InboundPolicy",
-            "ALTER TABLE PullCorrelationRuleEntity RENAME TO 
InboundCorrelationRuleEntity",
-            "ALTER TABLE ExternalResource RENAME COLUMN pullPolicy_id TO 
inboundPolicy_id",
-            "ALTER TABLE InboundCorrelationRuleEntity RENAME COLUMN 
pullPolicy_id TO inboundPolicy_id");
+    private static final String INIT_SQL_STATEMENTS =
+            """
+            INSERT INTO InboundPolicy SELECT * FROM PullPolicy;
+            UPDATE ExternalResource SET inboundPolicy_id=pullPolicy_id;
+            ALTER TABLE ExternalResource DROP COLUMN pullPolicy_id;
+
+            INSERT INTO InboundCorrelationRuleEntity(id, inboundPolicy_id, 
anyType_id, implementation_id) 
+            SELECT id, pullPolicy_id, anyType_id, implementation_id FROM 
PullCorrelationRuleEntity;
+
+            DROP TABLE PullCorrelationRuleEntity;
+            DROP TABLE PullPolicy;
+            """;
 
     private static final String FINAL_SQL_STATEMENTS =
             """
@@ -55,7 +62,7 @@ public class GenerateUpgradeSQL {
             DROP TABLE IF EXISTS qrtz_scheduler_state CASCADE;
             DROP TABLE IF EXISTS qrtz_simple_triggers CASCADE;
             DROP TABLE IF EXISTS qrtz_simprop_triggers CASCADE;
-            DROP TABLE IF EXISTS qrtz_triggers CASCADE;            
+            DROP TABLE IF EXISTS qrtz_triggers CASCADE;
             """;
 
     private final JDBCConfiguration jdbcConf;
@@ -165,7 +172,7 @@ public class GenerateUpgradeSQL {
         return result.toString();
     }
 
-    private String roles() {
+    private String roles() throws JsonProcessingException {
         StringBuilder result = new StringBuilder();
 
         List<Map<String, Object>> dynMembershipConds = 
jdbcTemplate.queryForList(
@@ -178,6 +185,28 @@ public class GenerateUpgradeSQL {
 
         result.append("DROP TABLE DynRoleMembership;\n");
 
+        List<Map<String, Object>> roles = jdbcTemplate.queryForList(
+                "SELECT id, anyLayout from SyncopeRole WHERE anyLayout IS NOT 
NULL");
+
+        for (Map<String, Object> role : roles) {
+            JsonNode anyLayout = 
MAPPER.readTree(role.get("anyLayout").toString());
+            for (JsonNode child : anyLayout) {
+                if (child.isObject()) {
+                    if (child.has("virAttrs")) {
+                        ((ObjectNode) child).remove("virAttrs");
+                    }
+                    if (child.has("whichVirAttrs")) {
+                        ((ObjectNode) child).remove("whichVirAttrs");
+                    }
+                }
+            }
+
+            result.append(String.format(
+                    "UPDATE SyncopeRole SET anyLayout='%s' WHERE id='%s';\n",
+                    MAPPER.writeValueAsString(anyLayout).replace("'", "&#39;"),
+                    role.get("id").toString()));
+        }
+
         return result.toString();
     }
 
@@ -237,7 +266,54 @@ public class GenerateUpgradeSQL {
         result.append("UPDATE Implementation ").
                 append("SET type='INBOUND_ACTIONS' WHERE 
type='PULL_ACTIONS';\n");
         result.append("UPDATE Implementation ").
-                append("SET type='INBOUND_CORRELATION_RULE' WHERE 
type='PULL_CORRELATION_RULE';\n\n");
+                append("SET type='INBOUND_CORRELATION_RULE' WHERE 
type='PULL_CORRELATION_RULE';\n");
+
+        List<Map<String, Object>> implementations = jdbcTemplate.queryForList(
+                "SELECT id, body from Implementation "
+                + "WHERE body LIKE 
'org.apache.syncope.core.persistence.jpa.attrvalue.validation.%'");
+
+        implementations.forEach(implementation -> result.append(String.format(
+                "UPDATE Implementation SET body='%s' WHERE id='%s';\n",
+                implementation.get("body").toString().replace(
+                        
"org.apache.syncope.core.persistence.jpa.attrvalue.validation.",
+                        
"org.apache.syncope.core.persistence.common.attrvalue."),
+                implementation.get("id").toString())));
+
+        return result.toString();
+    }
+
+    private String anyTemplates() throws JsonProcessingException {
+        StringBuilder result = new StringBuilder();
+
+        List<Map<String, Object>> templates = jdbcTemplate.queryForList(
+                "SELECT id, template from AnyTemplateRealm");
+
+        for (Map<String, Object> template : templates) {
+            JsonNode t = MAPPER.readTree(template.get("template").toString());
+            if (t.has("virAttrs")) {
+                ((ObjectNode) t).remove("virAttrs");
+
+                result.append(String.format(
+                        "UPDATE AnyTemplateRealm SET template='%s' WHERE 
id='%s';\n",
+                        MAPPER.writeValueAsString(t).replace("'", "&#39;"),
+                        template.get("id").toString()));
+            }
+        }
+
+        templates = jdbcTemplate.queryForList(
+                "SELECT id, template from AnyTemplatePullTask");
+
+        for (Map<String, Object> template : templates) {
+            JsonNode t = MAPPER.readTree(template.get("template").toString());
+            if (t.has("virAttrs")) {
+                ((ObjectNode) t).remove("virAttrs");
+
+                result.append(String.format(
+                        "UPDATE AnyTemplatePullTask SET template='%s' WHERE 
id='%s';\n",
+                        MAPPER.writeValueAsString(t).replace("'", "&#39;"),
+                        template.get("id").toString()));
+            }
+        }
 
         return result.toString();
     }
@@ -257,8 +333,6 @@ public class GenerateUpgradeSQL {
     }
 
     public void run(final Writer out) throws IOException, SQLException {
-        INIT_SQL_STATEMENTS.forEach(jdbcTemplate::execute);
-
         WiserSchemaTool schemaTool = new WiserSchemaTool(jdbcConf, 
SchemaTool.ACTION_ADD);
         
schemaTool.setSchemaGroup(jdbcConf.getSchemaFactoryInstance().readSchema());
         schemaTool.setWriter(out);
@@ -267,13 +341,16 @@ public class GenerateUpgradeSQL {
             // run OpenJPA's SchemaTool to get the update statements
             schemaTool.run();
 
-            out.append(connInstances());
-            out.append(resources());
-            out.append(plainSchemas());
-            out.append(roles());
-            out.append(relationshipTypes());
-            out.append(implementations());
-            out.append(audit());
+            out.append('\n').append(INIT_SQL_STATEMENTS).append('\n');
+
+            out.append(connInstances()).append('\n');
+            out.append(resources()).append('\n');
+            out.append(plainSchemas()).append('\n');
+            out.append(roles()).append('\n');
+            out.append(relationshipTypes()).append('\n');
+            out.append(implementations()).append('\n');
+            out.append(anyTemplates()).append('\n');
+            out.append(audit()).append('\n');
 
             out.append(FINAL_SQL_STATEMENTS);
         }
diff --git 
a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/WiserSchemaTool.java
 
b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/WiserSchemaTool.java
index f7b80ee0d2..491121e981 100644
--- 
a/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/WiserSchemaTool.java
+++ 
b/core/persistence-jpa-upgrader/src/main/java/org/apache/syncope/core/persistence/jpa/upgrade/WiserSchemaTool.java
@@ -49,6 +49,11 @@ public class WiserSchemaTool extends SchemaTool {
         super(conf, action);
     }
 
+    @Override
+    protected void add() throws SQLException {
+        add(getDBSchemaGroup(true), assertSchemaGroup());
+    }
+
     @Override
     protected void buildSchema(
             final SchemaGroup db,
diff --git a/core/persistence-jpa-upgrader/src/main/resources/schema.xml 
b/core/persistence-jpa-upgrader/src/main/resources/schema.xml
index e0de4a63b3..d50923beb7 100644
--- a/core/persistence-jpa-upgrader/src/main/resources/schema.xml
+++ b/core/persistence-jpa-upgrader/src/main/resources/schema.xml
@@ -442,7 +442,7 @@ under the License.
         </table>
         <table name="FormPropertyDef">
             <pk column="id"/>
-            <column name="id" type="varchar" not-null="true" size="36"/>
+            <column name="id" type="varchar" not-null="true" size="255"/>
             <column name="datePattern" type="varchar" size="255"/>
             <column name="dropdownFreeForm" type="bit"/>
             <column name="dropdownSingleSelection" type="bit"/>
diff --git a/pom.xml b/pom.xml
index a3567249fa..037f055a31 100644
--- a/pom.xml
+++ b/pom.xml
@@ -406,7 +406,7 @@ under the License.
     <connid.azure.version>3.0.0</connid.azure.version>
     <connid.scim.version>1.0.5</connid.scim.version>
     <connid.servicenow.version>1.0.3</connid.servicenow.version>
-    <connid.okta.version>3.0.7</connid.okta.version>
+    <connid.okta.version>3.0.8</connid.okta.version>
     <connid.cmd.version>0.5</connid.cmd.version>
     <connid.kafka.version>1.0.0</connid.kafka.version>
     <connid.ldup.version>0.1.0</connid.ldup.version>

Reply via email to