Author: trang_vu
Date: 2011-11-04 07:57:14 -0400 (Fri, 04 Nov 2011)
New Revision: 5164
Added:
jcr/branches/1.12.x/patch/1.12.11-GA/JCR-1684/readme.txt
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/BaseXmlImporter.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImportVersionHistory.java
Log:
JCR-1684: Exception when we import the same node twice with its version history
Fix description
* Remove the version history of the node during import operation.
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/BaseXmlImporter.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/BaseXmlImporter.java 2011-11-04
11:22:25 UTC (rev 5163)
+++
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/BaseXmlImporter.java 2011-11-04
11:57:14 UTC (rev 5164)
@@ -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--)
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java 2011-11-04
11:22:25 UTC (rev 5163)
+++
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java 2011-11-04
11:57:14 UTC (rev 5164)
@@ -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))
{
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java 2011-11-04
11:22:25 UTC (rev 5163)
+++
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java 2011-11-04
11:57:14 UTC (rev 5164)
@@ -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))
{
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImportVersionHistory.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImportVersionHistory.java 2011-11-04
11:22:25 UTC (rev 5163)
+++
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImportVersionHistory.java 2011-11-04
11:57:14 UTC (rev 5164)
@@ -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);
+ }
}
Added: jcr/branches/1.12.x/patch/1.12.11-GA/JCR-1684/readme.txt
===================================================================
--- jcr/branches/1.12.x/patch/1.12.11-GA/JCR-1684/readme.txt (rev
0)
+++ jcr/branches/1.12.x/patch/1.12.11-GA/JCR-1684/readme.txt 2011-11-04 11:57:14 UTC (rev
5164)
@@ -0,0 +1,62 @@
+Summary
+
+ * Status: exception when we import the same node twice with its version history
+ * CCP Issue: CCP-1124, Product Jira Issue: JCR-1684.
+ * Complexity: Medium
+
+The Proposal
+Problem description
+
+What is the problem to fix?
+
+ * Exception when we import the same node twice with its version history
+
+Fix description
+
+How is the problem fixed?
+
+* Remove the version history of the node during import operation
+
+Patch file: JCR-1684.patch
+
+Tests to perform
+
+Reproduction test
+* TestImportVersionHistory
+
+Tests performed at DevLevel
+ * functional tests, manual testing on PLF 3.0.x
+
+Tests performed at QA/Support Level
+*
+Documentation changes
+
+Documentation changes:
+ * No
+Configuration changes
+
+Configuration changes:
+ * No
+
+Will previous configuration continue to work?
+ * Yes
+
+Risks and impacts
+
+Can this bug fix have any side effects on current client projects?
+
+ * No
+
+Is there a performance risk/cost?
+ * No
+
+Validation (PM/Support/QA)
+
+PM Comment
+* PM validated
+
+Support Comment
+* Support validated
+
+QA Feedbacks
+*