use of com.enonic.xp.schema.xdata.XData in project xp by enonic.
the class ImageContentProcessor method extractMetadata.
private ExtraDatas extractMetadata(final MediaInfo mediaInfo, final XDatas xDatas, final CreateAttachment sourceAttachment) {
final ExtraDatas.Builder extradatasBuilder = ExtraDatas.create();
final Map<XDataName, ExtraData> metadataMap = new HashMap<>();
final ExtraData geoData = extractGeoLocation(mediaInfo, xDatas);
if (geoData != null) {
metadataMap.put(MediaInfo.GPS_INFO_METADATA_NAME, geoData);
extradatasBuilder.add(geoData);
}
for (Map.Entry<String, Collection<String>> entry : mediaInfo.getMetadata().asMap().entrySet()) {
for (XData xData : xDatas) {
final String formItemName = getConformityName(entry.getKey());
final FormItem formItem = xData.getForm().getFormItems().getItemByName(formItemName);
if (formItem == null) {
continue;
}
ExtraData extraData = metadataMap.get(xData.getName());
if (extraData == null) {
extraData = new ExtraData(xData.getName(), new PropertyTree());
metadataMap.put(xData.getName(), extraData);
extradatasBuilder.add(extraData);
}
if (FormItemType.INPUT.equals(formItem.getType())) {
Input input = (Input) formItem;
if (InputTypeName.DATE_TIME.equals(input.getInputType())) {
extraData.getData().addLocalDateTime(formItemName, ValueTypes.LOCAL_DATE_TIME.convert(entry.getValue().toArray()[0]));
} else if (InputTypeName.LONG.equals(input.getInputType())) {
final Long[] longValues = entry.getValue().stream().map(Long::parseLong).toArray(Long[]::new);
extraData.getData().addLongs(formItemName, longValues);
} else {
extraData.getData().addStrings(formItemName, entry.getValue());
}
}
}
}
fillComputedFormItems(metadataMap.values(), mediaInfo, sourceAttachment);
return extradatasBuilder.build();
}
use of com.enonic.xp.schema.xdata.XData in project xp by enonic.
the class ImageContentProcessor method extractGeoLocation.
private ExtraData extractGeoLocation(final MediaInfo mediaInfo, final XDatas xDatas) {
final ImmutableMultimap<String, String> mediaItems = mediaInfo.getMetadata();
final Double geoLat = parseDouble(mediaItems.get(GEO_LATITUDE).stream().findFirst().orElse(null));
final Double geoLong = parseDouble(mediaItems.get(GEO_LONGITUDE).stream().findFirst().orElse(null));
if (geoLat == null || geoLong == null) {
return null;
}
final XData geoMixin = xDatas.getXData(MediaInfo.GPS_INFO_METADATA_NAME);
if (geoMixin == null) {
return null;
}
final ExtraData extraData = new ExtraData(geoMixin.getName(), new PropertyTree());
final FormItem formItem = geoMixin.getForm().getFormItems().getItemByName(MediaInfo.GPS_INFO_GEO_POINT);
if (FormItemType.INPUT.equals(formItem.getType())) {
final Input input = (Input) formItem;
if (InputTypeName.GEO_POINT.equals(input.getInputType())) {
final GeoPoint geoPoint = new GeoPoint(geoLat, geoLong);
extraData.getData().addGeoPoint(formItem.getName(), ValueTypes.GEO_POINT.convert(geoPoint));
}
}
return extraData;
}
use of com.enonic.xp.schema.xdata.XData 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.schema.xdata.XData in project xp by enonic.
the class ImageContentProcessorTest method testProcessUpdateWithMediaInfo.
@Test
public void testProcessUpdateWithMediaInfo() 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 CreateAttachments createAttachments = createAttachments();
final ProcessUpdateParams processUpdateParams = ProcessUpdateParams.create().contentType(ContentType.create().superType(ContentTypeName.imageMedia()).name("myContent").build()).mediaInfo(MediaInfo.create().addMetadata("exposure time", "1").addMetadata("gps altitude ", "2").build()).createAttachments(createAttachments).build();
final ProcessUpdateResult result = this.imageContentProcessor.processUpdate(processUpdateParams);
final PropertyTree data = new PropertyTree();
final EditableContent editableContent = new EditableContent(Content.create().name("myContentName").parentPath(ContentPath.ROOT).data(data).build());
result.getEditor().edit(editableContent);
assertEquals(editableContent.extraDatas.first().getData().getString("shutterTime", 0), "1");
assertEquals(editableContent.extraDatas.first().getData().getString("altitude", 0), "2");
assertEquals(13, editableContent.extraDatas.first().getData().getLong(MediaInfo.MEDIA_INFO_BYTE_SIZE, 0));
}
use of com.enonic.xp.schema.xdata.XData in project xp by enonic.
the class XDataServiceImplTest method testApplications.
@Test
public void testApplications() {
initializeApps();
final XDatas types1 = this.service.getAll();
assertNotNull(types1);
assertEquals(9, types1.getSize());
final XDatas types2 = this.service.getByApplication(ApplicationKey.from("myapp1"));
assertNotNull(types2);
assertEquals(2, types2.getSize());
final XDatas types3 = this.service.getByApplication(ApplicationKey.from("myapp2"));
assertNotNull(types3);
assertEquals(4, types3.getSize());
final XData xData = service.getByName(XDataName.from("myapp2:xdata1"));
assertNotNull(xData);
}
Aggregations