Search in sources :

Example 36 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit by apache.

the class VersionHistoryResourceImpl method initProperties.

//--------------------------------------------------------------------------
/**
     * Fill the property set for this resource.
     */
@Override
protected void initProperties() {
    if (!propsInitialized) {
        super.initProperties();
        // change resource type defined by default item collection
        properties.add(new ResourceType(new int[] { ResourceType.COLLECTION, ResourceType.VERSION_HISTORY }));
        // required root-version property for version-history resource
        try {
            String rootVersionHref = getLocatorFromNode(((VersionHistory) getNode()).getRootVersion()).getHref(false);
            properties.add(new HrefProperty(VersionHistoryResource.ROOT_VERSION, rootVersionHref, false));
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
        // required, protected version-set property for version-history resource
        try {
            VersionIterator vIter = ((VersionHistory) getNode()).getAllVersions();
            ArrayList<Version> l = new ArrayList<Version>();
            while (vIter.hasNext()) {
                l.add(vIter.nextVersion());
            }
            properties.add(getHrefProperty(VersionHistoryResource.VERSION_SET, l.toArray(new Version[l.size()]), true, false));
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
    }
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Version(javax.jcr.version.Version) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) ResourceType(org.apache.jackrabbit.webdav.property.ResourceType) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory)

Example 37 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit by apache.

the class VersionResourceImpl method getVersionHistory.

/**
     * Returns the {@link VersionHistory} associated with the repository version.
     * Note: in contrast to a versionable node, the version history of a version
     * item is always represented by its nearest ancestor.
     *
     * @return the {@link org.apache.jackrabbit.webdav.version.VersionHistoryResource} associated with this resource.
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionResource#getVersionHistory()
     * @see javax.jcr.Item#getParent()
     */
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        VersionHistory vh = getVersionHistoryItem();
        DavResourceLocator loc = getLocatorFromNode(vh);
        DavResource vhr = createResourceFromLocator(loc);
        if (vhr instanceof VersionHistoryResource) {
            return (VersionHistoryResource) vhr;
        } else {
            // severe error since resource factory doesn't behave correctly.
            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 38 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit by apache.

the class ResourceFactoryImpl method createResource.

/**
     * Tries to retrieve the repository item defined by the locator's resource
     * path and build the corresponding WebDAV resource. If the repository
     * supports the versioning option different resources are created for
     * version, versionhistory and common nodes.
     *
     * @param node
     * @param locator
     * @param session
     * @return
     * @throws DavException
     */
private DavResource createResource(Node node, DavResourceLocator locator, DavSession session) throws DavException {
    JcrDavSession.checkImplementation(session);
    JcrDavSession sessionImpl = (JcrDavSession) session;
    DavResource resource;
    if (versioningSupported(sessionImpl.getRepositorySession())) {
        // create special resources for Version and VersionHistory
        if (node instanceof Version) {
            resource = new VersionResourceImpl(locator, this, sessionImpl, resourceConfig, node);
        } else if (node instanceof VersionHistory) {
            resource = new VersionHistoryResourceImpl(locator, this, sessionImpl, resourceConfig, node);
        } else {
            resource = new VersionControlledResourceImpl(locator, this, sessionImpl, resourceConfig, node);
        }
    } else {
        resource = new DavResourceImpl(locator, this, session, resourceConfig, node);
    }
    return resource;
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) Version(javax.jcr.version.Version) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) VersionHistory(javax.jcr.version.VersionHistory)

Example 39 with VersionHistory

use of javax.jcr.version.VersionHistory 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
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) RepositoryException(javax.jcr.RepositoryException) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) LinkedList(java.util.LinkedList)

Example 40 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit by apache.

the class VersionHistoryItemCollection method initProperties.

/**
     * Fill the property set for this resource.
     */
@Override
protected void initProperties() {
    super.initProperties();
    // change resource type defined by default item collection
    properties.add(new ResourceType(ResourceType.VERSION_HISTORY));
    // jcr specific property pointing to the node this history belongs to
    try {
        properties.add(new DefaultDavProperty<String>(JCR_VERSIONABLEUUID, ((VersionHistory) item).getVersionableIdentifier()));
    } catch (RepositoryException e) {
        log.error(e.getMessage());
    }
}
Also used : ResourceType(org.apache.jackrabbit.webdav.property.ResourceType) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory)

Aggregations

VersionHistory (javax.jcr.version.VersionHistory)73 Node (javax.jcr.Node)45 Version (javax.jcr.version.Version)29 Test (org.junit.Test)25 RepositoryException (javax.jcr.RepositoryException)17 VersionManager (javax.jcr.version.VersionManager)17 Session (javax.jcr.Session)12 VersionIterator (javax.jcr.version.VersionIterator)12 Property (javax.jcr.Property)7 DavException (org.apache.jackrabbit.webdav.DavException)7 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)7 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 ArrayList (java.util.ArrayList)6 DavResource (org.apache.jackrabbit.webdav.DavResource)6 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)4 Workspace (javax.jcr.Workspace)3 VersionException (javax.jcr.version.VersionException)3 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)3 PathNotFoundException (javax.jcr.PathNotFoundException)2