Search in sources :

Example 1 with ActiveContentVersionEntry

use of com.enonic.xp.content.ActiveContentVersionEntry 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 ActiveContentVersionEntry

use of com.enonic.xp.content.ActiveContentVersionEntry 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

ActiveContentVersionEntry (com.enonic.xp.content.ActiveContentVersionEntry)2 GetActiveContentVersionsResult (com.enonic.xp.content.GetActiveContentVersionsResult)2 Content (com.enonic.xp.content.Content)1 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 Test (org.junit.jupiter.api.Test)1