[exo-jcr-commits] exo-jcr SVN: r5078 - in jcr/branches/1.12.x/patch/1.12.11-GA: JCR-1684 and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Oct 24 04:55:49 EDT 2011


Author: tolusha
Date: 2011-10-24 04:55:48 -0400 (Mon, 24 Oct 2011)
New Revision: 5078

Added:
   jcr/branches/1.12.x/patch/1.12.11-GA/JCR-1684/
   jcr/branches/1.12.x/patch/1.12.11-GA/JCR-1684/JCR-1684.patch
Log:
JCR-1684: patch proposed

Added: jcr/branches/1.12.x/patch/1.12.11-GA/JCR-1684/JCR-1684.patch
===================================================================
--- jcr/branches/1.12.x/patch/1.12.11-GA/JCR-1684/JCR-1684.patch	                        (rev 0)
+++ jcr/branches/1.12.x/patch/1.12.11-GA/JCR-1684/JCR-1684.patch	2011-10-24 08:55:48 UTC (rev 5078)
@@ -0,0 +1,196 @@
+Index: exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImportVersionHistory.java
+===================================================================
+--- exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImportVersionHistory.java	(revision 5039)
++++ exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImportVersionHistory.java	(working copy)
+@@ -26,6 +26,7 @@
+ 
+ import javax.jcr.ImportUUIDBehavior;
+ import javax.jcr.Node;
++import javax.jcr.Property;
+ import javax.jcr.Value;
+ 
+ /**
+@@ -133,4 +134,82 @@
+       // try to restore first version
+       parent.restore("1", true);
+    }
++
++   public void testImportVersionHistoryWithReferenceableProperty() throws Exception
++   {
++      Node parent = session.getRootNode().addNode("testRoot");
++      parent.addMixin("mix:versionable");
++      session.save();
++
++      parent.checkin();
++      parent.checkout();
++
++      Property prop = parent.getProperty("jcr:versionHistory");
++      Node vh = session.getNodeByUUID(prop.getValue().getString());
++
++      // add ref property to VH
++      parent.setProperty("ref", vh);
++      parent.save();
++
++      // export import version history and node
++      ByteArrayOutputStream out = new ByteArrayOutputStream();
++      session.exportSystemView("/testRoot", out, false, false);
++
++      ByteArrayOutputStream vhout = new ByteArrayOutputStream();
++      session.exportSystemView(parent.getVersionHistory().getPath(), vhout, false, false);
++
++      // prepare data for version import
++      String versionHistory = parent.getProperty("jcr:versionHistory").getValue().getString();
++      String baseVersion = parent.getProperty("jcr:baseVersion").getValue().getString();
++      Value[] jcrPredecessors = parent.getProperty("jcr:predecessors").getValues();
++      StringBuilder jcrPredecessorsBuilder = new StringBuilder();
++      String[] predecessorsHistory;
++      for (Value value : jcrPredecessors)
++      {
++         if (jcrPredecessorsBuilder.length() > 0)
++            jcrPredecessorsBuilder.append(",");
++         jcrPredecessorsBuilder.append(value.getString());
++      }
++      if (jcrPredecessorsBuilder.toString().indexOf(",") > -1)
++      {
++         predecessorsHistory = jcrPredecessorsBuilder.toString().split(",");
++      }
++      else
++      {
++         predecessorsHistory = new String[]{jcrPredecessorsBuilder.toString()};
++      }
++
++      // remove node
++      parent.remove();
++      session.save();
++
++      // import
++      session.importXML("/", new ByteArrayInputStream(out.toByteArray()),
++         ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true);
++
++      session.save();
++
++      parent = (NodeImpl)session.getItem("/testRoot");
++      VersionHistoryImporter versionHistoryImporter =
++         new VersionHistoryImporter((NodeImpl)parent, new ByteArrayInputStream(vhout.toByteArray()), baseVersion,
++            predecessorsHistory, versionHistory);
++      versionHistoryImporter.doImport();
++      session.save();
++
++      // import second time with replace existing flag
++      session.importXML("/", new ByteArrayInputStream(out.toByteArray()),
++         ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING, true);
++
++      session.save();
++
++      parent = (NodeImpl)session.getItem("/testRoot");
++      versionHistoryImporter =
++         new VersionHistoryImporter((NodeImpl)parent, new ByteArrayInputStream(vhout.toByteArray()), baseVersion,
++            predecessorsHistory, versionHistory);
++      versionHistoryImporter.doImport();
++      session.save();
++
++      // try to restore first version
++      parent.restore("1", true);
++   }
+ }
+Index: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java
+===================================================================
+--- exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java	(revision 5039)
++++ exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java	(working copy)
+@@ -588,15 +588,23 @@
+    {
+       try
+       {
+-
+          if (propertyInfo.getName().equals(Constants.JCR_VERSIONHISTORY))
+          {
+             String versionHistoryIdentifier = null;
+             versionHistoryIdentifier = ValueDataConvertor.readString(values.get(0));
+ 
+             currentNodeInfo.setVersionHistoryIdentifier(versionHistoryIdentifier);
+-            currentNodeInfo.setContainsVersionhistory(dataConsumer.getItemData(versionHistoryIdentifier) != null);
+ 
++            // check if node contains VH
++            if (dataConsumer.getItemData(versionHistoryIdentifier) != null)
++            {
++               ItemState vhLastState = getLastItemState(versionHistoryIdentifier);
++               currentNodeInfo.setContainsVersionhistory(vhLastState == null || !vhLastState.isDeleted());
++            }
++            else
++            {
++               currentNodeInfo.setContainsVersionhistory(false);
++            }
+          }
+          else if (propertyInfo.getName().equals(Constants.JCR_BASEVERSION))
+          {
+Index: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java
+===================================================================
+--- exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java	(revision 5039)
++++ exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java	(working copy)
+@@ -590,8 +590,16 @@
+                throw new RepositoryException(e);
+             }
+ 
+-            nodeData
+-               .setContainsVersionhistory(dataConsumer.getItemData(nodeData.getVersionHistoryIdentifier()) != null);
++            // check if node contains VH
++            if (dataConsumer.getItemData(nodeData.getVersionHistoryIdentifier()) != null)
++            {
++               ItemState vhLastState = getLastItemState(nodeData.getVersionHistoryIdentifier());
++               nodeData.setContainsVersionhistory(vhLastState == null || !vhLastState.isDeleted());
++            }
++            else
++            {
++               nodeData.setContainsVersionhistory(false);
++            }
+          }
+          else if (propName.equals(Constants.JCR_BASEVERSION))
+          {
+Index: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/BaseXmlImporter.java
+===================================================================
+--- exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/BaseXmlImporter.java	(revision 5039)
++++ exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/BaseXmlImporter.java	(working copy)
+@@ -347,10 +347,10 @@
+ 
+       PlainChangesLogImpl changes = new PlainChangesLogImpl();
+       // using VH helper as for one new VH, all changes in changes log
+-      new VersionHistoryDataHelper(nodeData, changes, dataConsumer, nodeTypeDataManager, nodeData
+-         .getVersionHistoryIdentifier(), nodeData.getBaseVersionIdentifier());
++      new VersionHistoryDataHelper(nodeData, changes, dataConsumer, nodeTypeDataManager,
++         nodeData.getVersionHistoryIdentifier(), nodeData.getBaseVersionIdentifier());
+ 
+-      if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING && !newVersionHistory)
++      if (!newVersionHistory)
+       {
+          for (ItemState state : changes.getAllStates())
+          {
+@@ -544,7 +544,7 @@
+     * <li>IMPORT_UUID_COLLISION_REMOVE_EXISTING - Remove same uuid item and his
+     * subtree. Also if item MIX_VERSIONABLE, remove version history</li>
+     * <li>IMPORT_UUID_COLLISION_REPLACE_EXISTING - Remove same uuid item and his
+-    * subtree.</li>
++    * subtree. Also if item MIX_VERSIONABLE, remove version history</li>
+     * <li>IMPORT_UUID_COLLISION_THROW - throw new ItemExistsException</li>
+     * </ol>
+     * 
+@@ -587,6 +587,11 @@
+                      removeExisted(sameUuidItem);
+                      break;
+                   case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING :
++                     // remove version history before removing item
++                     if (isMixVersionable)
++                     {
++                        removeVersionHistory(sameUuidItem);
++                     }
+                      removeExisted(sameUuidItem);
+                      ItemData parentOfsameUuidItem = dataConsumer.getItemData(sameUuidItem.getParentIdentifier());
+                      tree.push(ImportNodeData.createCopy((NodeData)parentOfsameUuidItem));
+@@ -644,7 +649,7 @@
+     * @param identifer
+     * @return
+     */
+-   private ItemState getLastItemState(String identifer)
++   protected ItemState getLastItemState(String identifer)
+    {
+       List<ItemState> allStates = changesLog.getAllStates();
+       for (int i = allStates.size() - 1; i >= 0; i--)



More information about the exo-jcr-commits mailing list