Search in sources :

Example 21 with ExtraData

use of com.enonic.xp.content.ExtraData in project xp by enonic.

the class PageRendererTest method createContent.

private Content createContent(final String id, final String name, final String contentTypeName) {
    final PropertyTree metadata = new PropertyTree();
    metadata.setLong("myProperty", 1L);
    return Content.create().id(ContentId.from(id)).parentPath(ContentPath.ROOT).name(name).valid(true).createdTime(Instant.parse("2013-08-23T12:55:09.162Z")).creator(PrincipalKey.from("user:system:admin")).owner(PrincipalKey.from("user:myStore:me")).language(Locale.ENGLISH).displayName("My Content").modifiedTime(Instant.parse("2013-08-23T12:55:09.162Z")).modifier(PrincipalKey.from("user:system:admin")).type(ContentTypeName.from(contentTypeName)).addExtraData(new ExtraData(XDataName.from("myApplication:myField"), metadata)).build();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) ExtraData(com.enonic.xp.content.ExtraData)

Example 22 with ExtraData

use of com.enonic.xp.content.ExtraData in project xp by enonic.

the class ContentMappingConstraintTest method newContent.

private Content newContent() {
    final Content.Builder builder = Content.create();
    builder.id(ContentId.from("123456"));
    builder.name("mycontent");
    builder.displayName("My Content");
    builder.parentPath(ContentPath.from("/a/b"));
    builder.type(ContentTypeName.from(ApplicationKey.from("com.enonic.test.app"), "mytype"));
    builder.modifier(PrincipalKey.from("user:system:admin"));
    builder.modifiedTime(Instant.ofEpochSecond(0));
    builder.creator(PrincipalKey.from("user:system:admin"));
    builder.createdTime(Instant.ofEpochSecond(0));
    builder.data(newPropertyTree());
    builder.hasChildren(true);
    builder.valid(true);
    builder.language(Locale.FRENCH);
    builder.addExtraData(new ExtraData(XDataName.from("myapplication:myschema"), newTinyPropertyTree()));
    builder.page(newPage());
    return builder.build();
}
Also used : Content(com.enonic.xp.content.Content) ExtraData(com.enonic.xp.content.ExtraData)

Example 23 with ExtraData

use of com.enonic.xp.content.ExtraData 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 24 with ExtraData

use of com.enonic.xp.content.ExtraData in project xp by enonic.

the class BaseContentHandler method createExtraDatas.

ExtraDatas createExtraDatas(final Map<String, Object> mapValue, final ContentTypeName contentTypeName) {
    if (mapValue == null) {
        return null;
    }
    final ExtraDatas.Builder extradatasBuilder = ExtraDatas.create();
    mapValue.forEach((key, metadatasObject) -> {
        final ApplicationKey applicationKey = ExtraData.fromApplicationPrefix(key);
        if (metadatasObject instanceof Map) {
            final Map<String, Object> metadatas = (Map<String, Object>) metadatasObject;
            metadatas.forEach((metadataName, value) -> {
                final XDataName xDataName = XDataName.from(applicationKey, metadataName);
                final ExtraData item = createExtraData(xDataName, contentTypeName, value);
                if (item != null) {
                    extradatasBuilder.add(item);
                }
            });
        }
    });
    return extradatasBuilder.build();
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ExtraDatas(com.enonic.xp.content.ExtraDatas) ExtraData(com.enonic.xp.content.ExtraData) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) XDataName(com.enonic.xp.schema.xdata.XDataName)

Example 25 with ExtraData

use of com.enonic.xp.content.ExtraData in project xp by enonic.

the class TestDataFixtures method newContent.

public static Content newContent() {
    final Content.Builder builder = Content.create();
    builder.id(ContentId.from("123456"));
    builder.name("mycontent");
    builder.displayName("My Content");
    builder.parentPath(ContentPath.from("/a/b"));
    builder.modifier(PrincipalKey.from("user:system:admin"));
    builder.modifiedTime(Instant.ofEpochSecond(0));
    builder.creator(PrincipalKey.from("user:system:admin"));
    builder.createdTime(Instant.ofEpochSecond(0));
    builder.language(Locale.ENGLISH);
    builder.data(newPropertyTree());
    builder.publishInfo(ContentPublishInfo.create().from(Instant.parse("2016-11-03T10:00:00Z")).to(Instant.parse("2016-11-23T10:00:00Z")).build());
    builder.addExtraData(new ExtraData(XDataName.from("com.enonic.myapplication:myschema"), newTinyPropertyTree()));
    builder.page(newPage());
    builder.attachments(newAttachments());
    return builder.build();
}
Also used : Content(com.enonic.xp.content.Content) ExtraData(com.enonic.xp.content.ExtraData)

Aggregations

ExtraData (com.enonic.xp.content.ExtraData)31 PropertyTree (com.enonic.xp.data.PropertyTree)18 Test (org.junit.jupiter.api.Test)10 XData (com.enonic.xp.schema.xdata.XData)8 XDataName (com.enonic.xp.schema.xdata.XDataName)8 Content (com.enonic.xp.content.Content)7 CreateContentParams (com.enonic.xp.content.CreateContentParams)5 ExtraDatas (com.enonic.xp.content.ExtraDatas)5 ApplicationKey (com.enonic.xp.app.ApplicationKey)4 Media (com.enonic.xp.content.Media)4 ProcessCreateParams (com.enonic.xp.content.processor.ProcessCreateParams)4 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)4 PropertySet (com.enonic.xp.data.PropertySet)4 Attachment (com.enonic.xp.attachment.Attachment)3 FormItem (com.enonic.xp.form.FormItem)3 Input (com.enonic.xp.form.Input)3 GeoPoint (com.enonic.xp.util.GeoPoint)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)2