use of com.enonic.xp.content.processor.ProcessUpdateParams in project xp by enonic.
the class ImageContentProcessorTest method testProcessUpdate.
@Test
public void testProcessUpdate() throws IOException {
Mockito.when(contentService.getBinary(Mockito.any(), Mockito.any())).thenReturn(this.loadImage("cat-small.jpg"));
final ProcessUpdateParams processUpdateParams = ProcessUpdateParams.create().contentType(ContentType.create().name(ContentTypeName.imageMedia()).superType(ContentTypeName.imageMedia()).build()).build();
final ProcessUpdateResult result = this.imageContentProcessor.processUpdate(processUpdateParams);
final PropertyTree data = new PropertyTree();
data.addProperty(ContentPropertyNames.MEDIA, ValueFactory.newString("MyImage.jpg"));
final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(ContentTypeName.imageMedia()).parentPath(ContentPath.ROOT).data(data).addExtraData(new ExtraData(MediaInfo.IMAGE_INFO_METADATA_NAME, new PropertyTree())).attachments(Attachments.from(Attachment.create().mimeType("image/jpg").name("MyImage.jpg").build())).build());
result.getEditor().edit(editableContent);
assertNotNull(editableContent.extraDatas.first().getData().getLong("pixelSize", 0));
assertNotNull(editableContent.extraDatas.first().getData().getLong("imageHeight", 0));
assertNotNull(editableContent.extraDatas.first().getData().getLong("imageWidth", 0));
assertNotNull(editableContent.extraDatas.first().getData().getLong("byteSize", 0));
}
use of com.enonic.xp.content.processor.ProcessUpdateParams in project xp by enonic.
the class ProjectAccessSiteProcessorTest method testProcessUpdateWithNoRightsAndNoChanges.
@Test
public void testProcessUpdateWithNoRightsAndNoChanges() {
final Context context = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(TEST_USER).build()).build();
context.runWith(() -> {
final ProcessUpdateParams params = createProcessUpdateParams("white", "white");
final ProcessUpdateResult result = this.projectAccessSiteProcessor.processUpdate(params);
assertNull(result);
});
}
use of com.enonic.xp.content.processor.ProcessUpdateParams in project xp by enonic.
the class ProjectAccessSiteProcessorTest method testProcessUpdateWithNoRights.
@Test
public void testProcessUpdateWithNoRights() throws ProjectAccessRequiredException {
final Context context = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(TEST_USER).build()).build();
context.runWith(() -> {
final ProcessUpdateParams params = createProcessUpdateParams("white", "blue");
assertThrows(ProjectAccessRequiredException.class, () -> this.projectAccessSiteProcessor.processUpdate(params));
});
}
use of com.enonic.xp.content.processor.ProcessUpdateParams in project xp by enonic.
the class ProjectAccessSiteProcessorTest method testProcessUpdateWithNoChanges.
@Test
public void testProcessUpdateWithNoChanges() {
final Context context = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(TEST_USER).principals(RoleKeys.ADMIN).build()).build();
context.runWith(() -> {
final ProcessUpdateParams params = createProcessUpdateParams("white", "white");
final ProcessUpdateResult result = this.projectAccessSiteProcessor.processUpdate(params);
assertNull(result);
});
}
use of com.enonic.xp.content.processor.ProcessUpdateParams in project xp by enonic.
the class ImageContentProcessor method processUpdate.
@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
final CreateAttachments createAttachments = params.getCreateAttachments();
final MediaInfo mediaInfo = params.getMediaInfo();
final CreateAttachment sourceAttachment = createAttachments == null ? null : createAttachments.first();
final ContentEditor editor;
if (mediaInfo != null) {
editor = editable -> {
final Map<XDataName, ExtraData> extraDatas = editable.extraDatas.stream().collect(Collectors.toMap(ExtraData::getName, o -> o));
final XDatas contentXDatas = getXDatas(params.getContentType().getName());
extractMetadata(mediaInfo, contentXDatas, sourceAttachment).forEach(extraData -> extraDatas.put(extraData.getName(), extraData));
editable.extraDatas = ExtraDatas.create().addAll(extraDatas.values()).build();
};
} else {
editor = editable -> {
if (!params.getContentType().getName().isDescendantOfMedia()) {
return;
}
editable.extraDatas = updateImageMetadata(editable);
};
}
return new ProcessUpdateResult(createAttachments, editor);
}
Aggregations