use of org.apache.jackrabbit.core.VersionManagerImpl in project pentaho-platform by pentaho.
the class JcrRepositoryFileUtilsTest method testCheckinNearestVersionableNodeIfNecessary.
@Test
public void testCheckinNearestVersionableNodeIfNecessary() throws Exception {
String versionMessage = "Version message";
String username = "admin";
Date curDate = new Date();
Node mockNode = mock(Node.class);
Node parentNode = mock(Node.class);
IPentahoSession pentahoSession = mock(IPentahoSession.class);
when(pentahoSession.getName()).thenReturn(username);
JcrRepositoryFileUtils.setRepositoryVersionManager(repositoryVersionManagerMockTrue);
VersionManagerImpl versionManager = mock(VersionManagerImpl.class);
when(workspaceMock.getVersionManager()).thenReturn(versionManager);
when(mockNode.getParent()).thenReturn(parentNode);
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);
Calendar cal = Calendar.getInstance();
if (curDate != null) {
cal.setTime(curDate);
} else {
cal.setTime(new Date());
}
// validate checkin was called
verify(versionManager).checkin(mockNode.getPath(), cal);
}
use of org.apache.jackrabbit.core.VersionManagerImpl in project pentaho-platform by pentaho.
the class JcrRepositoryFileUtils method checkinNearestVersionableNodeIfNecessary.
/**
* Conditionally checks in node if node is versionable.
* <p/>
* TODO mlowery move commented out version labeling to its own method
*/
public static void checkinNearestVersionableNodeIfNecessary(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Node node, final String versionMessage, Date versionDate, final boolean aclOnlyChange) throws RepositoryException {
Assert.notNull(node);
session.save();
/*
* session.save must be called inside the versionable node block and outside to ensure user changes are made when a
* file is not versioned.
*/
Node versionableNode = findNearestVersionableNode(session, pentahoJcrConstants, node);
if (versionableNode != null) {
versionableNode.setProperty(pentahoJcrConstants.getPHO_VERSIONAUTHOR(), getUsername());
if (StringUtils.hasText(versionMessage)) {
versionableNode.setProperty(pentahoJcrConstants.getPHO_VERSIONMESSAGE(), versionMessage);
} else {
// TODO mlowery why do I need to check for hasProperty here? in JR 1.6, I didn't need to
if (versionableNode.hasProperty(pentahoJcrConstants.getPHO_VERSIONMESSAGE())) {
versionableNode.setProperty(pentahoJcrConstants.getPHO_VERSIONMESSAGE(), (String) null);
}
}
if (aclOnlyChange) {
versionableNode.setProperty(pentahoJcrConstants.getPHO_ACLONLYCHANGE(), true);
} else {
// TODO mlowery why do I need to check for hasProperty here? in JR 1.6, I didn't need to
if (versionableNode.hasProperty(pentahoJcrConstants.getPHO_ACLONLYCHANGE())) {
versionableNode.getProperty(pentahoJcrConstants.getPHO_ACLONLYCHANGE()).remove();
}
}
// required before checkin since we set some properties above
session.save();
Calendar cal = Calendar.getInstance();
if (versionDate != null) {
cal.setTime(versionDate);
} else {
cal.setTime(new Date());
}
((VersionManagerImpl) session.getWorkspace().getVersionManager()).checkin(versionableNode.getPath(), cal);
// prevent the number of versions from increasing. We still need a versioned node
if (!getRepositoryVersionManager().isVersioningEnabled(versionableNode.getPath())) {
List<VersionSummary> versionSummaries = (List<VersionSummary>) getVersionSummaries(session, pentahoJcrConstants, versionableNode.getIdentifier(), Boolean.TRUE);
if ((versionSummaries != null) && (versionSummaries.size() > 1)) {
VersionSummary versionSummary = (VersionSummary) versionSummaries.toArray()[versionSummaries.size() - 2];
if (versionSummary != null) {
String versionId = (String) versionSummary.getId();
session.getWorkspace().getVersionManager().getVersionHistory(versionableNode.getPath()).removeVersion(versionId);
session.save();
}
}
}
}
}
use of org.apache.jackrabbit.core.VersionManagerImpl in project pentaho-platform by pentaho.
the class JcrRepositoryFileDaoTest method setUp.
@Before
public void setUp() throws RepositoryException {
Node node = mock(Node.class);
Node nodeParent = mock(Node.class);
when(node.getIdentifier()).thenReturn("");
when(nodeParent.getIdentifier()).thenReturn("");
when(node.getParent()).thenReturn(nodeParent);
when(node.isNodeType("null:pentahoFile")).thenReturn(true);
when(node.isNodeType("null:pentahoVersionable")).thenReturn(true);
VersionManagerImpl versionManager = mock(VersionManagerImpl.class);
Workspace workspace = mock(Workspace.class);
when(workspace.getVersionManager()).thenReturn(versionManager);
Session session = mock(Session.class);
when(session.getWorkspace()).thenReturn(workspace);
when(session.getNodeByIdentifier(anyString())).thenReturn(node);
when(session.getItem(anyString())).thenReturn(node);
pentahoSession = mock(IPentahoSession.class);
PentahoSessionHolder.setSession(pentahoSession);
IRepositoryVersionManager repositoryVersionManager = mock(IRepositoryVersionManager.class);
when(repositoryVersionManager.isVersioningEnabled(anyString())).thenReturn(true);
PentahoSystem.registerObject(repositoryVersionManager);
JcrTemplate jcrTemplate = new JcrTemplate() {
@Override
public Object execute(JcrCallback callback) throws DataAccessException {
try {
return callback.doInJcr(session);
} catch (Exception e) {
// wrapping exception to comply overriding rules
throw new RuntimeException(e);
}
}
};
List<ITransformer<IRepositoryFileData>> transformerList = Collections.emptyList();
IPathConversionHelper pathConversionHelper = new DefaultPathConversionHelper();
IRepositoryFileAclDao aclDao = mock(IRepositoryFileAclDao.class);
accessVoterManager = mock(IRepositoryAccessVoterManager.class);
JcrRepositoryFileDao jcrDao = new JcrRepositoryFileDao(jcrTemplate, transformerList, null, null, pathConversionHelper, aclDao, null, accessVoterManager);
dao = spy(jcrDao);
}
use of org.apache.jackrabbit.core.VersionManagerImpl 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(anyString())).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((String) anyObject())).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.getParent()).thenReturn(parentNode);
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((String) anyObject());
}
Aggregations