Search in sources :

Example 16 with ExtraData

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

the class ContentMapper method serializeExtraData.

private void serializeExtraData(final MapGenerator gen, final Iterable<ExtraData> values) {
    gen.map("x");
    final ListMultimap<ApplicationKey, ExtraData> extradatasByModule = ArrayListMultimap.create();
    for (ExtraData extraData : values) {
        extradatasByModule.put(extraData.getName().getApplicationKey(), extraData);
    }
    for (final ApplicationKey applicationKey : extradatasByModule.keys()) {
        final List<ExtraData> extraDatas = extradatasByModule.get(applicationKey);
        if (extraDatas.isEmpty()) {
            continue;
        }
        gen.map(extraDatas.get(0).getApplicationPrefix());
        for (final ExtraData extraData : extraDatas) {
            gen.map(extraData.getName().getLocalName());
            new PropertyTreeMapper(extraData.getData()).serialize(gen);
            gen.end();
        }
        gen.end();
    }
    gen.end();
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ExtraData(com.enonic.xp.content.ExtraData) PropertyTreeMapper(com.enonic.xp.lib.common.PropertyTreeMapper)

Example 17 with ExtraData

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

the class ContentFixtures method newMedia.

public static Media newMedia() {
    final Attachment attachment = Attachment.create().name("logo.png").mimeType("image/png").label("small").build();
    final PropertyTree data = newPropertyTree();
    data.addString("media", attachment.getName());
    final PropertyTree mediaData = newPropertyTree();
    mediaData.setLong(IMAGE_INFO_PIXEL_SIZE, 300L * 200L);
    mediaData.setLong(IMAGE_INFO_IMAGE_HEIGHT, 200L);
    mediaData.setLong(IMAGE_INFO_IMAGE_WIDTH, 300L);
    mediaData.setLong(MEDIA_INFO_BYTE_SIZE, 100000L);
    final ExtraData mediaExtraData = new ExtraData(MediaInfo.IMAGE_INFO_METADATA_NAME, mediaData);
    final Media.Builder builder = Media.create();
    builder.id(ContentId.from("123456"));
    builder.type(ContentTypeName.imageMedia());
    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.attachments(Attachments.from(attachment));
    builder.data(data);
    builder.addExtraData(new ExtraData(XDataName.from("myapplication:myschema"), newTinyPropertyTree()));
    builder.addExtraData(mediaExtraData);
    builder.page(newPage());
    return builder.build();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Media(com.enonic.xp.content.Media) Attachment(com.enonic.xp.attachment.Attachment) ExtraData(com.enonic.xp.content.ExtraData)

Example 18 with ExtraData

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

the class ContentFixtures 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.data(newPropertyTree());
    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 19 with ExtraData

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

the class HtmlAreaContentProcessorTest method extra_data.

@Test
public void extra_data() throws IOException {
    final XDataName xDataName = XDataName.from("xDataName");
    final XData xData = XData.create().name(xDataName).addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
    final ContentType contentType = ContentType.create().name(contentTypeName).superType(ContentTypeName.folder()).xData(XDataNames.from(xDataName)).build();
    Mockito.when(contentTypeService.getByName(GetContentTypeParams.from(ContentTypeName.site()))).thenReturn(contentType);
    Mockito.when(xDataService.getByNames(XDataNames.from(xDataName))).thenReturn(XDatas.from(xData));
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans01.jpg\" data-src=\"image://image-id\"/>"));
    final EditableSite editableSite = new EditableSite(Site.create().name("myContentName").type(ContentTypeName.site()).parentPath(ContentPath.ROOT).data(new PropertyTree()).extraDatas(ExtraDatas.create().add(new ExtraData(XDataName.from("xDataName"), data)).build()).build());
    result.getEditor().edit(editableSite);
    assertEquals(1, editableSite.processedReferences.build().getSize());
    assertTrue(editableSite.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) EditableSite(com.enonic.xp.content.EditableSite) PropertyTree(com.enonic.xp.data.PropertyTree) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName) Test(org.junit.jupiter.api.Test)

Example 20 with ExtraData

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

the class HtmlAreaContentProcessorTest method create.

@Test
public void create() throws IOException {
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans01.jpg\" data-src=\"image://image-id1\"/>"));
    final XDataName xDataName = XDataName.from("xDataName");
    final XData xData = XData.create().name(xDataName).addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
    final PropertyTree extraData = new PropertyTree();
    extraData.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans02.jpg\" data-src=\"image://image-id2\"/>"));
    Mockito.when(xDataService.getByNames(XDataNames.from(xDataName))).thenReturn(XDatas.from(xData));
    final ProcessCreateParams processCreateParams = Mockito.mock(ProcessCreateParams.class);
    final CreateContentParams createContentParams = CreateContentParams.create().parent(ContentPath.ROOT).contentData(data).extraDatas(ExtraDatas.create().add(new ExtraData(XDataName.from("xDataName"), extraData)).build()).type(contentTypeName).build();
    contentType = ContentType.create(contentType).xData(XDataNames.from(XDataName.from("xDataName"))).build();
    Mockito.when(contentTypeService.getByName(GetContentTypeParams.from(contentTypeName))).thenReturn(contentType);
    Mockito.when(processCreateParams.getCreateContentParams()).thenReturn(createContentParams);
    final ProcessCreateResult result = htmlAreaContentProcessor.processCreate(processCreateParams);
    assertEquals(2, result.getCreateContentParams().getProcessedIds().getSize());
    assertTrue(result.getCreateContentParams().getProcessedIds().contains(ContentId.from("image-id1")));
    assertTrue(result.getCreateContentParams().getProcessedIds().contains(ContentId.from("image-id2")));
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Test(org.junit.jupiter.api.Test)

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