Search in sources :

Example 1 with ContentPublishInfo

use of com.enonic.xp.content.ContentPublishInfo in project xp by enonic.

the class PublishContentHandler method publishContent.

private PublishContentResultMapper publishContent() {
    final List<ContentPath> contentNotFound = new ArrayList<>();
    final List<ContentId> contentIds = new ArrayList<>();
    for (final String key : this.keys) {
        if (key.startsWith("/")) {
            final ContentPath path = ContentPath.from(key);
            final Content content = getByPath(path);
            if (content != null) {
                contentIds.add(content.getId());
            } else {
                contentNotFound.add(path);
            }
        } else {
            contentIds.add(ContentId.from(key));
        }
    }
    final PushContentParams.Builder builder = PushContentParams.create();
    builder.contentIds(ContentIds.from(contentIds));
    builder.target(Branch.from(targetBranch));
    if (this.contentPublishInfo != null) {
        final Object from = this.contentPublishInfo.get("from");
        final Object to = this.contentPublishInfo.get("to");
        final ContentPublishInfo contentPublishInfo = ContentPublishInfo.create().from(from == null ? null : Instant.parse((String) from)).to(to == null ? null : Instant.parse((String) to)).build();
        builder.contentPublishInfo(contentPublishInfo);
    }
    if (this.excludeChildrenIds != null) {
        builder.excludeChildrenIds(ContentIds.from(this.excludeChildrenIds));
    }
    if (this.includeChildren != null) {
        builder.includeChildren(this.includeChildren);
    }
    if (this.includeDependencies != null) {
        builder.includeDependencies(includeDependencies);
    }
    builder.message(message);
    final PublishContentResult result = this.contentService.publish(builder.build());
    return result != null ? new PublishContentResultMapper(result, contentNotFound) : null;
}
Also used : ArrayList(java.util.ArrayList) ContentPath(com.enonic.xp.content.ContentPath) PublishContentResultMapper(com.enonic.xp.lib.content.mapper.PublishContentResultMapper) PushContentParams(com.enonic.xp.content.PushContentParams) PublishContentResult(com.enonic.xp.content.PublishContentResult) Content(com.enonic.xp.content.Content) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) ContentId(com.enonic.xp.content.ContentId)

Example 2 with ContentPublishInfo

use of com.enonic.xp.content.ContentPublishInfo in project xp by enonic.

the class ContentAuditLogSupportImpl method doPublish.

private void doPublish(final PushContentParams params, final PublishContentResult result, final Context rootContext) {
    if (params.getContentIds() == null) {
        return;
    }
    final PropertyTree data = new PropertyTree();
    final PropertySet paramsSet = data.addSet("params");
    final PropertySet resultSet = data.addSet("result");
    if (params.getContentIds() != null) {
        paramsSet.addStrings("contentIds", params.getContentIds().stream().map(ContentId::toString).collect(Collectors.toList()));
    }
    if (params.getExcludedContentIds() != null) {
        paramsSet.addStrings("excludedContentIds", params.getExcludedContentIds().stream().map(ContentId::toString).collect(Collectors.toList()));
    }
    if (params.getExcludeChildrenIds() != null) {
        paramsSet.addStrings("excludeChildrenIds", params.getExcludeChildrenIds().stream().map(ContentId::toString).collect(Collectors.toList()));
    }
    if (params.getContentPublishInfo() != null) {
        final ContentPublishInfo contentPublishInfo = params.getContentPublishInfo();
        final PropertySet contentPublishInfoSet = paramsSet.addSet("contentPublishInfo");
        contentPublishInfoSet.addInstant("from", contentPublishInfo.getFrom());
        contentPublishInfoSet.addInstant("to", contentPublishInfo.getTo());
        contentPublishInfoSet.addInstant("first", contentPublishInfo.getFirst());
    }
    paramsSet.addString("target", params.getTarget().toString());
    paramsSet.addString("message", params.getMessage());
    paramsSet.addBoolean("includeDependencies", params.isIncludeDependencies());
    addContents(resultSet, result.getPushedContents(), "pushedContents");
    addContents(resultSet, result.getDeletedContents(), "deletedContents");
    addContents(resultSet, result.getFailedContents(), "failedContents");
    addContents(resultSet, result.getUnpublishedContents(), "unpublishedContents");
    log("system.content.publish", data, ContentIds.create().addAll(result.getPushedContents()).addAll(result.getDeletedContents()).addAll(result.getUnpublishedContents()).build(), rootContext);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) ContentId(com.enonic.xp.content.ContentId)

