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());
}
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);
}
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;
}
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);
}
}
Aggregations