You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2018/04/23 10:12:24 UTC

[1/2] syncope git commit: SYNCOPE-1303: fix content migration from 1.2 to 2.0.9-SNAPSHOT version - This closes #71

Repository: syncope
Updated Branches:
  refs/heads/2_0_X e021f8535 -> da7fe0dc7
  refs/heads/master 01daf0b25 -> a2dfa8f01


SYNCOPE-1303: fix content migration from 1.2 to 2.0.9-SNAPSHOT version - This closes #71


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

Branch: refs/heads/master
Commit: a2dfa8f01ec6de9a2e81d9ccf0b47a3dd7162b5e
Parents: 01daf0b
Author: lorenzo <lo...@tirasa.net>
Authored: Mon Apr 23 10:27:38 2018 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Mon Apr 23 12:11:51 2018 +0200

----------------------------------------------------------------------
 .../cli/commands/migrate/MigrateConf.java       | 40 +++++++++++++++-----
 .../client/cli/commands/MigrateTest.java        |  1 -
 2 files changed, 31 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/a2dfa8f0/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
index 8edf1f8..85b60df 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
 import java.io.FileWriter;
 import java.io.InputStream;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.nio.file.Files;
 import java.nio.file.Paths;
@@ -39,6 +40,7 @@ import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.TransformerException;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter;
 import org.apache.syncope.client.cli.Input;
@@ -127,7 +129,9 @@ public class MigrateConf {
         }
     }
 
