use of com.enonic.xp.content.GetActiveContentVersionsResult in project xp by enonic.
the class ContentServiceImpl method getActiveVersion.
@Override
public ContentVersion getActiveVersion(final GetActiveContentVersionParams params) {
final GetActiveContentVersionsResult activeVersions = getActiveVersions(GetActiveContentVersionsParams.create().branches(Branches.from(params.getBranch())).contentId(params.getContentId()).build());
final UnmodifiableIterator<ActiveContentVersionEntry> activeVersionIterator = activeVersions.getActiveContentVersions().iterator();
return activeVersionIterator.hasNext() ? activeVersionIterator.next().getContentVersion() : null;
}
use of com.enonic.xp.content.GetActiveContentVersionsResult in project xp by enonic.
the class GetActiveContentVersionsCommand method execute.
public GetActiveContentVersionsResult execute() {
this.nodeService.refresh(RefreshMode.STORAGE);
final NodeId nodeId = NodeId.from(contentId.toString());
final GetActiveNodeVersionsResult activeNodeVersions = this.nodeService.getActiveVersions(GetActiveNodeVersionsParams.create().nodeId(nodeId).branches(this.branches).build());
final ContentVersionFactory contentVersionFactory = new ContentVersionFactory(this.nodeService);
final GetActiveContentVersionsResult.Builder builder = GetActiveContentVersionsResult.create();
final ImmutableMap<Branch, NodeVersionMetadata> nodeVersionsMap = activeNodeVersions.getNodeVersions();
for (final Branch branch : nodeVersionsMap.keySet()) {
final NodeVersionMetadata nodeVersionMetadata = nodeVersionsMap.get(branch);
builder.add(ActiveContentVersionEntry.from(branch, contentVersionFactory.create(nodeVersionMetadata)));
}
return builder.build();
}
use of com.enonic.xp.content.GetActiveContentVersionsResult in project xp by enonic.
the class ContentServiceImplTest_versions method get_active_versions.
@Test
public void get_active_versions() throws Exception {
final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my test content").parent(ContentPath.ROOT).name("myContent").type(ContentTypeName.folder()).build());
this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).build());
// Two versions, since publish adds one version
assertVersions(content.getId(), 2);
final UpdateContentParams updateContentParams = new UpdateContentParams();
updateContentParams.contentId(content.getId()).editor(edit -> {
edit.displayName = "new display name";
});
this.contentService.update(updateContentParams);
assertVersions(content.getId(), 3);
final GetActiveContentVersionsResult activeVersions = this.contentService.getActiveVersions(GetActiveContentVersionsParams.create().contentId(content.getId()).branches(Branches.from(WS_DEFAULT, WS_OTHER)).build());
final ImmutableList<ActiveContentVersionEntry> activeContentVersions = activeVersions.getActiveContentVersions();
assertEquals(2, activeContentVersions.size());
final UnmodifiableIterator<ActiveContentVersionEntry> iterator = activeContentVersions.iterator();
assertTrue(iterator.next().getContentVersion() != iterator.next().getContentVersion());
}
Aggregations