use of com.enonic.xp.content.processor.ProcessCreateParams in project xp by enonic.
the class ImageContentProcessorTest method testProcessCreate.
@Test
public void testProcessCreate() throws IOException {
Mockito.when(this.xDataService.getFromContentType(Mockito.any(ContentType.class))).thenReturn(XDatas.empty());
final CreateAttachments createAttachments = createAttachments();
final CreateContentParams params = createContentParams(createAttachments);
final ProcessCreateParams processCreateParams = new ProcessCreateParams(params, MediaInfo.create().build());
final ProcessCreateResult result = this.imageContentProcessor.processCreate(processCreateParams);
assertEquals(result.getCreateContentParams().getCreateAttachments().first(), createAttachments.first());
}
use of com.enonic.xp.content.processor.ProcessCreateParams in project xp by enonic.
the class ImageContentProcessorTest method testProcessCreateWithGeoData.
@Test
public void testProcessCreateWithGeoData() throws IOException {
final XData gpsInfo = createXData(GPS_INFO_METADATA_NAME, "Gps Info", createGpsInfoMixinForm());
Mockito.when(this.xDataService.getFromContentType(Mockito.any())).thenReturn(XDatas.from(gpsInfo));
final CreateContentParams params = createContentParams(createAttachments());
final ProcessCreateParams processCreateParams = new ProcessCreateParams(params, MediaInfo.create().addMetadata("geo lat", "1").addMetadata("geo long", "2").build());
final GeoPoint geoPoint = new GeoPoint(1.0, 2.0);
final ProcessCreateResult result = this.imageContentProcessor.processCreate(processCreateParams);
final ExtraData geoExtraData = result.getCreateContentParams().getExtraDatas().first();
assertEquals(geoExtraData.getName(), GPS_INFO_METADATA_NAME);
assertEquals(geoExtraData.getData().getGeoPoint(MediaInfo.GPS_INFO_GEO_POINT, 0), geoPoint);
}
use of com.enonic.xp.content.processor.ProcessCreateParams 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));
}
use of com.enonic.xp.content.processor.ProcessCreateParams in project xp by enonic.
the class ImageContentProcessorTest method testProcessCreateWithExtraData.
@Test
public void testProcessCreateWithExtraData() 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 CreateContentParams params = createContentParams(createAttachments());
final ProcessCreateParams processCreateParams = new ProcessCreateParams(params, MediaInfo.create().addMetadata("exposure time", "1").addMetadata("gps altitude ", "2").build());
final ProcessCreateResult result = this.imageContentProcessor.processCreate(processCreateParams);
final ExtraData extraData = result.getCreateContentParams().getExtraDatas().first();
assertEquals(xDataInfo.getName(), extraData.getName());
assertEquals(extraData.getData().getString("shutterTime", 0), "1");
assertEquals(extraData.getData().getString("altitude", 0), "2");
assertEquals(13, extraData.getData().getLong(MediaInfo.MEDIA_INFO_BYTE_SIZE, 0));
}
use of com.enonic.xp.content.processor.ProcessCreateParams in project xp by enonic.
the class CreateContentCommand method runContentProcessors.
private CreateContentParams runContentProcessors(final CreateContentParams createContentParams, final ContentType contentType) {
CreateContentParams processedParams = createContentParams;
for (final ContentProcessor contentProcessor : this.contentProcessors) {
if (contentProcessor.supports(contentType)) {
final ProcessCreateResult result = contentProcessor.processCreate(new ProcessCreateParams(processedParams, mediaInfo));
processedParams = CreateContentParams.create(result.getCreateContentParams()).build();
}
}
return processedParams;
}
Aggregations