-    private static void exec(final String src, final String dst) throws XMLStreamException, IOException {
+    private static void exec(final String src, final String dst)
+            throws XMLStreamException, IOException, TransformerException {
+
         XMLStreamWriter writer = new PrettyPrintXMLStreamWriter(
                 OUTPUT_FACTORY.createXMLStreamWriter(new FileWriter(dst)), 2);
         writer.writeStartDocument("UTF-8", "1.0");
@@ -144,6 +148,8 @@ public class MigrateConf {
         reader.nextTag(); // root
         reader.nextTag(); // dataset
 
+        String realmUUID = UUID.randomUUID().toString();
+
         writer.writeStartElement("AnyType");
         writer.writeAttribute("id", "USER");
         writer.writeAttribute("kind", "USER");
@@ -179,7 +185,7 @@ public class MigrateConf {
         Set<String> connInstanceCapabilities = new HashSet<>();
 
         String lastUUID;
-        String syncopeConf = UUID.randomUUID().toString();
+        String syncopeConf = "cd64d66f-6fff-4008-b966-a06b1cc1436d";
         Map<String, String> cPlainAttrs = new HashMap<>();
         Map<String, String> policies = new HashMap<>();
         Map<String, String> connInstances = new HashMap<>();
@@ -203,6 +209,7 @@ public class MigrateConf {
                     case "cschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("PlainSchema");
                         copyAttrs(reader, writer);
@@ -233,6 +240,7 @@ public class MigrateConf {
                     case "uschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("PlainSchema");
                         copyAttrs(reader, writer);
@@ -244,6 +252,7 @@ public class MigrateConf {
                     case "uderschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("DerSchema");
                         copyAttrs(reader, writer);
@@ -262,6 +271,7 @@ public class MigrateConf {
                     case "rschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("PlainSchema");
                         copyAttrs(reader, writer);
@@ -273,6 +283,7 @@ public class MigrateConf {
                     case "rderschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("DerSchema");
                         copyAttrs(reader, writer);
@@ -291,6 +302,7 @@ public class MigrateConf {
                     case "mschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("PlainSchema");
                         copyAttrs(reader, writer);
@@ -302,6 +314,7 @@ public class MigrateConf {
                     case "mderschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("DerSchema");
                         copyAttrs(reader, writer);
@@ -530,7 +543,7 @@ public class MigrateConf {
                             reporter.writeEndElement();
                         } else {
                             writer.writeStartElement("MappingItem");
-                            copyAttrs(reader, writer,
+                            copyAttrs(reader, writer, "purpose",
                                     "accountid", "intMappingType", "mapping_id", "intMappingType", "intAttrName");
                             writer.writeAttribute("id", UUID.randomUUID().toString());
                             writer.writeAttribute("mapping_id", mappings.
@@ -540,9 +553,13 @@ public class MigrateConf {
                             writeIntAttrName(
                                     uIntMappingType,
                                     "intAttrName",
-                                    mappings.get(getAttributeValue(reader, "intAttrName")),
+                                    getAttributeValue(reader, "intAttrName"),
                                     writer);
 
+                            String purposeValue = getAttributeValue(reader, "purpose");
+                            writer.writeAttribute("purpose",
+                                    "SYNCHRONIZATION".equals(purposeValue) ? "PULL" : purposeValue);
+
                             writer.writeEndElement();
                         }
                         break;
@@ -637,6 +654,7 @@ public class MigrateConf {
                             case "SyncTask":
                                 writer.writeAttribute("DTYPE", "PullTask");
                                 writer.writeAttribute("syncStatus", getAttributeValue(reader, "syncStatus"));
+                                writer.writeAttribute("destinationRealm_id", realmUUID);
 
                                 String fullReconciliation = getAttributeValue(reader, "fullReconciliation");
                                 if ("1".equals(fullReconciliation)) {
@@ -673,6 +691,7 @@ public class MigrateConf {
                                     writer.writeAttribute("template", template.toString());
                                     writer.writeEndElement();
                                 }
+
                                 break;
 
                             case "SchedTask":
@@ -731,8 +750,8 @@ public class MigrateConf {
                         String syncActionClassName = getAttributeValue(reader, "element");
                         switch (syncActionClassName) {
                             case "org.apache.syncope.core.sync.impl.LDAPMembershipSyncActions":
-                                syncActionClassName =
-                                        "org.apache.syncope.core.provisioning.java.pushpull.LDAPMembershipPullActions";
+                                syncActionClassName = "org.apache.syncope.core.provisioning."
+                                        + "java.pushpull.LDAPMembershipPullActions";
                                 break;
 
                             case "org.apache.syncope.core.sync.impl.LDAPPasswordSyncActions":
@@ -804,7 +823,7 @@ public class MigrateConf {
                                 "notification_id", notifications.get(getAttributeValue(reader, "notification_id")));
                         writer.writeAttribute(
                                 "event", getAttributeValue(reader, "events").
-                                replaceAll("Controller", "Logic"));
+                                        replaceAll("Controller", "Logic"));
                         writer.writeEndElement();
                         break;
 
@@ -865,7 +884,7 @@ public class MigrateConf {
         }
 
         writer.writeStartElement("Realm");
-        writer.writeAttribute("id", UUID.randomUUID().toString());
+        writer.writeAttribute("id", realmUUID);
         writer.writeAttribute("name", "/");
         if (globalAccountPolicy != null) {
             writer.writeAttribute("accountPolicy_id", globalAccountPolicy);
@@ -897,7 +916,10 @@ public class MigrateConf {
                         "Migration completed; file successfully created under " + input.secondParameter());
             } catch (Exception e) {
                 LOG.error("Error migrating configuration from {}", input.firstParameter(), e);
-                migrateResultManager.genericError("Error performing configuration migration: " + e.getMessage());
+                StringWriter errors = new StringWriter();
+                e.printStackTrace(new PrintWriter(errors));
+                migrateResultManager.genericError("Error performing configuration migration: "
+                        + errors.toString());
             }
         } else {
             migrateResultManager.commandOptionError(HELP_MESSAGE);

http://git-wip-us.apache.org/repos/asf/syncope/blob/a2dfa8f0/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java
----------------------------------------------------------------------
diff --git a/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java b/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java
index cdf83b1..0b1c749 100644
--- a/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java
+++ b/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java
@@ -76,7 +76,6 @@ public class MigrateTest {
         // 3. attempt to set initial content from the migrated MasterContent.xml
         SAXParserFactory factory = SAXParserFactory.newInstance();
         try (InputStream in = new FileInputStream(args[3])) {
-
             SAXParser parser = factory.newSAXParser();
             parser.parse(in, new ContentLoaderHandler(dataSource, ROOT_ELEMENT, false));
         }


[2/2] syncope git commit: SYNCOPE-1303: fix content migration from 1.2 to 2.0.9-SNAPSHOT version

Posted by il...@apache.org.
SYNCOPE-1303: fix content migration from 1.2 to 2.0.9-SNAPSHOT version


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

Branch: refs/heads/2_0_X
Commit: da7fe0dc714d6f9a5ada0a45ce0b918de40293c4
Parents: e021f85
Author: lorenzo <lo...@tirasa.net>
Authored: Mon Apr 23 10:27:38 2018 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Mon Apr 23 12:12:16 2018 +0200

----------------------------------------------------------------------
 .../cli/commands/migrate/MigrateConf.java       | 40 +++++++++++++++-----
 .../client/cli/commands/MigrateTest.java        |  1 -
 2 files changed, 31 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/da7fe0dc/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
index 8edf1f8..85b60df 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
 import java.io.FileWriter;
 import java.io.InputStream;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.nio.file.Files;
 import java.nio.file.Paths;
@@ -39,6 +40,7 @@ import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.TransformerException;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter;
 import org.apache.syncope.client.cli.Input;
@@ -127,7 +129,9 @@ public class MigrateConf {
         }
     }
 
-    private static void exec(final String src, final String dst) throws XMLStreamException, IOException {
+    private static void exec(final String src, final String dst)
+            throws XMLStreamException, IOException, TransformerException {
+
         XMLStreamWriter writer = new PrettyPrintXMLStreamWriter(
                 OUTPUT_FACTORY.createXMLStreamWriter(new FileWriter(dst)), 2);
         writer.writeStartDocument("UTF-8", "1.0");
@@ -144,6 +148,8 @@ public class MigrateConf {
         reader.nextTag(); // root
         reader.nextTag(); // dataset
 
+        String realmUUID = UUID.randomUUID().toString();
+
         writer.writeStartElement("AnyType");
         writer.writeAttribute("id", "USER");
         writer.writeAttribute("kind", "USER");
@@ -179,7 +185,7 @@ public class MigrateConf {
         Set<String> connInstanceCapabilities = new HashSet<>();
 
         String lastUUID;
-        String syncopeConf = UUID.randomUUID().toString();
+        String syncopeConf = "cd64d66f-6fff-4008-b966-a06b1cc1436d";
         Map<String, String> cPlainAttrs = new HashMap<>();
         Map<String, String> policies = new HashMap<>();
         Map<String, String> connInstances = new HashMap<>();
@@ -203,6 +209,7 @@ public class MigrateConf {
                     case "cschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("PlainSchema");
                         copyAttrs(reader, writer);
@@ -233,6 +240,7 @@ public class MigrateConf {
                     case "uschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("PlainSchema");
                         copyAttrs(reader, writer);
@@ -244,6 +252,7 @@ public class MigrateConf {
                     case "uderschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("DerSchema");
                         copyAttrs(reader, writer);
@@ -262,6 +271,7 @@ public class MigrateConf {
                     case "rschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("PlainSchema");
                         copyAttrs(reader, writer);
@@ -273,6 +283,7 @@ public class MigrateConf {
                     case "rderschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("DerSchema");
                         copyAttrs(reader, writer);
@@ -291,6 +302,7 @@ public class MigrateConf {
                     case "mschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("PlainSchema");
                         copyAttrs(reader, writer);
@@ -302,6 +314,7 @@ public class MigrateConf {
                     case "mderschema":
                         writer.writeStartElement("SyncopeSchema");
                         writer.writeAttribute("id", getAttributeValue(reader, "name"));
+                        writer.writeEndElement();
 
                         writer.writeStartElement("DerSchema");
                         copyAttrs(reader, writer);
@@ -530,7 +543,7 @@ public class MigrateConf {
                             reporter.writeEndElement();
                         } else {
                             writer.writeStartElement("MappingItem");
-                            copyAttrs(reader, writer,
+                            copyAttrs(reader, writer, "purpose",
                                     "accountid", "intMappingType", "mapping_id", "intMappingType", "intAttrName");
                             writer.writeAttribute("id", UUID.randomUUID().toString());
                             writer.writeAttribute("mapping_id", mappings.
@@ -540,9 +553,13 @@ public class MigrateConf {
                             writeIntAttrName(
                                     uIntMappingType,
                                     "intAttrName",
-                                    mappings.get(getAttributeValue(reader, "intAttrName")),
+                                    getAttributeValue(reader, "intAttrName"),
                                     writer);
 
+                            String purposeValue = getAttributeValue(reader, "purpose");
+                            writer.writeAttribute("purpose",
+                                    "SYNCHRONIZATION".equals(purposeValue) ? "PULL" : purposeValue);
+
                             writer.writeEndElement();
                         }
                         break;
@@ -637,6 +654,7 @@ public class MigrateConf {
                             case "SyncTask":
                                 writer.writeAttribute("DTYPE", "PullTask");
                                 writer.writeAttribute("syncStatus", getAttributeValue(reader, "syncStatus"));
+                                writer.writeAttribute("destinationRealm_id", realmUUID);
 
                                 String fullReconciliation = getAttributeValue(reader, "fullReconciliation");
                                 if ("1".equals(fullReconciliation)) {
@@ -673,6 +691,7 @@ public class MigrateConf {
                                     writer.writeAttribute("template", template.toString());
                                     writer.writeEndElement();
                                 }
+
                                 break;
 
                             case "SchedTask":
@@ -731,8 +750,8 @@ public class MigrateConf {
                         String syncActionClassName = getAttributeValue(reader, "element");
                         switch (syncActionClassName) {
                             case "org.apache.syncope.core.sync.impl.LDAPMembershipSyncActions":
-                                syncActionClassName =
-                                        "org.apache.syncope.core.provisioning.java.pushpull.LDAPMembershipPullActions";
+                                syncActionClassName = "org.apache.syncope.core.provisioning."
+                                        + "java.pushpull.LDAPMembershipPullActions";
                                 break;
 
                             case "org.apache.syncope.core.sync.impl.LDAPPasswordSyncActions":
@@ -804,7 +823,7 @@ public class MigrateConf {
                                 "notification_id", notifications.get(getAttributeValue(reader, "notification_id")));
                         writer.writeAttribute(
                                 "event", getAttributeValue(reader, "events").
-                                replaceAll("Controller", "Logic"));
+                                        replaceAll("Controller", "Logic"));
                         writer.writeEndElement();
                         break;
 
@@ -865,7 +884,7 @@ public class MigrateConf {
         }
 
         writer.writeStartElement("Realm");
-        writer.writeAttribute("id", UUID.randomUUID().toString());
+        writer.writeAttribute("id", realmUUID);
         writer.writeAttribute("name", "/");
         if (globalAccountPolicy != null) {
             writer.writeAttribute("accountPolicy_id", globalAccountPolicy);
@@ -897,7 +916,10 @@ public class MigrateConf {
                         "Migration completed; file successfully created under " + input.secondParameter());
             } catch (Exception e) {
                 LOG.error("Error migrating configuration from {}", input.firstParameter(), e);
-                migrateResultManager.genericError("Error performing configuration migration: " + e.getMessage());
+                StringWriter errors = new StringWriter();
+                e.printStackTrace(new PrintWriter(errors));
+                migrateResultManager.genericError("Error performing configuration migration: "
+                        + errors.toString());
             }
         } else {
             migrateResultManager.commandOptionError(HELP_MESSAGE);

http://git-wip-us.apache.org/repos/asf/syncope/blob/da7fe0dc/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java
----------------------------------------------------------------------
diff --git a/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java b/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java
index 8ceadce..a2be175 100644
--- a/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java
+++ b/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java
@@ -76,7 +76,6 @@ public class MigrateTest {
         // 3. attempt to set initial content from the migrated MasterContent.xml
         SAXParserFactory factory = SAXParserFactory.newInstance();
         try (InputStream in = new FileInputStream(args[3])) {
-
             SAXParser parser = factory.newSAXParser();
             parser.parse(in, new ContentLoaderHandler(dataSource, ROOT_ELEMENT, false));
         }