Example 3 with ContentPublishInfo

use of com.enonic.xp.content.ContentPublishInfo in project xp by enonic.

the class UpdateContentCommand method validateBlockingChecks.

private void validateBlockingChecks(final Content editedContent) {
    validatePropertyTree(editedContent);
    final ContentPublishInfo publishInfo = editedContent.getPublishInfo();
    if (publishInfo != null) {
        final Instant publishToInstant = publishInfo.getTo();
        if (publishToInstant != null) {
            final Instant publishFromInstant = publishInfo.getFrom();
            Preconditions.checkArgument(publishFromInstant != null, "'Publish from' must be set if 'Publish from' is set.");
            Preconditions.checkArgument(publishToInstant.compareTo(publishFromInstant) >= 0, "'Publish to' must be set after 'Publish from'.");
        }
    }
    if (editedContent.getType().isImageMedia()) {
        validateImageMediaProperties(editedContent);
    }
}
Also used : Instant(java.time.Instant) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo)

Example 4 with ContentPublishInfo

use of com.enonic.xp.content.ContentPublishInfo in project xp by enonic.

the class ContentServiceImplTest_publish_update_publishedTime method keep_original_published_time.

@Test
public void keep_original_published_time() throws Exception {
    final Content content = doCreateContent();
    doPublishContent(content);
    assertVersions(content.getId(), 2);
    final ContentPublishInfo publishInfo = this.contentService.getById(content.getId()).getPublishInfo();
    assertNotNull(publishInfo);
    assertNotNull(publishInfo.getFirst());
    assertNotNull(publishInfo.getFrom());
    final UpdateContentParams updateContentParams = new UpdateContentParams();
    updateContentParams.contentId(content.getId()).editor(edit -> edit.displayName = "new display name");
    this.contentService.update(updateContentParams);
    doPublishContent(content);
    assertVersions(content.getId(), 3);
    final ContentPublishInfo unUpdatedPublishInfo = this.contentService.getById(content.getId()).getPublishInfo();
    assertEquals(publishInfo, unUpdatedPublishInfo);
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) Test(org.junit.jupiter.api.Test)

Example 5 with ContentPublishInfo

use of com.enonic.xp.content.ContentPublishInfo in project xp by enonic.

the class ContentServiceImplTest_publish_update_publishedTime method set_publish_time_again_if_reset.

@Test
public void set_publish_time_again_if_reset() throws Exception {
    final Content content = doCreateContent();
    doPublishContent(content);
    final ContentPublishInfo publishInfo = this.contentService.getById(content.getId()).getPublishInfo();
    final UpdateContentParams updateContentParams = new UpdateContentParams();
    updateContentParams.contentId(content.getId()).editor(edit -> edit.publishInfo = null);
    this.contentService.update(updateContentParams);
    doPublishContent(content);
    final ContentPublishInfo updatedPublishInfo = this.contentService.getById(content.getId()).getPublishInfo();
    assertTrue(updatedPublishInfo.getFrom().isAfter(publishInfo.getFrom()));
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) Test(org.junit.jupiter.api.Test)

Aggregations

ContentPublishInfo (com.enonic.xp.content.ContentPublishInfo)7 Content (com.enonic.xp.content.Content)5 ContentId (com.enonic.xp.content.ContentId)3 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)3 Test (org.junit.jupiter.api.Test)3 ContentPath (com.enonic.xp.content.ContentPath)2 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 ActiveContentVersionEntry (com.enonic.xp.content.ActiveContentVersionEntry)1 ApplyContentPermissionsParams (com.enonic.xp.content.ApplyContentPermissionsParams)1 ApplyContentPermissionsResult (com.enonic.xp.content.ApplyContentPermissionsResult)1 CompareContentParams (com.enonic.xp.content.CompareContentParams)1 CompareContentResult (com.enonic.xp.content.CompareContentResult)1 CompareContentResults (com.enonic.xp.content.CompareContentResults)1 CompareContentsParams (com.enonic.xp.content.CompareContentsParams)1 ContentAccessException (com.enonic.xp.content.ContentAccessException)1