use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.
the class VersionedDocumentBundlingTest method restoreVersionedNode.
@Test
public void restoreVersionedNode() throws Exception {
String assetParentPath = "/bundlingtest/par";
Node asset = JcrUtils.getOrCreateByPath(assetParentPath + "/foo.png", "oak:Unstructured", "oak:Asset", s, false);
Node assetParent = s.getNode(assetParentPath);
assetParent.addMixin(JcrConstants.MIX_VERSIONABLE);
asset.addNode("jcr:content", "oak:Unstructured");
s.save();
VersionManager vm = s.getWorkspace().getVersionManager();
Version version = vm.checkin(assetParentPath);
vm.checkout(assetParentPath);
asset.getNode("jcr:content").setProperty("foo1", "bar1");
s.save();
vm.restore(version, true);
}
use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.
the class CopyVersionHistoryTest method assertVersionableProperties.
private static void assertVersionableProperties(final Session session, final String... names) throws RepositoryException {
VersionManager vMgr = session.getWorkspace().getVersionManager();
for (final String mixin : MIXINS) {
final String pathPrefix = VERSIONABLES_PATH_PREFIX + mixin + "/";
for (final String name : names) {
final String path = pathPrefix + name;
Node versionable = session.getNode(path);
String versionHistoryUuid = versionable.getProperty(JCR_VERSIONHISTORY).getString();
assertEquals(getVersionHistoryForPath(session, path).getIdentifier(), versionHistoryUuid);
final Version baseVersion = vMgr.getBaseVersion(path);
assertEquals("1.2", baseVersion.getName());
final Value[] predecessors = versionable.getProperty(JCR_PREDECESSORS).getValues();
assertEquals(1, predecessors.length);
assertEquals(baseVersion.getIdentifier(), predecessors[0].getString());
}
}
}
use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.
the class BrokenVersionableTest method createSourceContent.
private NodeStore createSourceContent() throws Exception {
SegmentNodeStore source = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
RepositoryImpl repository = (RepositoryImpl) new Jcr(new Oak(source)).createRepository();
Session session = repository.login(CREDENTIALS);
List<String> versionHistoryPaths = new ArrayList<String>();
try {
CndImporter.registerNodeTypes(new StringReader("<test = 'http://jackrabbit.apache.org/ns/test'>\n" + "[test:Versionable] > nt:unstructured, mix:versionable"), session);
Node root = session.getRootNode();
Node versionable1 = root.addNode("versionable1", NT_UNSTRUCTURED);
versionable1.addMixin(MIX_VERSIONABLE);
versionable1.addNode("child", NT_UNSTRUCTURED);
Node versionable2 = root.addNode("versionable2", "test:Versionable");
versionable2.addNode("child", NT_UNSTRUCTURED);
session.save();
VersionManager vMgr = session.getWorkspace().getVersionManager();
vMgr.checkin("/versionable1");
vMgr.checkin("/versionable2");
versionHistoryPaths.add(vMgr.getVersionHistory("/versionable1").getPath());
versionHistoryPaths.add(vMgr.getVersionHistory("/versionable2").getPath());
} finally {
session.logout();
repository.shutdown();
}
// remove version history to corrupt the JCR repository structure
NodeBuilder rootBuilder = source.getRoot().builder();
for (String versionHistoryPath : versionHistoryPaths) {
NodeStateTestUtils.createOrGetBuilder(rootBuilder, versionHistoryPath).remove();
}
source.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
return source;
}
use of javax.jcr.version.VersionManager in project jackrabbit by apache.
the class RemoveVersionTest method testRemoveAllVersions.
/**
* Creates 3 versions and removes them afterwards. Checks if version history
* was purged, too.
*
* Tests error reported in JCR-2601
*
* @throws Exception if an error occurs
*/
public void testRemoveAllVersions() throws Exception {
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
superuser.save();
String path = n.getPath();
// create some versions
VersionManager mgr = superuser.getWorkspace().getVersionManager();
// v1.0
mgr.checkpoint(path);
// v1.1
mgr.checkpoint(path);
// v1.2
mgr.checkpoint(path);
// get version history
VersionHistory vh = mgr.getVersionHistory(path);
String id = vh.getIdentifier();
// remove versionable node
n.remove();
superuser.save();
// get the names of the versions
List<String> names = new LinkedList<String>();
VersionIterator vit = vh.getAllVersions();
while (vit.hasNext()) {
Version v = vit.nextVersion();
if (!v.getName().equals("jcr:rootVersion")) {
names.add(v.getName());
}
}
assertEquals("Number of versions", 3, names.size());
// remove all versions
for (String name : names) {
vh.removeVersion(name);
}
// assert that version history is gone
try {
superuser.getNodeByIdentifier(id);
fail("Version history not removed after last version was removed.");
} catch (RepositoryException e) {
// ok
}
}
use of javax.jcr.version.VersionManager in project jackrabbit by apache.
the class VersionControlledItemCollection method resolveMergeConflict.
/**
* Resolve one or multiple merge conflicts present on this resource. Please
* note that the 'setProperties' or 'removeProperties' set my contain additional
* resource properties, that need to be changed. Those properties are left
* untouched, whereas the {@link #AUTO_MERGE_SET DAV:auto-merge-set}, is
* removed from the list upon successful resolution of a merge conflict.<br>
* If the removeProperties or setProperties set do not contain the mentioned
* merge conflict resource properties or if the value of those properties do
* not allow for a resolution of an existing merge conflict, this method
* returns silently.
*
* @param changeList
* @throws org.apache.jackrabbit.webdav.DavException
* @see Node#doneMerge(Version)
* @see Node#cancelMerge(Version)
*/
private void resolveMergeConflict(List<? extends PropEntry> changeList) throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
try {
Node n = (Node) item;
VersionManager vMgr = getVersionManager();
String path = item.getPath();
DavProperty<?> autoMergeSet = null;
DavProperty<?> predecessorSet = null;
/* find DAV:auto-merge-set entries. If none exists no attempt is made
to resolve merge conflict > return silently */
for (int i = 0; i < changeList.size(); i++) {
PropEntry propEntry = changeList.get(i);
// conflicts are resolved with 'cancel'
if (propEntry instanceof DavPropertyName && AUTO_MERGE_SET.equals(propEntry)) {
// retrieve the current jcr:mergeFailed property values
if (!n.hasProperty(JcrConstants.JCR_MERGEFAILED)) {
throw new DavException(DavServletResponse.SC_CONFLICT, "Attempt to resolve non-existing merge conflicts.");
}
Value[] mergeFailed = n.getProperty(JcrConstants.JCR_MERGEFAILED).getValues();
for (Value value : mergeFailed) {
vMgr.cancelMerge(path, (Version) getRepositorySession().getNodeByIdentifier(value.getString()));
}
// remove this entry from the changeList
changeList.remove(propEntry);
} else if (propEntry instanceof DavProperty) {
if (AUTO_MERGE_SET.equals(((DavProperty<?>) propEntry).getName())) {
autoMergeSet = (DavProperty<?>) propEntry;
} else if (PREDECESSOR_SET.equals(((DavProperty<?>) propEntry).getName())) {
predecessorSet = (DavProperty<?>) propEntry;
}
}
}
// resolved individually according to the DAV:predecessor-set property.
if (autoMergeSet != null) {
// retrieve the current jcr:mergeFailed property values
if (!n.hasProperty(JcrConstants.JCR_MERGEFAILED)) {
throw new DavException(DavServletResponse.SC_CONFLICT, "Attempt to resolve non-existing merge conflicts.");
}
List<String> mergeset = new HrefProperty(autoMergeSet).getHrefs();
List<String> predecL;
if (predecessorSet == null) {
predecL = Collections.emptyList();
} else {
predecL = new HrefProperty(predecessorSet).getHrefs();
}
Session session = getRepositorySession();
// loop over the mergeFailed values (versions) and test whether they are
// removed from the DAV:auto-merge-set thus indicating resolution.
Value[] mergeFailed = n.getProperty(JcrConstants.JCR_MERGEFAILED).getValues();
for (Value value : mergeFailed) {
// build version-href from each entry in the jcr:mergeFailed property
// in order to be able to compare to the entries in the HrefProperty.
Version version = (Version) session.getNodeByIdentifier(value.getString());
String href = getLocatorFromItem(version).getHref(true);
// thus indicating that this merge conflict needs to be resolved.
if (!mergeset.contains(href)) {
// must be called.
if (predecL.contains(href)) {
vMgr.doneMerge(path, version);
} else {
vMgr.cancelMerge(path, version);
}
}
}
// after successful resolution of merge-conflicts according to
// DAV:auto-merge-set and DAV:predecessor-set remove these entries
// from the changeList.
changeList.remove(autoMergeSet);
if (predecessorSet != null) {
changeList.remove(predecessorSet);
}
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
Aggregations