Search in sources :

Example 1 with ContentTypeName

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

the class XmlRelationshipTypeParser method parseTypes.

private List<ContentTypeName> parseTypes(final DomElement root, final String name) {
    final DomElement types = root.getChild(name);
    if (types == null) {
        return Collections.emptyList();
    }
    final ApplicationRelativeResolver resolver = new ApplicationRelativeResolver(this.currentApplication);
    return types.getChildren("content-type").stream().map(child -> resolver.toContentTypeName(child.getValue().trim())).collect(Collectors.toList());
}
Also used : PublicApi(com.enonic.xp.annotation.PublicApi) List(java.util.List) RelationshipType(com.enonic.xp.schema.relationship.RelationshipType) ApplicationRelativeResolver(com.enonic.xp.app.ApplicationRelativeResolver) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) DomElement(com.enonic.xp.xml.DomElement) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) DomElement(com.enonic.xp.xml.DomElement) ApplicationRelativeResolver(com.enonic.xp.app.ApplicationRelativeResolver)

Example 2 with ContentTypeName

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

the class ContentDependenciesResolver method resolveOutboundDependenciesAggregation.

private Collection<ContentDependenciesAggregation> resolveOutboundDependenciesAggregation(final ContentId contentId) {
    final Map<ContentTypeName, Long> aggregationJsonMap = new HashMap<>();
    final Contents contents = this.contentService.getByIds(new GetContentByIdsParams(this.contentService.getOutboundDependencies(contentId)));
    contents.forEach(existingContent -> {
        final ContentTypeName contentTypeName = existingContent.getType();
        final Long count = aggregationJsonMap.containsKey(contentTypeName) ? aggregationJsonMap.get(contentTypeName) + 1 : 1;
        aggregationJsonMap.put(contentTypeName, count);
    });
    return aggregationJsonMap.entrySet().stream().map(entry -> new ContentDependenciesAggregation(entry.getKey(), entry.getValue())).collect(toList());
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) ContentService(com.enonic.xp.content.ContentService) ContentIndexPath(com.enonic.xp.content.ContentIndexPath) FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) Collection(java.util.Collection) HashMap(java.util.HashMap) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) HashSet(java.util.HashSet) ContentQuery(com.enonic.xp.content.ContentQuery) ContentId(com.enonic.xp.content.ContentId) Collectors.toList(java.util.stream.Collectors.toList) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Contents(com.enonic.xp.content.Contents) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) TermsAggregationQuery(com.enonic.xp.query.aggregation.TermsAggregationQuery) Map(java.util.Map) ContentDependencies(com.enonic.xp.content.ContentDependencies) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) Contents(com.enonic.xp.content.Contents) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) HashMap(java.util.HashMap) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName)

Example 3 with ContentTypeName

use of com.enonic.xp.schema.content.ContentTypeName 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)

Example 4 with ContentTypeName

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

the class UpdateMediaCommand 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 Content existingContent = getContent(params.getContent());
    Preconditions.checkArgument(existingContent.getType().equals(type), "Updated content must be of type: " + existingContent.getType());
    final CreateAttachment mediaAttachment = CreateAttachment.create().name(params.getName()).mimeType(params.getMimeType()).label("source").byteSource(params.getByteSource()).text(type.isTextualMedia() ? mediaInfo.getTextContent() : null).build();
    final MediaFormDataBuilder mediaFormBuilder = 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());
    final UpdateContentParams updateParams = new UpdateContentParams().contentId(params.getContent()).clearAttachments(true).createAttachments(CreateAttachments.from(mediaAttachment)).editor(editable -> mediaFormBuilder.build(editable.data));
    return UpdateContentCommand.create(this).params(updateParams).mediaInfo(mediaInfo).contentTypeService(this.contentTypeService).siteService(this.siteService).xDataService(this.xDataService).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).build().execute();
}
Also used : MediaInfo(com.enonic.xp.media.MediaInfo) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName)

Example 5 with ContentTypeName

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

the class UpdatedEventSyncCommand method doSyncMedia.

private void doSyncMedia(final ContentToSync content, final UpdateContentParams updateParams) {
    if (content.getSourceContent() instanceof Media) {
        final Media sourceMedia = (Media) content.getSourceContent();
        final Attachment mediaAttachment = sourceMedia.getMediaAttachment();
        final ByteSource sourceBinary = content.getSourceContext().callWith(() -> contentService.getBinary(sourceMedia.getId(), mediaAttachment.getBinaryReference()));
        final MediaInfo mediaInfo = content.getSourceContext().callWith(() -> mediaInfoService.parseMediaInfo(sourceBinary));
        final ContentTypeName type = ContentTypeFromMimeTypeResolver.resolve(mediaAttachment.getMimeType());
        final CreateAttachment createAttachment = CreateAttachment.create().name(mediaAttachment.getName()).mimeType(mediaAttachment.getMimeType()).label("source").byteSource(sourceBinary).text(type != null && type.isTextualMedia() ? mediaInfo.getTextContent() : null).build();
        updateParams.clearAttachments(true).createAttachments(CreateAttachments.from(createAttachment));
    }
}
Also used : MediaInfo(com.enonic.xp.media.MediaInfo) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) Media(com.enonic.xp.content.Media) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ByteSource(com.google.common.io.ByteSource) Attachment(com.enonic.xp.attachment.Attachment) CreateAttachment(com.enonic.xp.attachment.CreateAttachment)

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