Search in sources :

Example 1 with GetActiveContentVersionsResult

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;
}
Also used : GetActiveContentVersionsResult(com.enonic.xp.content.GetActiveContentVersionsResult) ActiveContentVersionEntry(com.enonic.xp.content.ActiveContentVersionEntry)

Example 2 with GetActiveContentVersionsResult

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();
}
Also used : GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) GetActiveContentVersionsResult(com.enonic.xp.content.GetActiveContentVersionsResult) Branch(com.enonic.xp.branch.Branch) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeId(com.enonic.xp.node.NodeId)

Example 3 with GetActiveContentVersionsResult

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());
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) GetActiveContentVersionsResult(com.enonic.xp.content.GetActiveContentVersionsResult) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ActiveContentVersionEntry(com.enonic.xp.content.ActiveContentVersionEntry) Test(org.junit.jupiter.api.Test)

Aggregations

GetActiveContentVersionsResult (com.enonic.xp.content.GetActiveContentVersionsResult)3 ActiveContentVersionEntry (com.enonic.xp.content.ActiveContentVersionEntry)2 Branch (com.enonic.xp.branch.Branch)1 Content (com.enonic.xp.content.Content)1 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 GetActiveNodeVersionsResult (com.enonic.xp.node.GetActiveNodeVersionsResult)1 NodeId (com.enonic.xp.node.NodeId)1 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)1 Test (org.junit.jupiter.api.Test)1