Search in sources :

Example 86 with VersionHistory

use of javax.jcr.version.VersionHistory in project pentaho-platform by pentaho.

the class JcrRepositoryFileUtilsTest method testCheckinNearestVersionableNodeIfNecessaryWithoutVersioning.

@Test
public void testCheckinNearestVersionableNodeIfNecessaryWithoutVersioning() throws Exception {
    String versionMessage = "Version message";
    String username = "admin";
    String mockNodeId = "12345";
    String versionName = "versionName";
    String versionableIdentifier = "versionableIdentifier";
    Date curDate = new Date();
    Calendar cal = Calendar.getInstance();
    if (curDate != null) {
        cal.setTime(curDate);
    } else {
        cal.setTime(new Date());
    }
    // disable versioning
    JcrRepositoryFileUtils.setRepositoryVersionManager(repositoryVersionManagerMockFalse);
    Node mockNode = mock(Node.class);
    Node parentNode = mock(Node.class);
    Node versionNode = mock(Node.class);
    Version mockVersion = mock(Version.class);
    Version mockVersion2 = mock(Version.class);
    VersionManagerImpl versionManager = mock(VersionManagerImpl.class);
    VersionHistory mockVersionHistory = mock(VersionHistory.class);
    IPentahoSession pentahoSession = mock(IPentahoSession.class);
    when(pentahoSession.getName()).thenReturn(username);
    when(sessionMock.getNodeByIdentifier(nullable(String.class))).thenReturn(mockNode);
    String[] mockVersionLabels = { "label1" };
    when(mockVersionHistory.getVersionLabels(mockVersion)).thenReturn(mockVersionLabels);
    when(mockVersionHistory.getVersionableIdentifier()).thenReturn(versionableIdentifier);
    Version[] mockVersionsList = { mockVersion, mockVersion2 };
    Version[] mockVersionsList2 = { mockVersion };
    when(mockVersion.getSuccessors()).thenReturn(mockVersionsList, mockVersionsList2, null);
    when(mockVersion.getNode(any())).thenReturn(versionNode);
    when(mockVersion.getName()).thenReturn(versionName);
    when(mockVersion.getCreated()).thenReturn(cal);
    when(versionManager.getVersionHistory(mockNode.getPath())).thenReturn(mockVersionHistory);
    when(workspaceMock.getVersionManager()).thenReturn(versionManager);
    when(mockVersionHistory.getRootVersion()).thenReturn(mockVersion);
    when(mockNode.getIdentifier()).thenReturn(mockNodeId);
    PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(sessionMock);
    when(mockNode.isNodeType(pentahoJcrConstants.getPHO_MIX_VERSIONABLE())).thenReturn(Boolean.TRUE);
    PentahoSessionHolder.setSession(pentahoSession);
    JcrRepositoryFileUtils.checkinNearestVersionableNodeIfNecessary(sessionMock, pentahoJcrConstants, mockNode, versionMessage, curDate, true);
    // verify checkin was called
    verify(versionManager).checkin(mockNode.getPath(), cal);
    // verify version is deleted
    verify(mockVersionHistory).removeVersion(any());
}
Also used : VersionManagerImpl(org.apache.jackrabbit.core.VersionManagerImpl) Version(javax.jcr.version.Version) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Calendar(java.util.Calendar) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Date(java.util.Date) Test(org.junit.Test)

Example 87 with VersionHistory

use of javax.jcr.version.VersionHistory in project pentaho-platform by pentaho.

the class JcrRepositoryFileUtils method getVersionSummary.

public static Object getVersionSummary(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId, final Serializable versionId) throws RepositoryException {
    VersionManager vMgr = session.getWorkspace().getVersionManager();
    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    VersionHistory versionHistory = vMgr.getVersionHistory(fileNode.getPath());
    Version version = null;
    if (versionId != null) {
        version = versionHistory.getVersion(versionId.toString());
    } else {
        version = vMgr.getBaseVersion(fileNode.getPath());
    }
    return toVersionSummary(pentahoJcrConstants, versionHistory, version);
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) VersionHistory(javax.jcr.version.VersionHistory)

