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());
}
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());
}
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();
}
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();
}
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));
}
}
Aggregations