use of com.enonic.xp.attachment.CreateAttachments in project xp by enonic.
the class UpdatedEventSyncCommand method doSyncThumbnail.
private void doSyncThumbnail(final ContentToSync content, final UpdateContentParams updateParams) {
if (!Objects.equals(content.getSourceContent().getThumbnail(), content.getTargetContent().getThumbnail())) {
final Thumbnail sourceThumbnail = content.getSourceContent().getThumbnail();
if (sourceThumbnail != null) {
final ByteSource sourceBinary = content.getSourceContext().callWith(() -> contentService.getBinary(content.getSourceContent().getId(), sourceThumbnail.getBinaryReference()));
final CreateAttachment createThumbnail = CreateAttachment.create().name(AttachmentNames.THUMBNAIL).mimeType(sourceThumbnail.getMimeType()).byteSource(sourceBinary).build();
final CreateAttachments.Builder createAttachments = CreateAttachments.create().add(createThumbnail);
if (updateParams.getCreateAttachments() != null) {
createAttachments.add(updateParams.getCreateAttachments());
}
updateParams.createAttachments(createAttachments.build());
} else {
final Thumbnail targetThumbnail = content.getTargetContent().getThumbnail();
updateParams.removeAttachments(BinaryReferences.from(targetThumbnail.getBinaryReference()));
}
}
}
use of com.enonic.xp.attachment.CreateAttachments in project xp by enonic.
the class UpdateNodeParamsFactory method produce.
public UpdateNodeParams produce() {
final Content editedContent = params.getEditedContent();
final CreateAttachments createAttachments = params.getCreateAttachments();
final NodeEditor nodeEditor = toNodeEditor(params);
final UpdateNodeParams.Builder builder = UpdateNodeParams.create().id(NodeId.from(editedContent.getId())).editor(nodeEditor);
if (createAttachments != null) {
for (final CreateAttachment createAttachment : createAttachments) {
builder.attachBinary(createAttachment.getBinaryReference(), createAttachment.getByteSource());
}
}
return builder.build();
}
use of com.enonic.xp.attachment.CreateAttachments in project xp by enonic.
the class ImageContentProcessor method processCreate.
@Override
public ProcessCreateResult processCreate(final ProcessCreateParams params) {
final CreateContentParams createContentParams = params.getCreateContentParams();
final MediaInfo mediaInfo = params.getMediaInfo();
final CreateAttachments originalAttachments = createContentParams.getCreateAttachments();
Preconditions.checkArgument(originalAttachments.getSize() == 1, "Expected only one attachment");
final CreateAttachment sourceAttachment = originalAttachments.first();
final XDatas contentXDatas = getXDatas(createContentParams.getType());
ExtraDatas extraDatas = null;
if (mediaInfo != null) {
extraDatas = extractMetadata(mediaInfo, contentXDatas, sourceAttachment);
}
final CreateAttachments.Builder builder = CreateAttachments.create();
builder.add(sourceAttachment);
return new ProcessCreateResult(CreateContentParams.create(createContentParams).createAttachments(builder.build()).extraDatas(extraDatas).build());
}
use of com.enonic.xp.attachment.CreateAttachments in project xp by enonic.
the class HtmlAreaContentProcessor method processUpdate.
@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
final CreateAttachments createAttachments = params.getCreateAttachments();
final ContentEditor editor;
editor = editable -> {
final ContentIds.Builder processedIds = ContentIds.create();
final ContentType contentType = contentTypeService.getByName(GetContentTypeParams.from(editable.source.getType()));
processContentData(editable.data, contentType, processedIds);
processExtraData(editable.extraDatas, processedIds);
processPageData(editable.page, processedIds);
if (editable instanceof EditableSite) {
processSiteConfigData(((EditableSite) editable).siteConfigs, processedIds);
}
editable.processedReferences = processedIds;
};
return new ProcessUpdateResult(createAttachments, editor);
}
use of com.enonic.xp.attachment.CreateAttachments in project xp by enonic.
the class ImageContentProcessorTest method testCreateMoreThanOneAttachmentFails.
@Test
public void testCreateMoreThanOneAttachmentFails() {
final CreateAttachments createAttachments = CreateAttachments.create().add(CreateAttachment.create().name("myAtt1").byteSource(ByteSource.wrap("this is 1st stuff".getBytes())).text("This is the text").build()).add(CreateAttachment.create().name("myAtt2").byteSource(ByteSource.wrap("this is 2nd stuff".getBytes())).text("This is the text").build()).build();
final CreateContentParams params = createContentParams(createAttachments);
final ProcessCreateParams processCreateParams = new ProcessCreateParams(params, MediaInfo.create().build());
assertThrows(IllegalArgumentException.class, () -> this.imageContentProcessor.processCreate(processCreateParams));
}
Aggregations