Example 88 with VersionHistory

use of javax.jcr.version.VersionHistory in project pentaho-platform by pentaho.

the class JcrRepositoryFileUtils method getVersionSummaries.

public static Object getVersionSummaries(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId, final boolean includeAclOnlyChanges) throws RepositoryException {
    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    VersionHistory versionHistory = session.getWorkspace().getVersionManager().getVersionHistory(fileNode.getPath());
    // get root version but don't include it in version summaries; from JSR-170 specification section 8.2.5:
    // [root version] is a dummy version that serves as the starting point of the version graph. Like all version
    // nodes,
    // it has a subnode called jcr:frozenNode. But, in this case that frozen node does not contain any state
    // information
    // about N
    Version version = versionHistory.getRootVersion();
    Version[] successors = version.getSuccessors();
    List<VersionSummary> versionSummaries = new ArrayList<VersionSummary>();
    while (successors != null && successors.length > 0) {
        // branching not supported
        version = successors[0];
        VersionSummary sum = toVersionSummary(pentahoJcrConstants, versionHistory, version);
        if (!sum.isAclOnlyChange() || (includeAclOnlyChanges && sum.isAclOnlyChange())) {
            versionSummaries.add(sum);
        }
        successors = version.getSuccessors();
    }
    return versionSummaries;
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary) VersionHistory(javax.jcr.version.VersionHistory)

Example 89 with VersionHistory

use of javax.jcr.version.VersionHistory in project pentaho-platform by pentaho.

the class RepositoryCleaner method findVersionNodesAndPurge.

private void findVersionNodesAndPurge(Node node, Session session) {
    if (node == null || session == null) {
        return;
    }
    try {
        if (node.getName().equals(JCR_FROZEN_NODE) && node.hasProperty(JCR_FROZEN_UUID) && !node.getParent().getName().equals(JCR_ROOT_VERSION)) {
            // Version Node
            Property property = node.getProperty(JCR_FROZEN_UUID);
            Value uuid = property.getValue();
            Node nodeByIdentifier = null;
            try {
                nodeByIdentifier = session.getNodeByIdentifier(uuid.getString());
                nodeByIdentifier = session.getNode(nodeByIdentifier.getPath());
            } catch (RepositoryException ex) {
            // ignored this means the node is gone.
            }
            if (nodeByIdentifier == null) {
                // node is gone
                logger.info("Removed orphan version: " + node.getPath());
                ((VersionHistory) node.getParent().getParent()).removeVersion(node.getParent().getName());
            }
        }
    } catch (RepositoryException e) {
        logger.error("Error purging version nodes. Routine will continue", e);
    }
    NodeIterator nodes = null;
    try {
        nodes = node.getNodes();
    } catch (RepositoryException e) {
        logger.error("Error purging version nodes. Routine will continue", e);
    }
    if (nodes == null) {
        return;
    }
    while (nodes.hasNext()) {
        findVersionNodesAndPurge(nodes.nextNode(), session);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property)

Aggregations

VersionHistory (javax.jcr.version.VersionHistory)89 Node (javax.jcr.Node)59 Version (javax.jcr.version.Version)43 Test (org.junit.Test)30 VersionManager (javax.jcr.version.VersionManager)26 RepositoryException (javax.jcr.RepositoryException)25 VersionIterator (javax.jcr.version.VersionIterator)23 Session (javax.jcr.Session)19 Property (javax.jcr.Property)11 ArrayList (java.util.ArrayList)8 DavException (org.apache.jackrabbit.webdav.DavException)7 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)7 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 Workspace (javax.jcr.Workspace)6 DavResource (org.apache.jackrabbit.webdav.DavResource)6 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 Value (javax.jcr.Value)5 NodeIterator (javax.jcr.NodeIterator)4 PathNotFoundException (javax.jcr.PathNotFoundException)4 NodeType (javax.jcr.nodetype.NodeType)4