Search in sources :

Example 6 with ProcessCreateResult

use of com.enonic.xp.content.processor.ProcessCreateResult 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)

Example 7 with ProcessCreateResult

use of com.enonic.xp.content.processor.ProcessCreateResult 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)

Aggregations

CreateContentParams (com.enonic.xp.content.CreateContentParams)7 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)7 ProcessCreateParams (com.enonic.xp.content.processor.ProcessCreateParams)5 Test (org.junit.jupiter.api.Test)4 ExtraData (com.enonic.xp.content.ExtraData)3 XData (com.enonic.xp.schema.xdata.XData)3 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)2 ContentType (com.enonic.xp.schema.content.ContentType)2 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)1 ContentIds (com.enonic.xp.content.ContentIds)1 ExtraDatas (com.enonic.xp.content.ExtraDatas)1 ContentProcessor (com.enonic.xp.content.processor.ContentProcessor)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 Form (com.enonic.xp.form.Form)1 MediaInfo (com.enonic.xp.media.MediaInfo)1 XDataName (com.enonic.xp.schema.xdata.XDataName)1 XDatas (com.enonic.xp.schema.xdata.XDatas)1 GeoPoint (com.enonic.xp.util.GeoPoint)1