use of com.enonic.xp.content.GetContentByIdsParams in project xp by enonic.
the class ContentServiceImplTest_getByIds method test_pending_publish_draft.
@Test
public void test_pending_publish_draft() throws Exception {
final Content content1 = createContent(ContentPath.ROOT);
final Content content2 = createContent(ContentPath.ROOT, ContentPublishInfo.create().from(Instant.now().plus(Duration.ofDays(1))).build());
final ContentIds ids = ContentIds.from(content1.getId(), content2.getId());
final Contents contents = this.contentService.getByIds(new GetContentByIdsParams(ids));
assertEquals(contents.getSize(), 2);
assertTrue(contents.contains(content1));
assertTrue(contents.contains(content2));
}
use of com.enonic.xp.content.GetContentByIdsParams in project xp by enonic.
the class ContentServiceImplTest_getByIds method test_published_draft.
@Test
public void test_published_draft() throws Exception {
final Content content1 = createContent(ContentPath.ROOT);
final Content content2 = createContent(ContentPath.ROOT, ContentPublishInfo.create().from(Instant.now().minus(Duration.ofDays(1))).to(Instant.now().plus(Duration.ofDays(1))).build());
final ContentIds ids = ContentIds.from(content1.getId(), content2.getId());
final Contents contents = this.contentService.getByIds(new GetContentByIdsParams(ids));
assertEquals(contents.getSize(), 2);
assertTrue(contents.contains(content1));
assertTrue(contents.contains(content2));
}
use of com.enonic.xp.content.GetContentByIdsParams in project xp by enonic.
the class ContentServiceImpl method getPublishStatuses.
@Override
public GetPublishStatusesResult getPublishStatuses(final GetPublishStatusesParams params) {
final GetContentByIdsParams getContentByIdsParams = new GetContentByIdsParams(params.getContentIds());
final Instant now = Instant.now();
final Contents contents = ContextBuilder.from(ContextAccessor.current()).branch(params.getTarget()).attribute("ignorePublishTimes", Boolean.TRUE).build().callWith(() -> this.getByIds(getContentByIdsParams));
final GetPublishStatusesResult.Builder getPublishStatusesResult = GetPublishStatusesResult.create();
contents.stream().map(content -> {
final ContentPublishInfo publishInfo = content.getPublishInfo();
if (publishInfo != null) {
if (publishInfo.getTo() != null && publishInfo.getTo().compareTo(now) < 0) {
return new GetPublishStatusResult(content.getId(), PublishStatus.EXPIRED);
}
if (publishInfo.getFrom() != null && publishInfo.getFrom().compareTo(now) > 0) {
return new GetPublishStatusResult(content.getId(), PublishStatus.PENDING);
}
}
return new GetPublishStatusResult(content.getId(), PublishStatus.ONLINE);
}).forEach(getPublishStatusesResult::add);
return getPublishStatusesResult.build();
}
Aggregations