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