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;
}
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);
}
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);
}
}
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);
}
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()));
}
Aggregations