]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoSync.java
Deal with already existing MANIFEST
[gpl/argeo-slc.git] / runtime / org.argeo.slc.repo / src / main / java / org / argeo / slc / repo / RepoSync.java
index 8d0147ec00c3259be9b0d608531fefc38ce3a30a..7f1e1e32d2f70b7cd4e4f6424dbaf6f2dc755445 100644 (file)
@@ -206,8 +206,10 @@ public class RepoSync implements Runnable {
                                        .getQueryManager()
                                        .createQuery(
                                                        "select file from ["
-                                                                       + (true ? "nt:file" : "nt:base")
-                                                                       + "] as file", Query.JCR_SQL2);
+                                                                       + (true ? NodeType.NT_FILE
+                                                                                       : NodeType.NT_BASE) + "] as file",
+                                                       Query.JCR_SQL2);
+
                        QueryResult result = countQuery.execute();
                        Long expectedCount = result.getNodes().getSize();
                        return expectedCount;
@@ -248,6 +250,7 @@ public class RepoSync implements Runnable {
                        if (log.isDebugEnabled())
                                log.debug("Synced " + sourceSession.getWorkspace().getName());
                } catch (Exception e) {
+                       e.printStackTrace();
                        throw new SlcException("Cannot sync "
                                        + sourceSession.getWorkspace().getName() + " to "
                                        + targetSession.getWorkspace().getName(), e);
@@ -262,78 +265,81 @@ public class RepoSync implements Runnable {
        protected void syncNode(Node sourceNode, Session targetSession)
                        throws RepositoryException, SAXException {
                // Boolean singleLevel = singleLevel(sourceNode);
+               try {
+                       if (monitor != null && monitor.isCanceled()) {
+                               updateMonitor("Fetched has been canceled, "
+                                               + "process is terminating");
+                               return;
+                       }
 
-               if (monitor != null && monitor.isCanceled()) {
-                       updateMonitor("Fetched has been canceled, "
-                                       + "process is terminating");
-                       return;
-               }
-
-               Node targetParentNode = targetSession.getNode(sourceNode.getParent()
-                               .getPath());
-               Node targetNode;
-               if (monitor != null
-                               && sourceNode.isNodeType(NodeType.NT_HIERARCHY_NODE))
-                       monitor.subTask("Process " + sourceNode.getPath());
-
-               final Boolean isNew;
-               if (!targetSession.itemExists(sourceNode.getPath())) {
-                       isNew = true;
-                       targetNode = targetParentNode.addNode(sourceNode.getName(),
-                                       sourceNode.getPrimaryNodeType().getName());
-               } else {
-                       isNew = false;
-                       targetNode = targetSession.getNode(sourceNode.getPath());
-                       if (!targetNode.getPrimaryNodeType().getName()
-                                       .equals(sourceNode.getPrimaryNodeType().getName()))
-                               targetNode.setPrimaryType(sourceNode.getPrimaryNodeType()
-                                               .getName());
-               }
+                       Node targetParentNode = targetSession.getNode(sourceNode
+                                       .getParent().getPath());
+                       Node targetNode;
+                       if (monitor != null
+                                       && sourceNode.isNodeType(NodeType.NT_HIERARCHY_NODE))
+                               monitor.subTask("Process " + sourceNode.getPath());
+
+                       final Boolean isNew;
+                       if (!targetSession.itemExists(sourceNode.getPath())) {
+                               isNew = true;
+                               targetNode = targetParentNode.addNode(sourceNode.getName(),
+                                               sourceNode.getPrimaryNodeType().getName());
+                       } else {
+                               isNew = false;
+                               targetNode = targetSession.getNode(sourceNode.getPath());
+                               if (!targetNode.getPrimaryNodeType().getName()
+                                               .equals(sourceNode.getPrimaryNodeType().getName()))
+                                       targetNode.setPrimaryType(sourceNode.getPrimaryNodeType()
+                                                       .getName());
+                       }
 
-               // export
-               // sourceNode.getSession().exportSystemView(sourceNode.getPath(),
-               // contentHandler, false, singleLevel);
-
-               // if (singleLevel) {
-               // if (targetSession.hasPendingChanges()) {
-               // // updateMonitor(
-               // // (isNew ? "Added " : "Updated ") + targetNode.getPath(),
-               // // true);
-               // if (doSave)
-               // targetSession.save();
-               // } else {
-               // // updateMonitor("Checked " + targetNode.getPath(), false);
-               // }
-               // }
-
-               // mixin and properties
-               for (NodeType nt : sourceNode.getMixinNodeTypes()) {
-                       if (!targetNode.isNodeType(nt.getName())
-                                       && targetNode.canAddMixin(nt.getName()))
-                               targetNode.addMixin(nt.getName());
-               }
-               copyProperties(sourceNode, targetNode);
+                       // export
+                       // sourceNode.getSession().exportSystemView(sourceNode.getPath(),
+                       // contentHandler, false, singleLevel);
+
+                       // if (singleLevel) {
+                       // if (targetSession.hasPendingChanges()) {
+                       // // updateMonitor(
+                       // // (isNew ? "Added " : "Updated ") + targetNode.getPath(),
+                       // // true);
+                       // if (doSave)
+                       // targetSession.save();
+                       // } else {
+                       // // updateMonitor("Checked " + targetNode.getPath(), false);
+                       // }
+                       // }
+
+                       // mixin and properties
+                       for (NodeType nt : sourceNode.getMixinNodeTypes()) {
+                               if (!targetNode.isNodeType(nt.getName())
+                                               && targetNode.canAddMixin(nt.getName()))
+                                       targetNode.addMixin(nt.getName());
+                       }
+                       copyProperties(sourceNode, targetNode);
 
-               // next level
-               for (NodeIterator ni = sourceNode.getNodes(); ni.hasNext();) {
-                       Node sourceChild = ni.nextNode();
-                       syncNode(sourceChild, targetSession);
-               }
+                       // next level
+                       NodeIterator ni = sourceNode.getNodes();
+                       while (ni != null && ni.hasNext()) {
+                               Node sourceChild = ni.nextNode();
+                               syncNode(sourceChild, targetSession);
+                       }
 
-               copyTimestamps(sourceNode, targetNode);
+                       copyTimestamps(sourceNode, targetNode);
 
-               if (sourceNode.isNodeType(NodeType.NT_HIERARCHY_NODE)) {
-                       if (targetSession.hasPendingChanges()) {
-                               if (sourceNode.isNodeType(NodeType.NT_FILE))
-                                       updateMonitor(
-                                                       (isNew ? "Added " : "Updated ")
-                                                                       + targetNode.getPath(), true);
-                               // if (doSave)
-                               targetSession.save();
-                       } else {
-                               if (sourceNode.isNodeType(NodeType.NT_FILE))
-                                       updateMonitor("Checked " + targetNode.getPath(), false);
+                       if (sourceNode.isNodeType(NodeType.NT_HIERARCHY_NODE)) {
+                               if (targetSession.hasPendingChanges()) {
+                                       if (sourceNode.isNodeType(NodeType.NT_FILE))
+                                               updateMonitor((isNew ? "Added " : "Updated ")
+                                                               + targetNode.getPath(), true);
+                                       // if (doSave)
+                                       targetSession.save();
+                               } else {
+                                       if (sourceNode.isNodeType(NodeType.NT_FILE))
+                                               updateMonitor("Checked " + targetNode.getPath(), false);
+                               }
                        }
+               } catch (RepositoryException e) {
+                       throw new SlcException("Cannot sync source node " + sourceNode, e);
                }
        }