use of com.enonic.xp.content.ExtraDatas in project xp by enonic.
the class CreateNodeParamsFactory method produce.
public CreateNodeParams produce() {
final PropertyTree contentAsData = contentDataSerializer.toCreateNodeData(params);
final PropertySet extraDataSet = contentAsData.getPropertySet(PropertyPath.from(ContentPropertyNames.EXTRA_DATA));
final String language = contentAsData.getString(PropertyPath.from(ContentPropertyNames.LANGUAGE));
final SiteConfigs siteConfigs = new SiteConfigsDataSerializer().fromProperties(contentAsData.getPropertySet(PropertyPath.from(ContentPropertyNames.DATA))).build();
final Page page = contentAsData.hasProperty(COMPONENTS) ? contentDataSerializer.fromPageData(contentAsData.getRoot()) : null;
final ExtraDatas extraData = extraDataSet != null ? contentDataSerializer.fromExtraData(extraDataSet) : null;
final ContentIndexConfigFactory.Builder indexConfigFactoryBuilder = ContentIndexConfigFactory.create().contentTypeName(params.getType()).siteConfigs(siteConfigs).siteService(siteService).xDataService(xDataService).contentTypeService(contentTypeService);
if (page != null) {
indexConfigFactoryBuilder.page(page).pageDescriptorService(pageDescriptorService).partDescriptorService(partDescriptorService).layoutDescriptorService(layoutDescriptorService);
}
if (extraData != null) {
indexConfigFactoryBuilder.extraDatas(extraData);
}
if (!nullToEmpty(language).isBlank()) {
indexConfigFactoryBuilder.language(language);
}
final IndexConfigDocument indexConfigDocument = indexConfigFactoryBuilder.build().produce();
final CreateNodeParams.Builder builder = CreateNodeParams.create().name(resolveNodeName(params.getName())).parent(ContentNodeHelper.translateContentParentToNodeParentPath(params.getParent())).data(contentAsData).indexConfigDocument(indexConfigDocument).permissions(params.getPermissions()).inheritPermissions(params.isInheritPermissions()).childOrder(params.getChildOrder()).nodeType(ContentConstants.CONTENT_NODE_COLLECTION);
for (final CreateAttachment attachment : params.getCreateAttachments()) {
builder.attachBinary(attachment.getBinaryReference(), attachment.getByteSource());
}
return builder.build();
}
use of com.enonic.xp.content.ExtraDatas in project xp by enonic.
the class ImageContentProcessor method processCreate.
@Override
public ProcessCreateResult processCreate(final ProcessCreateParams params) {
final CreateContentParams createContentParams = params.getCreateContentParams();
final MediaInfo mediaInfo = params.getMediaInfo();
final CreateAttachments originalAttachments = createContentParams.getCreateAttachments();
Preconditions.checkArgument(originalAttachments.getSize() == 1, "Expected only one attachment");
final CreateAttachment sourceAttachment = originalAttachments.first();
final XDatas contentXDatas = getXDatas(createContentParams.getType());
ExtraDatas extraDatas = null;
if (mediaInfo != null) {
extraDatas = extractMetadata(mediaInfo, contentXDatas, sourceAttachment);
}
final CreateAttachments.Builder builder = CreateAttachments.create();
builder.add(sourceAttachment);
return new ProcessCreateResult(CreateContentParams.create(createContentParams).createAttachments(builder.build()).extraDatas(extraDatas).build());
}
use of com.enonic.xp.content.ExtraDatas 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.content.ExtraDatas in project xp by enonic.
the class ContentServiceImplTest_update method update_with_metadata.
@Test
public void update_with_metadata() throws Exception {
final PropertyTree data = new PropertyTree();
data.setString("testString", "value");
data.setString("testString2", "value");
final Mixin mixin = Mixin.create().name("myapplication:my_mixin").addFormItem(Input.create().name("inputToBeMixedIn").label("Mixed in").inputType(InputTypeName.TEXT_LINE).build()).build();
Mockito.when(this.mixinService.getByName(Mockito.isA(MixinName.class))).thenReturn(mixin);
final ExtraData extraData = new ExtraData(XDataName.from("myapplication:my_mixin"), new PropertyTree());
ExtraDatas extraDatas = ExtraDatas.from(List.of(extraData));
final CreateContentParams createContentParams = CreateContentParams.create().contentData(data).displayName("This is my content").parent(ContentPath.ROOT).permissions(AccessControlList.empty()).type(ContentTypeName.folder()).extraDatas(extraDatas).build();
final Content content = this.contentService.create(createContentParams);
assertTrue(content.hasExtraData());
final UpdateContentParams updateContentParams = new UpdateContentParams();
updateContentParams.contentId(content.getId()).editor(edit -> {
final PropertyTree editData = edit.data;
editData.setString("testString", "value-updated");
});
this.contentService.update(updateContentParams);
final Content storedContent = this.contentService.getById(content.getId());
assertEquals("This is my content", storedContent.getDisplayName());
assertEquals("value-updated", storedContent.getData().getString("testString"));
assertEquals("value", storedContent.getData().getString("testString2"));
}
use of com.enonic.xp.content.ExtraDatas 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);
}
Aggregations