use of javax.jcr.version.Version in project jackrabbit by apache.
the class VersionControlledResourceImpl method checkin.
/**
* Calls {@link javax.jcr.Node#checkin()} on the underlying repository node.
*
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionControlledResource#checkin()
*/
public String checkin() throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
if (!isVersionControlled()) {
throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
}
try {
Version v = getNode().checkin();
String versionHref = getLocatorFromNode(v).getHref(false);
return versionHref;
} catch (RepositoryException e) {
// UnsupportedRepositoryException should not occur
throw new JcrDavException(e);
}
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class VersionItemCollection method getProperty.
@Override
public DavProperty<?> getProperty(DavPropertyName name) {
DavProperty prop = super.getProperty(name);
if (prop == null && exists()) {
Version v = (Version) item;
try {
if (VERSION_NAME.equals(name)) {
// required, protected DAV:version-name property
prop = new DefaultDavProperty<String>(VERSION_NAME, v.getName(), true);
} else if (VERSION_HISTORY.equals(name)) {
// required DAV:version-history (computed) property
String vhHref = getLocatorFromItem(getVersionHistoryItem()).getHref(true);
prop = new HrefProperty(VERSION_HISTORY, vhHref, true);
} else if (PREDECESSOR_SET.equals(name)) {
// required DAV:predecessor-set (protected) property
prop = getHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true);
} else if (SUCCESSOR_SET.equals(name)) {
// required DAV:successor-set (computed) property
prop = getHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true);
} else if (LABEL_NAME_SET.equals(name)) {
// required, protected DAV:label-name-set property
String[] labels = getVersionHistoryItem().getVersionLabels(v);
prop = new LabelSetProperty(labels);
} else if (CHECKOUT_SET.equals(name)) {
// required DAV:checkout-set (computed) property
PropertyIterator it = v.getReferences();
List<Node> nodeList = new ArrayList<Node>();
while (it.hasNext()) {
Property p = it.nextProperty();
if (JcrConstants.JCR_BASEVERSION.equals(p.getName())) {
Node n = p.getParent();
if (n.isCheckedOut()) {
nodeList.add(n);
}
}
}
prop = getHrefProperty(CHECKOUT_SET, nodeList.toArray(new Node[nodeList.size()]), true);
}
} catch (RepositoryException e) {
log.error(e.getMessage());
}
}
return prop;
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class VersionHistoryResourceImpl method getMembers.
//--------------------------------------------------------< DavResource >---
/**
* Show all versions of this history as members.
*
* @return
* @see DavResource#getMembers()
*/
@Override
public DavResourceIterator getMembers() {
ArrayList<DavResource> list = new ArrayList<DavResource>();
if (exists() && isCollection()) {
try {
// only display versions as members of the vh. the jcr:versionLabels
// node is an internal structure.
VersionIterator it = ((VersionHistory) getNode()).getAllVersions();
while (it.hasNext()) {
// omit item filter here. if the version history is visible
// its versions should be visible as well.
Version v = it.nextVersion();
DavResourceLocator vhLocator = getLocator();
DavResourceLocator resourceLocator = vhLocator.getFactory().createResourceLocator(vhLocator.getPrefix(), vhLocator.getWorkspacePath(), v.getPath(), false);
DavResource childRes = getFactory().createResource(resourceLocator, getSession());
list.add(childRes);
}
} catch (RepositoryException e) {
// should not occur
log.error("Unexpected error", e);
} catch (DavException e) {
// should not occur
log.error("Unexpected error", e);
}
}
return new DavResourceIteratorImpl(list);
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class RestoreTest method testRestoreOrderJcr2_3.
/**
* Test the child ordering of restored nodes.
* @throws RepositoryException
*/
public void testRestoreOrderJcr2_3() throws RepositoryException, NotExecutableException {
// create a test-root that has orderable child nodes
Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
ensureMixinType(testRoot, mixVersionable);
versionableNode.getSession().save();
// create children of vNode and checkin
Node child1 = testRoot.addNode(nodeName1);
ensureMixinType(child1, mixVersionable);
Node child2 = testRoot.addNode(nodeName2);
ensureMixinType(child2, mixVersionable);
testRoot.getSession().save();
versionManager.checkin(child1.getPath());
versionManager.checkin(child2.getPath());
Version v1 = versionManager.checkin(testRoot.getPath());
// remove node 1
versionManager.checkout(testRoot.getPath());
child1.remove();
testRoot.getSession().save();
versionManager.checkout(testRoot.getPath());
// restore version 1.0
versionManager.restore(testRoot.getPath(), v1.getName(), true);
// check order
NodeIterator iter = testRoot.getNodes();
assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
Node n1 = iter.nextNode();
assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
Node n2 = iter.nextNode();
String orderOk = nodeName1 + ", " + nodeName2;
String order = n1.getName() + ", " + n2.getName();
assertEquals("Invalid child node ordering", orderOk, order);
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class WorkspaceRestoreTest method testWorkspaceRestoreWithParent.
/**
* Test if Workspace.restore(Version[], boolean) succeeds if the following two
* preconditions are fulfilled:<ul>
* <li>For every version V in S that corresponds to a missing node in the workspace,
* there must also be a parent of V in S.</li>
* <li>S must contain at least one version that corresponds to an existing
* node in the workspace.</li>
* </ul>
*/
@SuppressWarnings("deprecation")
public void testWorkspaceRestoreWithParent() throws RepositoryException {
try {
Version parentV = wVersionableNode.checkin();
superuser.getWorkspace().restore(new Version[] { parentV, wChildVersion }, false);
} catch (RepositoryException e) {
fail("Workspace.restore(Version[], boolean) with a version that has no corresponding node must succeed if a version of a parent with correspondance is present in the version array.");
}
}
Aggregations