Search in sources :

Example 11 with GetContentByIdsParams

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));
}
Also used : Contents(com.enonic.xp.content.Contents) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Content(com.enonic.xp.content.Content) ContentIds(com.enonic.xp.content.ContentIds) Test(org.junit.jupiter.api.Test)

Example 12 with GetContentByIdsParams

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));
}
Also used : Contents(com.enonic.xp.content.Contents) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Content(com.enonic.xp.content.Content) ContentIds(com.enonic.xp.content.ContentIds) Test(org.junit.jupiter.api.Test)

Example 13 with GetContentByIdsParams

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();
}
Also used : DuplicateContentParams(com.enonic.xp.content.DuplicateContentParams) QueryParser(com.enonic.xp.query.parser.QueryParser) FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) ArchiveContentsResult(com.enonic.xp.archive.ArchiveContentsResult) PublishContentResult(com.enonic.xp.content.PublishContentResult) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeService(com.enonic.xp.node.NodeService) ProjectService(com.enonic.xp.project.ProjectService) CreateSiteParams(com.enonic.xp.site.CreateSiteParams) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) PushContentParams(com.enonic.xp.content.PushContentParams) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) ArchiveContentParams(com.enonic.xp.archive.ArchiveContentParams) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ContentValidator(com.enonic.xp.content.ContentValidator) FindContentByQueryParams(com.enonic.xp.content.FindContentByQueryParams) EventPublisher(com.enonic.xp.event.EventPublisher) Node(com.enonic.xp.node.Node) FindContentVersionsResult(com.enonic.xp.content.FindContentVersionsResult) ResolvePublishDependenciesParams(com.enonic.xp.content.ResolvePublishDependenciesParams) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ContentVersionId(com.enonic.xp.content.ContentVersionId) RestoreContentParams(com.enonic.xp.archive.RestoreContentParams) ReorderChildParams(com.enonic.xp.content.ReorderChildParams) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) Component(org.osgi.service.component.annotations.Component) Tracer(com.enonic.xp.trace.Tracer) MediaInfoService(com.enonic.xp.media.MediaInfoService) MoveContentsResult(com.enonic.xp.content.MoveContentsResult) ByteSource(com.google.common.io.ByteSource) ContentAccessException(com.enonic.xp.content.ContentAccessException) ContentPath(com.enonic.xp.content.ContentPath) SetActiveContentVersionResult(com.enonic.xp.content.SetActiveContentVersionResult) Content(com.enonic.xp.content.Content) IOException(java.io.IOException) ReorderChildNodeParams(com.enonic.xp.node.ReorderChildNodeParams) FindContentIdsByParentResult(com.enonic.xp.content.FindContentIdsByParentResult) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) PublishStatus(com.enonic.xp.content.PublishStatus) ContentIds(com.enonic.xp.content.ContentIds) RenameContentParams(com.enonic.xp.content.RenameContentParams) GetActiveContentVersionsResult(com.enonic.xp.content.GetActiveContentVersionsResult) MoveContentParams(com.enonic.xp.content.MoveContentParams) NodeAccessException(com.enonic.xp.node.NodeAccessException) UnmodifiableIterator(com.google.common.collect.UnmodifiableIterator) GetActiveContentVersionParams(com.enonic.xp.content.GetActiveContentVersionParams) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) GetPublishStatusesParams(com.enonic.xp.content.GetPublishStatusesParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) FindContentPathsByQueryParams(com.enonic.xp.content.FindContentPathsByQueryParams) ImportContentParams(com.enonic.xp.content.ImportContentParams) LoggerFactory(org.slf4j.LoggerFactory) ImportContentResult(com.enonic.xp.content.ImportContentResult) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) GetPublishStatusesResult(com.enonic.xp.content.GetPublishStatusesResult) Trace(com.enonic.xp.trace.Trace) ApplyContentPermissionsParams(com.enonic.xp.content.ApplyContentPermissionsParams) FindContentPathsByQueryResult(com.enonic.xp.content.FindContentPathsByQueryResult) ContentId(com.enonic.xp.content.ContentId) ApplyContentPermissionsResult(com.enonic.xp.content.ApplyContentPermissionsResult) FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) DuplicateContentsResult(com.enonic.xp.content.DuplicateContentsResult) CompareContentsParams(com.enonic.xp.content.CompareContentsParams) ContentDependencies(com.enonic.xp.content.ContentDependencies) ContextBuilder(com.enonic.xp.context.ContextBuilder) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) BinaryReference(com.enonic.xp.util.BinaryReference) SiteService(com.enonic.xp.site.SiteService) Predicate(java.util.function.Predicate) ContentProcessor(com.enonic.xp.content.processor.ContentProcessor) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) NodeId(com.enonic.xp.node.NodeId) List(java.util.List) Site(com.enonic.xp.site.Site) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) ReorderChildContentsResult(com.enonic.xp.content.ReorderChildContentsResult) Contents(com.enonic.xp.content.Contents) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) GetActiveContentVersionsParams(com.enonic.xp.content.GetActiveContentVersionsParams) ContentDataSerializer(com.enonic.xp.core.impl.content.serializer.ContentDataSerializer) UnpublishContentsResult(com.enonic.xp.content.UnpublishContentsResult) CompareContentResults(com.enonic.xp.content.CompareContentResults) CreateContentParams(com.enonic.xp.content.CreateContentParams) RefreshMode(com.enonic.xp.node.RefreshMode) ContentService(com.enonic.xp.content.ContentService) SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) ResolveRequiredDependenciesParams(com.enonic.xp.content.ResolveRequiredDependenciesParams) RestoreContentsResult(com.enonic.xp.archive.RestoreContentsResult) ContentValidityParams(com.enonic.xp.content.ContentValidityParams) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) DeleteContentParams(com.enonic.xp.content.DeleteContentParams) CompareContentResult(com.enonic.xp.content.CompareContentResult) ContentVersion(com.enonic.xp.content.ContentVersion) SetNodeChildOrderParams(com.enonic.xp.node.SetNodeChildOrderParams) ContentPaths(com.enonic.xp.content.ContentPaths) NodeVersionId(com.enonic.xp.node.NodeVersionId) FindContentVersionsParams(com.enonic.xp.content.FindContentVersionsParams) UndoPendingDeleteContentParams(com.enonic.xp.content.UndoPendingDeleteContentParams) Activate(org.osgi.service.component.annotations.Activate) HasUnpublishedChildrenParams(com.enonic.xp.content.HasUnpublishedChildrenParams) XDataService(com.enonic.xp.schema.xdata.XDataService) PropertyTree(com.enonic.xp.data.PropertyTree) PartDescriptorService(com.enonic.xp.region.PartDescriptorService) Logger(org.slf4j.Logger) ContentPropertyNames(com.enonic.xp.content.ContentPropertyNames) UpdateMediaParams(com.enonic.xp.content.UpdateMediaParams) UnpublishContentParams(com.enonic.xp.content.UnpublishContentParams) NodePath(com.enonic.xp.node.NodePath) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) Branches(com.enonic.xp.branch.Branches) ApplicationKey(com.enonic.xp.app.ApplicationKey) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ContentQuery(com.enonic.xp.content.ContentQuery) ReprocessContentParams(com.enonic.xp.content.ReprocessContentParams) GetPublishStatusResult(com.enonic.xp.content.GetPublishStatusResult) CompareContentParams(com.enonic.xp.content.CompareContentParams) ContentValidityResult(com.enonic.xp.content.ContentValidityResult) Modified(org.osgi.service.component.annotations.Modified) ReorderChildContentsParams(com.enonic.xp.content.ReorderChildContentsParams) SetContentChildOrderParams(com.enonic.xp.content.SetContentChildOrderParams) ActiveContentVersionEntry(com.enonic.xp.content.ActiveContentVersionEntry) Reference(org.osgi.service.component.annotations.Reference) CreateMediaParams(com.enonic.xp.content.CreateMediaParams) InputStream(java.io.InputStream) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Contents(com.enonic.xp.content.Contents) GetPublishStatusesResult(com.enonic.xp.content.GetPublishStatusesResult) Instant(java.time.Instant) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) GetPublishStatusResult(com.enonic.xp.content.GetPublishStatusResult)

Aggregations

Contents (com.enonic.xp.content.Contents)13 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)13 Content (com.enonic.xp.content.Content)11 ContentIds (com.enonic.xp.content.ContentIds)11 Test (org.junit.jupiter.api.Test)10 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)5 PropertyTree (com.enonic.xp.data.PropertyTree)5 CreateContentParams (com.enonic.xp.content.CreateContentParams)4 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)3 ContentDependencies (com.enonic.xp.content.ContentDependencies)2 ContentId (com.enonic.xp.content.ContentId)2 ContentQuery (com.enonic.xp.content.ContentQuery)2 ContentService (com.enonic.xp.content.ContentService)2 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)1 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 ArchiveContentParams (com.enonic.xp.archive.ArchiveContentParams)1 ArchiveContentsResult (com.enonic.xp.archive.ArchiveContentsResult)1 RestoreContentParams (com.enonic.xp.archive.RestoreContentParams)1 RestoreContentsResult (com.enonic.xp.archive.RestoreContentsResult)1 Branches (com.enonic.xp.branch.Branches)1