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();
}
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();
}
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();
}
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")));
}
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")));
}
Aggregations