Search in sources :

Example 1 with ProcessCreateParams

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());
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ContentType(com.enonic.xp.schema.content.ContentType) CreateContentParams(com.enonic.xp.content.CreateContentParams) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessCreateParams

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);
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) CreateContentParams(com.enonic.xp.content.CreateContentParams) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Test(org.junit.jupiter.api.Test)

Example 3 with ProcessCreateParams

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));
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) CreateContentParams(com.enonic.xp.content.CreateContentParams) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Test(org.junit.jupiter.api.Test)

Example 4 with 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));
}
Also used : Form(com.enonic.xp.form.Form) CreateContentParams(com.enonic.xp.content.CreateContentParams) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Test(org.junit.jupiter.api.Test)

Example 5 with ProcessCreateParams

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;
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) ContentProcessor(com.enonic.xp.content.processor.ContentProcessor) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams)

Aggregations

CreateContentParams (com.enonic.xp.content.CreateContentParams)6 ProcessCreateParams (com.enonic.xp.content.processor.ProcessCreateParams)6 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)5 Test (org.junit.jupiter.api.Test)5 ExtraData (com.enonic.xp.content.ExtraData)3 XData (com.enonic.xp.schema.xdata.XData)3 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)2 ContentProcessor (com.enonic.xp.content.processor.ContentProcessor)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 Form (com.enonic.xp.form.Form)1 ContentType (com.enonic.xp.schema.content.ContentType)1 XDataName (com.enonic.xp.schema.xdata.XDataName)1 GeoPoint (com.enonic.xp.util.GeoPoint)1