Search in sources :

Example 1 with LocalTransform

use of org.alfresco.repo.content.transform.LocalTransform in project alfresco-repository by Alfresco.

the class LocalSynchronousTransformClient method isSupported.

@Override
public boolean isSupported(String sourceMimetype, long sourceSizeInBytes, String contentUrl, String targetMimetype, Map<String, String> actualOptions, String transformName, NodeRef sourceNodeRef) {
    String renditionName = TransformDefinition.convertToRenditionName(transformName);
    LocalTransform transform = localTransformServiceRegistry.getLocalTransform(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, renditionName);
    if (logger.isDebugEnabled()) {
        logger.debug(TRANSFORM + renditionName + " from " + sourceMimetype + (transform == null ? " is unsupported" : " is supported"));
    }
    return transform != null;
}
Also used : LocalTransform(org.alfresco.repo.content.transform.LocalTransform)

Example 2 with LocalTransform

use of org.alfresco.repo.content.transform.LocalTransform in project alfresco-repository by Alfresco.

the class LocalSynchronousTransformClient method transform.

@Override
public void transform(ContentReader reader, ContentWriter writer, Map<String, String> actualOptions, String transformName, NodeRef sourceNodeRef) {
    String renditionName = TransformDefinition.convertToRenditionName(transformName);
    try {
        if (reader == null) {
            throw new IllegalArgumentException("The content reader must be set");
        }
        if (!reader.exists()) {
            throw new IllegalArgumentException("sourceNodeRef " + sourceNodeRef + " has no content.");
        }
        String sourceMimetype = reader.getMimetype();
        long sourceSizeInBytes = reader.getSize();
        if (sourceMimetype == null) {
            throw new IllegalArgumentException("The content reader mimetype must be set");
        }
        String targetMimetype = writer.getMimetype();
        if (targetMimetype == null) {
            throw new IllegalArgumentException("The content writer mimetype must be set");
        }
        LocalTransform transform = localTransformServiceRegistry.getLocalTransform(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, renditionName);
        if (transform == null) {
            throw new UnsupportedTransformationException("Transformation of " + sourceMimetype + (sourceSizeInBytes > 0 ? " size " + sourceSizeInBytes : "") + " to " + targetMimetype + " unsupported");
        }
        if (logger.isDebugEnabled()) {
            logger.debug(TRANSFORM + " requested " + renditionName);
        }
        transform.transform(reader, writer, actualOptions, renditionName, sourceNodeRef);
        if (logger.isDebugEnabled()) {
            logger.debug(TRANSFORM + " created " + renditionName);
        }
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug(TRANSFORM + " failed " + renditionName, e);
        }
        throw e;
    }
}
Also used : UnsupportedTransformationException(org.alfresco.repo.content.transform.UnsupportedTransformationException) UnsupportedTransformationException(org.alfresco.repo.content.transform.UnsupportedTransformationException) LocalTransform(org.alfresco.repo.content.transform.LocalTransform)

Example 3 with LocalTransform

use of org.alfresco.repo.content.transform.LocalTransform in project alfresco-repository by Alfresco.

the class LocalTransformClient method checkSupported.

@Override
public void checkSupported(NodeRef sourceNodeRef, RenditionDefinition2 renditionDefinition, String sourceMimetype, long sourceSizeInBytes, String contentUrl) {
    String targetMimetype = renditionDefinition.getTargetMimetype();
    String renditionName = renditionDefinition.getRenditionName();
    Map<String, String> actualOptions = renditionDefinition.getTransformOptions();
    LocalTransform localTransform = localTransformServiceRegistry.getLocalTransform(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, renditionName);
    transform.set(localTransform);
    String message = TRANSFORM + renditionName + " from " + sourceMimetype + (localTransform == null ? " is unsupported" : " is supported");
    logger.debug(message);
    if (localTransform == null) {
        throw new UnsupportedOperationException(message);
    }
}
Also used : LocalTransform(org.alfresco.repo.content.transform.LocalTransform)

Example 4 with LocalTransform

use of org.alfresco.repo.content.transform.LocalTransform in project alfresco-repository by Alfresco.

the class ContentTransformServiceAdaptor method wrapLocalTransformer.

