Search in sources :

Example 1 with ExtraDatas

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();
}
Also used : SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) Page(com.enonic.xp.page.Page) SiteConfigs(com.enonic.xp.site.SiteConfigs) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ExtraDatas(com.enonic.xp.content.ExtraDatas) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument) ContentIndexConfigFactory(com.enonic.xp.core.impl.content.index.ContentIndexConfigFactory)

Example 2 with ExtraDatas

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());
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) MediaInfo(com.enonic.xp.media.MediaInfo) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) CreateContentParams(com.enonic.xp.content.CreateContentParams) XDatas(com.enonic.xp.schema.xdata.XDatas) ExtraDatas(com.enonic.xp.content.ExtraDatas) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult)

Example 3 with ExtraDatas

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;
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ExtraDatas(com.enonic.xp.content.ExtraDatas) PropertySet(com.enonic.xp.data.PropertySet) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName)

Example 4 with ExtraDatas

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"));
}
Also used : MixinName(com.enonic.xp.schema.mixin.MixinName) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ExtraDatas(com.enonic.xp.content.ExtraDatas) ExtraData(com.enonic.xp.content.ExtraData) Mixin(com.enonic.xp.schema.mixin.Mixin) Test(org.junit.jupiter.api.Test)

Example 5 with ExtraDatas

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);
}
Also used : MediaInfo(com.enonic.xp.media.MediaInfo) Cropping(com.enonic.xp.image.Cropping) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) ContentEditor(com.enonic.xp.content.ContentEditor) MEDIA_INFO_BYTE_SIZE(com.enonic.xp.media.MediaInfo.MEDIA_INFO_BYTE_SIZE) Map(java.util.Map) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ImageIO(javax.imageio.ImageIO) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) XDataName(com.enonic.xp.schema.xdata.XDataName) Media(com.enonic.xp.content.Media) Property(com.enonic.xp.data.Property) IMAGE_INFO_PIXEL_SIZE(com.enonic.xp.media.MediaInfo.IMAGE_INFO_PIXEL_SIZE) BufferedImage(java.awt.image.BufferedImage) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ContentProcessor(com.enonic.xp.content.processor.ContentProcessor) IMAGE_INFO_IMAGE_WIDTH(com.enonic.xp.media.MediaInfo.IMAGE_INFO_IMAGE_WIDTH) ContentType(com.enonic.xp.schema.content.ContentType) Collectors(java.util.stream.Collectors) ExtraDatas(com.enonic.xp.content.ExtraDatas) EditableContent(com.enonic.xp.content.EditableContent) InputTypeName(com.enonic.xp.inputtype.InputTypeName) FormItem(com.enonic.xp.form.FormItem) IMAGE_INFO_IMAGE_HEIGHT(com.enonic.xp.media.MediaInfo.IMAGE_INFO_IMAGE_HEIGHT) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) CreateContentParams(com.enonic.xp.content.CreateContentParams) ContentService(com.enonic.xp.content.ContentService) IMAGE_INFO(com.enonic.xp.media.MediaInfo.IMAGE_INFO) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) HashMap(java.util.HashMap) Attachment(com.enonic.xp.attachment.Attachment) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Component(org.osgi.service.component.annotations.Component) FormItemType(com.enonic.xp.form.FormItemType) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ExtraData(com.enonic.xp.content.ExtraData) XData(com.enonic.xp.schema.xdata.XData) Exceptions(com.enonic.xp.util.Exceptions) GeoPoint(com.enonic.xp.util.GeoPoint) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ByteSource(com.google.common.io.ByteSource) XDataService(com.enonic.xp.schema.xdata.XDataService) PropertyTree(com.enonic.xp.data.PropertyTree) ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) XDatas(com.enonic.xp.schema.xdata.XDatas) IOException(java.io.IOException) ValueTypes(com.enonic.xp.data.ValueTypes) Preconditions(com.google.common.base.Preconditions) Input(com.enonic.xp.form.Input) Reference(org.osgi.service.component.annotations.Reference) InputStream(java.io.InputStream) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) MediaInfo(com.enonic.xp.media.MediaInfo) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ContentEditor(com.enonic.xp.content.ContentEditor) XDatas(com.enonic.xp.schema.xdata.XDatas) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName)

Aggregations

ExtraDatas (com.enonic.xp.content.ExtraDatas)9 PropertyTree (com.enonic.xp.data.PropertyTree)6 ExtraData (com.enonic.xp.content.ExtraData)5 PropertySet (com.enonic.xp.data.PropertySet)4 XDataName (com.enonic.xp.schema.xdata.XDataName)4 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)3 CreateContentParams (com.enonic.xp.content.CreateContentParams)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)2 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)2 FormItem (com.enonic.xp.form.FormItem)2 Input (com.enonic.xp.form.Input)2 MediaInfo (com.enonic.xp.media.MediaInfo)2 XData (com.enonic.xp.schema.xdata.XData)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Attachment (com.enonic.xp.attachment.Attachment)1 Content (com.enonic.xp.content.Content)1