use of com.enonic.xp.attachment.Attachments in project xp by enonic.
the class AttachmentHandlerWorker method resolveAttachment.
private Attachment resolveAttachment(final Content content, final String name) {
final Attachments attachments = content.getAttachments();
final Attachment attachment = attachments.byName(name);
if (attachment != null) {
return attachment;
}
throw WebException.notFound(String.format("Attachment [%s] not found for [%s]", name, content.getPath()));
}
use of com.enonic.xp.attachment.Attachments in project xp by enonic.
the class AttachmentUrlBuilder method resolveAttachment.
private Attachment resolveAttachment(final Content content) {
final Attachments attachments = content.getAttachments();
final Attachment attachment;
if (this.params.getName() != null) {
attachment = attachments.byName(this.params.getName());
if (attachment == null) {
throw new IllegalArgumentException("Could not find attachment with name [" + this.params.getName() + "] on content [" + content.getId() + "]");
}
} else {
final String label = this.params.getLabel() != null ? this.params.getLabel() : "source";
attachment = attachments.byLabel(label);
if (attachment == null) {
throw new IllegalArgumentException("Could not find attachment with label [" + label + "] on content [" + content.getId() + "]");
}
}
return attachment;
}
use of com.enonic.xp.attachment.Attachments in project xp by enonic.
the class ContentDataSerializer method toUpdateNodeData.
public PropertyTree toUpdateNodeData(final UpdateContentTranslatorParams params) {
final PropertyTree newPropertyTree = new PropertyTree();
final PropertySet contentAsData = newPropertyTree.getRoot();
final Content content = params.getEditedContent();
addMetadata(contentAsData, content, params.getModifier());
contentAsData.addSet(DATA, content.getData().getRoot().copy(contentAsData.getTree()));
if (content.hasExtraData()) {
extraDataSerializer.toData(content.getAllExtraData(), contentAsData);
}
final Attachments attachments = mergeExistingAndUpdatedAttachments(content.getAttachments(), params);
applyAttachmentsAsData(attachments, contentAsData);
if (content.hasPage()) {
pageDataSerializer.toData(content.getPage(), contentAsData);
}
addProcessedReferences(contentAsData, content.getProcessedReferences());
return newPropertyTree;
}
use of com.enonic.xp.attachment.Attachments in project xp by enonic.
the class ContentServiceImplTest_create method create_with_attachments.
@Test
public void create_with_attachments() throws Exception {
final String name = "cat-small.jpg";
final ByteSource image = loadImage(name);
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.imageMedia()).createAttachments(createAttachment("cat", "image/jpeg", image)).build();
final Content content = this.contentService.create(createContentParams);
final Content storedContent = this.contentService.getById(content.getId());
final Attachments attachments = storedContent.getAttachments();
assertEquals(1, attachments.getSize());
}
use of com.enonic.xp.attachment.Attachments in project xp by enonic.
the class ContentServiceImplTest_media method create_media_image.
@Test
public void create_media_image() throws Exception {
final CreateMediaParams createMediaParams = new CreateMediaParams();
createMediaParams.byteSource(loadImage("cat-small.jpg")).name("Small cat").parent(ContentPath.ROOT);
Mockito.when(this.xDataService.getFromContentType(Mockito.any(ContentType.class))).thenReturn(XDatas.empty());
final Content content = this.contentService.create(createMediaParams);
final Content storedContent = this.contentService.getById(content.getId());
assertNotNull(storedContent.getName());
assertNotNull(storedContent.getCreatedTime());
assertNotNull(storedContent.getCreator());
assertNotNull(storedContent.getModifiedTime());
assertNotNull(storedContent.getModifier());
assertNotNull(storedContent.getData().getString(ContentPropertyNames.MEDIA));
final Attachments attachments = storedContent.getAttachments();
assertEquals(1, attachments.getSize());
}
Aggregations