private ContentTransformer wrapLocalTransformer(String sourceUrl, String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions transformationOptions) {
    AbstractContentTransformer2 transformer = null;
    Map<String, String> options = converter.getOptions(transformationOptions, null, null);
    LocalTransform localTransform = localTransformServiceRegistryImpl.getLocalTransform(sourceMimetype, sourceSize, targetMimetype, options, null);
    if (localTransform != null) {
        transformer = new AbstractContentTransformer2() {

            @Override
            public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options) throws ContentIOException {
                try {
                    transformInternal(reader, writer, transformationOptions);
                } catch (Exception e) {
                    throw new ContentIOException(e.getMessage(), e);
                }
            }

            @Override
            protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions transformationOptions) throws Exception {
                localTransform.transform(reader, writer, options, null, null);
            }

            @Override
            public void register() {
            }

            @Override
            public boolean isSupportedTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options) {
                return true;
            }

            @Override
            public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options) {
                return true;
            }

            @Override
            public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options) {
                return true;
            }

            @Override
            public boolean isTransformableSize(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options) {
                return true;
            }

            @Override
            public String getName() {
                return "Wrapped<" + localTransformServiceRegistryImpl.findTransformerName(sourceMimetype, sourceSize, targetMimetype, options, null) + ">";
            }
        };
    }
    return transformer;
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) AbstractContentTransformer2(org.alfresco.repo.content.transform.AbstractContentTransformer2) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) UnsupportedTransformationException(org.alfresco.repo.content.transform.UnsupportedTransformationException) NoTransformerException(org.alfresco.service.cmr.repository.NoTransformerException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) LocalTransform(org.alfresco.repo.content.transform.LocalTransform) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Example 5 with LocalTransform

use of org.alfresco.repo.content.transform.LocalTransform in project alfresco-repository by Alfresco.

the class LocalTransformClient method transform.

@Override
public void transform(NodeRef sourceNodeRef, RenditionDefinition2 renditionDefinition, String user, int sourceContentHashCode) {
    String renditionName = renditionDefinition.getRenditionName();
    String targetMimetype = renditionDefinition.getTargetMimetype();
    Map<String, String> actualOptions = renditionDefinition.getTransformOptions();
    LocalTransform localTransform = transform.get();
    executorService.submit(() -> {
        AuthenticationUtil.runAs((AuthenticationUtil.RunAsWork<Void>) () -> transactionService.getRetryingTransactionHelper().doInTransaction(() -> {
            try {
                if (localTransform == null) {
                    throw new IllegalStateException("isSupported was not called prior to an asynchronous transform.");
                }
                ContentReader reader = contentService.getReader(sourceNodeRef, ContentModel.PROP_CONTENT);
                if (null == reader || !reader.exists()) {
                    throw new IllegalArgumentException("sourceNodeRef " + sourceNodeRef + " has no content.");
                }
                if (logger.isDebugEnabled()) {
                    logger.debug(TRANSFORM + "requested " + renditionName);
                }
                ContentWriter writer = contentService.getTempWriter();
                writer.setMimetype(targetMimetype);
                localTransform.transform(reader, writer, actualOptions, renditionName, sourceNodeRef);
                InputStream inputStream = writer.getReader().getContentInputStream();
                if (logger.isDebugEnabled()) {
                    logger.debug(TRANSFORM + "to be consumed " + renditionName);
                }
                renditionService2.consume(sourceNodeRef, inputStream, renditionDefinition, sourceContentHashCode);
                if (logger.isDebugEnabled()) {
                    logger.debug(TRANSFORM + "consumed " + renditionName);
                }
            } catch (Exception e) {
                if (logger.isDebugEnabled()) {
                    logger.debug(TRANSFORM + "failed " + renditionName, e);
                }
                if (renditionDefinition instanceof TransformDefinition) {
                    ((TransformDefinition) renditionDefinition).setErrorMessage(e.getMessage());
                }
                renditionService2.failure(sourceNodeRef, renditionDefinition, sourceContentHashCode);
                throw e;
            }
            return null;
        }), user);
    });
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) InputStream(java.io.InputStream) ContentReader(org.alfresco.service.cmr.repository.ContentReader) LocalTransform(org.alfresco.repo.content.transform.LocalTransform)

Aggregations

LocalTransform (org.alfresco.repo.content.transform.LocalTransform)5 UnsupportedTransformationException (org.alfresco.repo.content.transform.UnsupportedTransformationException)2 ContentReader (org.alfresco.service.cmr.repository.ContentReader)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 InputStream (java.io.InputStream)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 AbstractContentTransformer2 (org.alfresco.repo.content.transform.AbstractContentTransformer2)1 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)1 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)1 NoTransformerException (org.alfresco.service.cmr.repository.NoTransformerException)1 TransformationOptions (org.alfresco.service.cmr.repository.TransformationOptions)1