本文整理汇总了Java中javax.jcr.version.VersionIterator类的典型用法代码示例。如果您正苦于以下问题:Java VersionIterator类的具体用法?Java VersionIterator怎么用?Java VersionIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VersionIterator类属于javax.jcr.version包,在下文中一共展示了VersionIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVersionList
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
protected List<T> getVersionList(Node node, NodeFilter nodeFilter) {
try {
List<T> versionList = new ArrayList<T>();
//VersionHistory versionHistory = node.getVersionHistory();
VersionHistory versionHistory = JcrUtils.getVersionManager(node.getSession()).getVersionHistory(node.getPath());
VersionIterator versionIterator = versionHistory.getAllVersions();
versionIterator.skip(1);
while (versionIterator.hasNext()) {
Version version = versionIterator.nextVersion();
NodeIterator nodeIterator = version.getNodes();
while (nodeIterator.hasNext()) {
T entityVersion = getJcrom().fromNode(getEntityClass(), nodeIterator.nextNode(), nodeFilter);
//Version baseVersion = node.getBaseVersion();
Version baseVersion = JcrUtils.getVersionManager(node.getSession()).getBaseVersion(node.getPath());
getJcrom().setBaseVersionInfo(entityVersion, baseVersion.getName(), baseVersion.getCreated());
versionList.add(entityVersion);
}
}
return versionList;
} catch (RepositoryException e) {
throw new JcrMappingException("Could not get version list", e);
}
}
示例2: getPageVersions
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
@Override
public List<PageVersion> getPageVersions(final String path) {
return jcrTemplate.execute(session -> {
Node rootNode = session.getRootNode();
Node node = JcrUtils.getNodeIfExists(rootNode, path);
if (node != null) {
VersionManager vm = session.getWorkspace().getVersionManager();
VersionHistory history = vm.getVersionHistory("/" + path);
List<PageVersion> versions = new ArrayList<>();
for (VersionIterator it = history.getAllVersions(); it.hasNext(); ) {
Version version = (Version) it.next();
if (!"jcr:rootVersion".equals(version.getName())) {
versions.add(convertNodeToPageVersion(version));
}
}
return versions;
} else {
return null;
}
});
}
示例3: initialize
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
private void initialize() throws RepositoryException {
if (versionName.equals("latest")) {
populate(resource, resource.getPath(), 0);
versionDate = Properties.lastModified(resource);
}
VersionManager versionManager = resource.getResourceResolver().adaptTo(Session.class).getWorkspace().getVersionManager();
try {
VersionHistory history = versionManager.getVersionHistory(this.resource.getPath());
VersionIterator versionIterator = history.getAllVersions();
while (versionIterator.hasNext()) {
Version next = versionIterator.nextVersion();
versionSelection.add(new VersionSelectionImpl(next.getName(), next.getCreated().getTime()));
if (next.getName().equalsIgnoreCase(versionName)) {
String versionPath = next.getFrozenNode().getPath();
Resource versionResource = resource.getResourceResolver().resolve(versionPath);
populate(versionResource, versionPath, 0);
versionDate = next.getCreated().getTime();
}
}
} catch (javax.jcr.UnsupportedRepositoryOperationException e) {
log.debug(String.format("node %s not versionable", this.resource.getPath()));
}
versionSelection.add(new VersionSelectionImpl("latest", Properties.lastModified(resource)));
}
示例4: lastVersion_oneVersion_returnVersion
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
@Test
public void lastVersion_oneVersion_returnVersion() throws Exception {
// given
VersionIterator versionIterator = mock(VersionIterator.class, withSettings().extraInterfaces(Iterator.class));
when(versionIterator.hasNext()).thenReturn(true, false);
Version last = mock(Version.class);
when(versionIterator.next()).thenReturn(last);
Resource resource = mockResource(versionIterator);
// when
Version result = underTest.lastVersion(resource);
// then
assertThat(result, is(last));
}
示例5: lastVersion_listOfVersion_returnLast
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
@Test
public void lastVersion_listOfVersion_returnLast() throws Exception {
// given
VersionIterator versionIterator = mock(VersionIterator.class, withSettings().extraInterfaces(Iterator.class));
when(versionIterator.hasNext()).thenReturn(true, true, true, false);
Version one = mock(Version.class);
Version two = mock(Version.class);
Version three = mock(Version.class);
when(versionIterator.next()).thenReturn(one, two, three);
Resource resource = mockResource(versionIterator);
// when
Version result = underTest.lastVersion(resource);
// then
assertThat(result, is(three));
}
示例6: testGetVersionLabels
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
@Test
public void testGetVersionLabels() throws RepositoryException {
when(mockNode.isNodeType(FROZEN_NODE)).thenReturn(true);
final VersionHistory mockVersionHistory = mock(VersionHistory.class);
final Version mockVersion = mock(Version.class);
when(mockVersion.getName()).thenReturn("uuid");
final Workspace mockWorkspace = mock(Workspace.class);
when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
final VersionManager mockVersionManager = mock(VersionManager.class);
when(mockWorkspace.getVersionManager()).thenReturn(mockVersionManager);
final VersionIterator mockVersionIterator = mock(VersionIterator.class);
when(mockVersionHistory.getAllVersions()).thenReturn(mockVersionIterator);
when(mockVersionIterator.hasNext()).thenReturn(false);
when(mockVersionManager.getVersionHistory(anyString())).thenReturn(
mockVersionHistory);
testObj.getVersions();
verify(mockVersionManager).getVersionHistory(anyString());
}
示例7: getVersionFiles
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
@Override
public List<VersionFile> getVersionFiles(String path) throws Exception{
path = processPath(path);
Node rootNode=getRootNode();
if (!rootNode.hasNode(path)) {
throw new RuleException("File [" + path + "] not exist.");
}
List<VersionFile> files = new ArrayList<VersionFile>();
Node fileNode = rootNode.getNode(path);
VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath());
VersionIterator iterator = versionHistory.getAllVersions();
while (iterator.hasNext()) {
Version version = iterator.nextVersion();
String versionName = version.getName();
if (versionName.startsWith("jcr:")) {
continue; // skip root version
}
Node fnode = version.getFrozenNode();
VersionFile file = new VersionFile();
file.setName(version.getName());
file.setPath(fileNode.getPath());
Property prop = fnode.getProperty(CRATE_USER);
file.setCreateUser(prop.getString());
prop = fnode.getProperty(CRATE_DATE);
file.setCreateDate(prop.getDate().getTime());
if(fnode.hasProperty(VERSION_COMMENT)){
prop=fnode.getProperty(VERSION_COMMENT);
file.setComment(prop.getString());
}
files.add(file);
}
return files;
}
示例8: updateVersion
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
protected String updateVersion(Session session, Node nodeByUUID) throws RepositoryException, OleDocStoreException {
session.save();
String currentVersion = null;
if (isVersioningEnabled()) {
VersionManager versionManager = getVersionManager(session);
versionManager.checkpoint(nodeByUUID.getPath());
VersionHistory versionHistory = versionManager.getVersionHistory(nodeByUUID.getPath());
VersionIterator allVersions = versionHistory.getAllVersions();
while (allVersions.hasNext()) {
currentVersion = allVersions.nextVersion().getName();
}
logger.info("Version updated for UUID:" + nodeByUUID.getIdentifier() + " ==== version:" + currentVersion);
}
return currentVersion;
}
示例9: getVersions
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
private List<Version> getVersions(String nodePath, Session session) throws RepositoryException {
List<Version> versions = new ArrayList<Version>();
for (VersionIterator iter = session.getWorkspace()
.getVersionManager().getVersionHistory(nodePath)
.getAllVersions(); iter.hasNext();) {
Version v = iter.nextVersion();
versions.add(v);
}
return versions;
}
示例10: lastVersion_noElement_returnNull
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
@Test
public void lastVersion_noElement_returnNull() throws Exception {
// given
VersionIterator versionIterator = mock(VersionIterator.class, withSettings().extraInterfaces(Iterator.class));
when(versionIterator.hasNext()).thenReturn(false);
Resource resource = mockResource(versionIterator);
// when
Version result = underTest.lastVersion(resource);
// then
assertNull(result);
}
示例11: lastVersion_error_returnNull
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
@Test
public void lastVersion_error_returnNull() throws Exception {
// given
VersionIterator versionIterator = mock(VersionIterator.class, withSettings().extraInterfaces(Iterator.class));
when(versionIterator.hasNext()).thenThrow(RepositoryException.class);
Resource resource = mockResource(versionIterator);
// when
Version result = underTest.lastVersion(resource);
// then
assertNull(result);
}
示例12: mockResource
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
private Resource mockResource(VersionIterator versionIterator) throws RepositoryException {
Resource resource = mock(Resource.class, RETURNS_DEEP_STUBS.get());
Session session = mock(Session.class, RETURNS_DEEP_STUBS.get());
when(resource.getResourceResolver().adaptTo(Session.class)).thenReturn(session);
when(session.getWorkspace().getVersionManager().getVersionHistory(anyString()).getAllVersions()).thenReturn(versionIterator);
return resource;
}
示例13: mockResource
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
static Resource mockResource(String path, String versionName, Date date) throws RepositoryException {
Resource resource = mock(Resource.class, Answers.RETURNS_DEEP_STUBS.get());
when(resource.getPath()).thenReturn(path);
when(resource.getValueMap()).thenReturn(mock(ValueMap.class));
Node node = mock(Node.class, Answers.RETURNS_DEEP_STUBS.get());
when(resource.adaptTo(Node.class)).thenReturn(node);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
when(resource.getResourceResolver()).thenReturn(resourceResolver);
when(resourceResolver.resolve(path)).thenReturn(resource);
Session session = mock(Session.class, Answers.RETURNS_DEEP_STUBS.get());
when(resourceResolver.adaptTo(Session.class)).thenReturn(session);
VersionManager versionManager = mock(VersionManager.class);
when(session.getWorkspace().getVersionManager()).thenReturn(versionManager);
VersionHistory history = mock(VersionHistory.class);
when(versionManager.getVersionHistory(path)).thenReturn(history);
Version version = mock(Version.class, Answers.RETURNS_DEEP_STUBS.get());
when(version.getName()).thenReturn(versionName);
final GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
when(version.getCreated()).thenReturn(calendar);
when(version.getFrozenNode().getPath()).thenReturn(path);
VersionIterator versionIterator = mock(VersionIterator.class);
when(versionIterator.hasNext()).thenReturn(true, false);
when(versionIterator.nextVersion()).thenReturn(version);
when(history.getAllVersions()).thenReturn(versionIterator);
return resource;
}
示例14: testRevertToUnknownVersion
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
@Test(expected = RepositoryRuntimeException.class)
public void testRevertToUnknownVersion() throws RepositoryException {
final String versionUUID = "uuid";
final VersionManager mockVersionManager = mock(VersionManager.class);
final VersionHistory mockHistory = mock(VersionHistory.class);
when(mockHistory.getVersionByLabel(versionUUID)).thenThrow(new VersionException());
final VersionIterator mockVersionIterator = mock(VersionIterator.class);
when(mockHistory.getAllVersions()).thenReturn(mockVersionIterator);
when(mockVersionIterator.hasNext()).thenReturn(false);
when(mockWorkspace.getVersionManager()).thenReturn(mockVersionManager);
when(mockVersionManager.getVersionHistory(EXAMPLE_VERSIONED_PATH)).thenReturn(mockHistory);
testObj.revertToVersion(testSession, EXAMPLE_VERSIONED_PATH, versionUUID);
}
示例15: testRemoveUnknownVersion
import javax.jcr.version.VersionIterator; //导入依赖的package包/类
@Test(expected = RepositoryRuntimeException.class)
public void testRemoveUnknownVersion() throws RepositoryException {
final String versionUUID = "uuid";
final VersionManager mockVersionManager = mock(VersionManager.class);
final VersionHistory mockHistory = mock(VersionHistory.class);
when(mockHistory.getVersionByLabel(versionUUID)).thenThrow(new VersionException());
final VersionIterator mockVersionIterator = mock(VersionIterator.class);
when(mockHistory.getAllVersions()).thenReturn(mockVersionIterator);
when(mockVersionIterator.hasNext()).thenReturn(false);
when(mockWorkspace.getVersionManager()).thenReturn(mockVersionManager);
when(mockVersionManager.getVersionHistory("/example")).thenReturn(mockHistory);
testObj.removeVersion(testSession, "/example", versionUUID);
}