use of com.enonic.xp.content.processor.ProcessUpdateResult 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);
}
use of com.enonic.xp.content.processor.ProcessUpdateResult in project xp by enonic.
the class ProjectAccessSiteProcessorTest method testProcessUpdateByContentAdmin.
@Test
public void testProcessUpdateByContentAdmin() {
final Context context = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(TEST_USER).principals(RoleKeys.CONTENT_MANAGER_ADMIN).build()).build();
context.runWith(() -> {
final ProcessUpdateParams params = createProcessUpdateParams("white", "blue");
final ProcessUpdateResult result = this.projectAccessSiteProcessor.processUpdate(params);
assertNull(result);
});
}
use of com.enonic.xp.content.processor.ProcessUpdateResult in project xp by enonic.
the class ProjectAccessSiteProcessorTest method testProcessUpdateByAdmin.
@Test
public void testProcessUpdateByAdmin() {
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", "blue");
final ProcessUpdateResult result = this.projectAccessSiteProcessor.processUpdate(params);
assertNull(result);
});
}
use of com.enonic.xp.content.processor.ProcessUpdateResult in project xp by enonic.
the class ImageContentProcessorTest method testProcessUpdateWithMediaInfo.
@Test
public void testProcessUpdateWithMediaInfo() throws IOException {
final Form.Builder form = Form.create();
form.addFormItem(createTextLine("shutterTime", "Exposure Time").occurrences(0, 1).build());
form.addFormItem(createTextLine("altitude", "Gps Altitude").occurrences(0, 1).build());
final XData xDataInfo = createXData(MediaInfo.IMAGE_INFO_METADATA_NAME, "Extra Info", form.build());
Mockito.when(this.xDataService.getFromContentType(Mockito.any())).thenReturn(XDatas.from(xDataInfo));
final CreateAttachments createAttachments = createAttachments();
final ProcessUpdateParams processUpdateParams = ProcessUpdateParams.create().contentType(ContentType.create().superType(ContentTypeName.imageMedia()).name("myContent").build()).mediaInfo(MediaInfo.create().addMetadata("exposure time", "1").addMetadata("gps altitude ", "2").build()).createAttachments(createAttachments).build();
final ProcessUpdateResult result = this.imageContentProcessor.processUpdate(processUpdateParams);
final PropertyTree data = new PropertyTree();
final EditableContent editableContent = new EditableContent(Content.create().name("myContentName").parentPath(ContentPath.ROOT).data(data).build());
result.getEditor().edit(editableContent);
assertEquals(editableContent.extraDatas.first().getData().getString("shutterTime", 0), "1");
assertEquals(editableContent.extraDatas.first().getData().getString("altitude", 0), "2");
assertEquals(13, editableContent.extraDatas.first().getData().getLong(MediaInfo.MEDIA_INFO_BYTE_SIZE, 0));
}
Aggregations