Search in sources :

Example 6 with ContentTypeName

use of com.enonic.xp.schema.content.ContentTypeName in project xp by enonic.

the class ContentTypeFilterTypeTest method testContentFilterIteration.

@Test
public void testContentFilterIteration() throws Exception {
    final ContentTypeFilter filter = ContentTypeFilter.create().defaultAllow().denyContentType(ContentTypeName.from("myapplication:com.enonic.tweet")).denyContentType("myapplication:system.folder").denyContentTypes(ContentTypeNames.from("myapplication:com.enonic.article", "myapplication:com.enonic.employee")).build();
    final Iterator<ContentTypeName> iterator = filter.iterator();
    assertEquals(ContentTypeName.from("myapplication:com.enonic.tweet"), iterator.next());
    assertEquals(ContentTypeName.from("myapplication:system.folder"), iterator.next());
    assertEquals(ContentTypeName.from("myapplication:com.enonic.article"), iterator.next());
    assertEquals(ContentTypeName.from("myapplication:com.enonic.employee"), iterator.next());
    assertFalse(iterator.hasNext());
}
Also used : ContentTypeFilter(com.enonic.xp.schema.content.ContentTypeFilter) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) Test(org.junit.jupiter.api.Test)

Example 7 with ContentTypeName

use of com.enonic.xp.schema.content.ContentTypeName in project xp by enonic.

the class ContentQueryNodeQueryTranslator method processContentTypesNames.

private static void processContentTypesNames(final ContentQuery contentQuery, final NodeQuery.Builder builder) {
    final ContentTypeNames contentTypeNames = contentQuery.getContentTypes();
    if (contentTypeNames != null && contentTypeNames.isNotEmpty()) {
        final ValueFilter.Builder contentTypeFilterBuilder = ValueFilter.create().fieldName(ContentPropertyNames.TYPE).setCache(true);
        for (final ContentTypeName contentTypeName : contentTypeNames) {
            contentTypeFilterBuilder.addValue(ValueFactory.newString(contentTypeName.toString()));
        }
        builder.addQueryFilter(contentTypeFilterBuilder.build());
    }
}
Also used : ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ContentTypeNames(com.enonic.xp.schema.content.ContentTypeNames) ValueFilter(com.enonic.xp.query.filter.ValueFilter)

Example 8 with ContentTypeName

use of com.enonic.xp.schema.content.ContentTypeName in project xp by enonic.

the class UpdateContentCommand method doExecute.

private Content doExecute() {
    final Content contentBeforeChange = getContent(params.getContentId());
    Content editedContent = editContent(params.getEditor(), contentBeforeChange);
    if (params.stopInherit()) {
        if (editedContent.getInherit().contains(ContentInheritType.CONTENT)) {
            nodeService.commit(NodeCommitEntry.create().message("Base inherited version").build(), NodeIds.from(params.getContentId().toString()));
            editedContent.getInherit().remove(ContentInheritType.CONTENT);
        }
        editedContent.getInherit().remove(ContentInheritType.NAME);
    }
    final BinaryReferences removeAttachments = Objects.requireNonNullElseGet(params.getRemoveAttachments(), BinaryReferences::empty);
    if (contentBeforeChange.equals(editedContent) && params.getCreateAttachments() == null && removeAttachments.isEmpty() && !this.params.isClearAttachments()) {
        return contentBeforeChange;
    }
    editedContent = processContent(contentBeforeChange, editedContent);
    validateBlockingChecks(editedContent);
    final ValidationErrors.Builder validationErrorsBuilder = ValidationErrors.create();
    if (!params.isClearAttachments() && contentBeforeChange.getValidationErrors() != null) {
        contentBeforeChange.getValidationErrors().stream().filter(validationError -> validationError instanceof AttachmentValidationError).map(validationError -> (AttachmentValidationError) validationError).filter(validationError -> !removeAttachments.contains(validationError.getAttachment())).forEach(validationErrorsBuilder::add);
    }
    final ValidationErrors validationErrors = ValidateContentDataCommand.create().contentId(editedContent.getId()).data(editedContent.getData()).extraDatas(editedContent.getAllExtraData()).contentTypeName(editedContent.getType()).contentName(editedContent.getName()).displayName(editedContent.getDisplayName()).createAttachments(params.getCreateAttachments()).contentValidators(this.contentValidators).contentTypeService(this.contentTypeService).validationErrorsBuilder(validationErrorsBuilder).build().execute();
    if (params.isRequireValid()) {
        validationErrors.stream().findFirst().ifPresent(validationError -> {
            throw new ContentDataValidationException(validationError.getMessage());
        });
    }
    editedContent = Content.create(editedContent).valid(!validationErrors.hasErrors()).validationErrors(validationErrors).build();
    editedContent = attachThumbnail(editedContent);
    editedContent = setModifiedTime(editedContent);
    final UpdateContentTranslatorParams updateContentTranslatorParams = UpdateContentTranslatorParams.create().editedContent(editedContent).createAttachments(this.params.getCreateAttachments()).removeAttachments(this.params.getRemoveAttachments()).clearAttachments(this.params.isClearAttachments()).modifier(getCurrentUser().getKey()).build();
    final UpdateNodeParams updateNodeParams = UpdateNodeParamsFactory.create(updateContentTranslatorParams).contentTypeService(this.contentTypeService).xDataService(this.xDataService).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).siteService(this.siteService).build().produce();
    final Node editedNode = this.nodeService.update(updateNodeParams);
    return translator.fromNode(editedNode, true);
}
Also used : ContentDataValidationException(com.enonic.xp.content.ContentDataValidationException) BinaryReferences(com.enonic.xp.util.BinaryReferences) MediaInfo(com.enonic.xp.media.MediaInfo) Node(com.enonic.xp.node.Node) LoggerFactory(org.slf4j.LoggerFactory) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ValidationErrors(com.enonic.xp.content.ValidationErrors) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) ContentEditor(com.enonic.xp.content.ContentEditor) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) Thumbnail(com.enonic.xp.icon.Thumbnail) PartDescriptorService(com.enonic.xp.region.PartDescriptorService) Media(com.enonic.xp.content.Media) Logger(org.slf4j.Logger) ContentAccessException(com.enonic.xp.content.ContentAccessException) ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) ContentInheritType(com.enonic.xp.content.ContentInheritType) Content(com.enonic.xp.content.Content) ContentProcessor(com.enonic.xp.content.processor.ContentProcessor) InputTypes(com.enonic.xp.inputtype.InputTypes) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) Instant(java.time.Instant) ContentType(com.enonic.xp.schema.content.ContentType) AttachmentValidationError(com.enonic.xp.content.AttachmentValidationError) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Objects(java.util.Objects) EditableContent(com.enonic.xp.content.EditableContent) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) Site(com.enonic.xp.site.Site) InputValidator(com.enonic.xp.core.impl.content.validate.InputValidator) EditableSite(com.enonic.xp.content.EditableSite) NodeAccessException(com.enonic.xp.node.NodeAccessException) ContentDataSerializer(com.enonic.xp.core.impl.content.serializer.ContentDataSerializer) Preconditions(com.google.common.base.Preconditions) UpdateContentTranslatorParams(com.enonic.xp.content.UpdateContentTranslatorParams) NodeIds(com.enonic.xp.node.NodeIds) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) UpdateContentTranslatorParams(com.enonic.xp.content.UpdateContentTranslatorParams) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) ContentDataValidationException(com.enonic.xp.content.ContentDataValidationException) BinaryReferences(com.enonic.xp.util.BinaryReferences) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Node(com.enonic.xp.node.Node) AttachmentValidationError(com.enonic.xp.content.AttachmentValidationError)

