Search in sources :

Example 1 with PublishContentResultMapper

use of com.enonic.xp.lib.content.mapper.PublishContentResultMapper 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)

Aggregations

Content (com.enonic.xp.content.Content)1 ContentId (com.enonic.xp.content.ContentId)1 ContentPath (com.enonic.xp.content.ContentPath)1 ContentPublishInfo (com.enonic.xp.content.ContentPublishInfo)1 PublishContentResult (com.enonic.xp.content.PublishContentResult)1 PushContentParams (com.enonic.xp.content.PushContentParams)1 PublishContentResultMapper (com.enonic.xp.lib.content.mapper.PublishContentResultMapper)1 ArrayList (java.util.ArrayList)1