use of com.enonic.xp.schema.xdata.XDataName in project xp by enonic.
the class ContentMappingConstraint method getXData.
private PropertyTree getXData(final ExtraDatas xDatas, final String appPrefix, final String name) {
if (xDatas == null) {
return null;
}
try {
final ApplicationKey app = ExtraData.fromApplicationPrefix(appPrefix);
final XDataName xDataName = XDataName.from(app, name);
final ExtraData extraData = xDatas.getMetadata(xDataName);
if (extraData == null) {
return null;
}
return extraData.getData();
} catch (Exception e) {
return null;
}
}
use of com.enonic.xp.schema.xdata.XDataName in project xp by enonic.
the class ExtraDataSerializer method fromData.
@Override
public ExtraDatas fromData(final PropertySet metadataSet) {
if (metadataSet != null) {
final ExtraDatas.Builder extradatasBuilder = ExtraDatas.create();
for (final String metadataApplicationPrefix : metadataSet.getPropertyNames()) {
final PropertySet xDataApplication = metadataSet.getSet(metadataApplicationPrefix);
for (final String metadataLocalName : xDataApplication.getPropertyNames()) {
final ApplicationKey applicationKey = ExtraData.fromApplicationPrefix(metadataApplicationPrefix);
final XDataName metadataName = XDataName.from(applicationKey, metadataLocalName);
extradatasBuilder.add(new ExtraData(metadataName, xDataApplication.getSet(metadataLocalName).toTree()));
}
}
return extradatasBuilder.build();
}
return null;
}
use of com.enonic.xp.schema.xdata.XDataName in project xp by enonic.
the class XmlContentTypeParser method buildMetaData.
private XDataNames buildMetaData(final DomElement root) {
final List<XDataName> names = new ArrayList<>();
for (final DomElement child : root.getChildren("x-data")) {
String name = child.getAttribute("name");
names.add(this.resolver.toXDataName(name));
}
return XDataNames.from(names);
}
use of com.enonic.xp.schema.xdata.XDataName in project xp by enonic.
the class ImageContentProcessor method processUpdate.
@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
final CreateAttachments createAttachments = params.getCreateAttachments();
final MediaInfo mediaInfo = params.getMediaInfo();
final CreateAttachment sourceAttachment = createAttachments == null ? null : createAttachments.first();
final ContentEditor editor;
if (mediaInfo != null) {
editor = editable -> {
final Map<XDataName, ExtraData> extraDatas = editable.extraDatas.stream().collect(Collectors.toMap(ExtraData::getName, o -> o));
final XDatas contentXDatas = getXDatas(params.getContentType().getName());
extractMetadata(mediaInfo, contentXDatas, sourceAttachment).forEach(extraData -> extraDatas.put(extraData.getName(), extraData));
editable.extraDatas = ExtraDatas.create().addAll(extraDatas.values()).build();
};
} else {
editor = editable -> {
if (!params.getContentType().getName().isDescendantOfMedia()) {
return;
}
editable.extraDatas = updateImageMetadata(editable);
};
}
return new ProcessUpdateResult(createAttachments, editor);
}
use of com.enonic.xp.schema.xdata.XDataName 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();
}
Aggregations