Example 9 with ContentTypeName

use of com.enonic.xp.schema.content.ContentTypeName in project xp by enonic.

the class ApplicationRelativeResolverTest method toContentTypeName.

@Test
public void toContentTypeName() {
    final ApplicationRelativeResolver resolver = new ApplicationRelativeResolver(ApplicationKey.from("aaa"));
    ContentTypeName contentTypeName = resolver.toContentTypeName("bbb");
    assertEquals(contentTypeName.getLocalName(), "bbb");
    contentTypeName = resolver.toContentTypeName("ccc:ddd");
    assertEquals(contentTypeName.getLocalName(), "ddd");
}
Also used : ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) Test(org.junit.jupiter.api.Test)

Example 10 with ContentTypeName

use of com.enonic.xp.schema.content.ContentTypeName in project xp by enonic.

the class AbstractContentCommand method validateParentChildRelations.

protected void validateParentChildRelations(final ContentPath parentPath, final ContentTypeName typeName) {
    if (parentPath.isRoot()) {
        // root allows anything except page-template and template-folder.
        if (typeName.isPageTemplate() || typeName.isTemplateFolder()) {
            throw new IllegalArgumentException(String.format("A content with type '%s' cannot be a child of root", typeName));
        } else {
            return;
        }
    }
    final Content parent = GetContentByPathCommand.create(parentPath, this).build().execute();
    if (parent == null) {
        throw new IllegalStateException(String.format("Cannot read parent type with path %s", parentPath));
    }
    final ContentTypeName parentTypeName = parent.getType();
    if ((typeName.isTemplateFolder() && !parentTypeName.isSite()) || (typeName.isPageTemplate() && !parentTypeName.isTemplateFolder())) {
        throw new IllegalArgumentException(String.format("A content with type '%s' cannot be a child of '%s' with path %s", typeName, parentTypeName, parentPath));
    }
    final ContentType parentType = contentTypeService.getByName(GetContentTypeParams.from(parentTypeName));
    if (parentType == null) {
        LOG.debug("Bypass validation for unknown content type of parent with path {}", parentPath);
        return;
    }
    if (!parentType.allowChildContent()) {
        throw new IllegalArgumentException(String.format("Child content is not allowed in '%s' with path %s", parentTypeName, parentPath));
    }
    final boolean isAllowed = allowContentTypeFilter(parentTypeName.getApplicationKey(), parentType.getAllowChildContentType()).test(typeName);
    if (!isAllowed) {
        throw new IllegalArgumentException(String.format("A content with type '%s' cannot be a child of '%s' with path %s", typeName, parentTypeName, parentPath));
    }
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) Content(com.enonic.xp.content.Content) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName)

Aggregations

ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)11 Content (com.enonic.xp.content.Content)4 MediaInfo (com.enonic.xp.media.MediaInfo)4 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)3 Media (com.enonic.xp.content.Media)2 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)2 ContentType (com.enonic.xp.schema.content.ContentType)2 Test (org.junit.jupiter.api.Test)2 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)1 PublicApi (com.enonic.xp.annotation.PublicApi)1 ApplicationRelativeResolver (com.enonic.xp.app.ApplicationRelativeResolver)1 Attachment (com.enonic.xp.attachment.Attachment)1 AttachmentValidationError (com.enonic.xp.content.AttachmentValidationError)1 ContentAccessException (com.enonic.xp.content.ContentAccessException)1 ContentDataValidationException (com.enonic.xp.content.ContentDataValidationException)1 ContentDependencies (com.enonic.xp.content.ContentDependencies)1 ContentDependenciesAggregation (com.enonic.xp.content.ContentDependenciesAggregation)1 ContentEditor (com.enonic.xp.content.ContentEditor)1 ContentId (com.enonic.xp.content.ContentId)1 ContentIndexPath (com.enonic.xp.content.ContentIndexPath)1