Search in sources :

Example 96 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class ContentDataProcessor method process.

public PropertyTree process(final PropertyTree originalData) {
    final PropertyTree data = originalData.copy();
    if (data.hasProperty(ContentPropertyNames.INHERIT)) {
        boolean changed = false;
        final ImmutableSet.Builder<String> inheritSet = ImmutableSet.builder();
        for (final String value : data.getStrings(ContentPropertyNames.INHERIT)) {
            if (!getTypesToProceed().contains(ContentInheritType.valueOf(value))) {
                inheritSet.add(value);
            } else {
                changed = true;
            }
        }
        if (changed) {
            data.removeProperties(ContentPropertyNames.INHERIT);
            data.addStrings(ContentPropertyNames.INHERIT, inheritSet.build());
        }
    }
    return data;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) PropertyTree(com.enonic.xp.data.PropertyTree)

Example 97 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class ContentOutboundDependenciesIdsResolver method resolveOutboundDependenciesIds.

private ContentIds resolveOutboundDependenciesIds(final ContentId contentId) {
    final Content content = this.contentService.getById(contentId);
    final ContentIds.Builder contentIds = ContentIds.create();
    final PropertySet contentPageData = new PropertyTree().getRoot();
    if (content.getPage() != null) {
        contentDataSerializer.toPageData(content.getPage(), contentPageData);
    }
    final Stream<Property> extraDataDependencies = content.hasExtraData() ? content.getAllExtraData().stream().flatMap(extraData -> extraData.getData().getProperties(ValueTypes.REFERENCE).stream()) : Stream.empty();
    Stream.of(content.getData().getProperties(ValueTypes.REFERENCE).stream(), contentPageData.getProperties(ValueTypes.REFERENCE).stream(), extraDataDependencies).flatMap(s -> s).forEach(property -> {
        final String value = property.getValue().toString();
        if (!contentId.toString().equals(value) && !nullToEmpty(value).isBlank()) {
            contentIds.add(ContentId.from(value));
        }
    });
    if (content.getProcessedReferences() != null && content.getProcessedReferences().getSize() > 0) {
        contentIds.addAll(content.getProcessedReferences());
    }
    return contentIds.build();
}
Also used : ContentId(com.enonic.xp.content.ContentId) ContentService(com.enonic.xp.content.ContentService) Property(com.enonic.xp.data.Property) Stream(java.util.stream.Stream) ContentIds(com.enonic.xp.content.ContentIds) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) PropertySet(com.enonic.xp.data.PropertySet) Content(com.enonic.xp.content.Content) ContentDataSerializer(com.enonic.xp.core.impl.content.serializer.ContentDataSerializer) ValueTypes(com.enonic.xp.data.ValueTypes) PropertyTree(com.enonic.xp.data.PropertyTree) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIds(com.enonic.xp.content.ContentIds) PropertySet(com.enonic.xp.data.PropertySet) Property(com.enonic.xp.data.Property)

Example 98 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class ContentServiceImpl method create.

@Override
public Content create(final CreateContentParams params) {
    final Content content = CreateContentCommand.create().nodeService(this.nodeService).contentTypeService(this.contentTypeService).translator(this.translator).eventPublisher(this.eventPublisher).siteService(this.siteService).xDataService(this.xDataService).contentProcessors(this.contentProcessors).contentValidators(this.contentValidators).formDefaultValuesProcessor(this.formDefaultValuesProcessor).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).allowUnsafeAttachmentNames(config.attachments_allowUnsafeNames()).params(params).build().execute();
    if (content instanceof Site) {
        this.create(CreateContentParams.create().owner(content.getOwner()).displayName(TEMPLATES_FOLDER_DISPLAY_NAME).name(TEMPLATES_FOLDER_NAME).inheritPermissions(true).parent(content.getPath()).type(ContentTypeName.templateFolder()).requireValid(true).contentData(new PropertyTree()).build());
        return this.doGetById(content.getId());
    }
    contentAuditLogSupport.createContent(params, content);
    return content;
}
Also used : Site(com.enonic.xp.site.Site) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree)

Example 99 with PropertyTree

use of com.enonic.xp.data.PropertyTree 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 100 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class CreateMediaCommand method doExecute.

private Content doExecute() {
    final MediaInfo mediaInfo = mediaInfoService.parseMediaInfo(params.getByteSource());
    if ((params.getMimeType() == null || isBinaryContentType(params.getMimeType())) && mediaInfo.getMediaType() != null) {
        params.mimeType(mediaInfo.getMediaType());
    }
    Preconditions.checkNotNull(params.getMimeType(), "Unable to resolve media type");
    final ContentTypeName resolvedTypeFromMimeType = ContentTypeFromMimeTypeResolver.resolve(params.getMimeType());
    final ContentTypeName type = resolvedTypeFromMimeType != null ? resolvedTypeFromMimeType : isExecutableContentType(params.getMimeType(), params.getName()) ? ContentTypeName.executableMedia() : ContentTypeName.unknownMedia();
    final PropertyTree data = new PropertyTree();
    new MediaFormDataBuilder().type(type).attachment(params.getName()).focalX(params.getFocalX()).focalY(params.getFocalY()).caption(params.getCaption()).artist(params.getArtist()).copyright(params.getCopyright()).tags(params.getTags()).build(data);
    final CreateAttachment mediaAttachment = CreateAttachment.create().name(params.getName()).mimeType(params.getMimeType()).label("source").byteSource(params.getByteSource()).text(type.isTextualMedia() ? mediaInfo.getTextContent() : "").build();
    final CreateContentParams createContentParams = CreateContentParams.create().name(params.getName()).parent(params.getParent()).requireValid(true).type(type).displayName(trimExtension(params.getName())).contentData(data).createAttachments(CreateAttachments.from(mediaAttachment)).inheritPermissions(true).build();
    final CreateContentCommand createCommand = CreateContentCommand.create(this).mediaInfo(mediaInfo).params(createContentParams).siteService(this.siteService).xDataService(this.xDataService).formDefaultValuesProcessor(this.formDefaultValuesProcessor).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).allowUnsafeAttachmentNames(this.allowUnsafeAttachmentNames).build();
    return createCommand.execute();
}
Also used : MediaInfo(com.enonic.xp.media.MediaInfo) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName)

Aggregations

PropertyTree (com.enonic.xp.data.PropertyTree)639 Test (org.junit.jupiter.api.Test)404 PropertySet (com.enonic.xp.data.PropertySet)134 Content (com.enonic.xp.content.Content)125 Node (com.enonic.xp.node.Node)112 CreateContentParams (com.enonic.xp.content.CreateContentParams)64 Form (com.enonic.xp.form.Form)37 Page (com.enonic.xp.page.Page)32 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)31 DescriptorKey (com.enonic.xp.page.DescriptorKey)30 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)30 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)28 PrincipalKey (com.enonic.xp.security.PrincipalKey)28 BinaryReference (com.enonic.xp.util.BinaryReference)28 Property (com.enonic.xp.data.Property)26 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)24 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)23 ByteSource (com.google.common.io.ByteSource)22 ExtraData (com.enonic.xp.content.ExtraData)21 Instant (java.time.Instant)21