Search in sources :

Example 16 with TransformationOptions

use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.

the class LegacySynchronousTransformClient 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);
    TransformationOptions transformationOptions = converter.getTransformationOptions(renditionName, actualOptions);
    transformationOptions.setSourceNodeRef(sourceNodeRef);
    ContentTransformer legacyTransform = getTransformer(contentUrl, sourceMimetype, sourceSizeInBytes, targetMimetype, transformationOptions);
    if (logger.isDebugEnabled()) {
        logger.debug(TRANSFORM + renditionName + " from " + sourceMimetype + (legacyTransform == null ? " is unsupported" : " is supported"));
    }
    return legacyTransform != null;
}
Also used : ContentTransformer(org.alfresco.repo.content.transform.ContentTransformer) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Example 17 with TransformationOptions

use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.

the class LegacySynchronousTransformClient method transform.

@Override
public void transform(ContentReader reader, ContentWriter writer, Map<String, String> actualOptions, String transformName, NodeRef sourceNodeRef) {
    String renditionName = TransformDefinition.convertToRenditionName(transformName);
    try {
        TransformationOptions options = converter.getTransformationOptions(renditionName, actualOptions);
        options.setSourceNodeRef(sourceNodeRef);
        if (null == reader || !reader.exists()) {
            throw new IllegalArgumentException("sourceNodeRef " + sourceNodeRef + " has no content.");
        }
        if (logger.isDebugEnabled()) {
            logger.debug(TRANSFORM + "requested " + renditionName);
        }
        // We don't obtain the Legacy transformer and then call its transform method as they unlike Local and
        // Transform Service transforms automatically fail over to the next highest priority. This was not done
        // for the newer transforms, as a fail over can always be defined and that makes it simpler to understand
        // what is going on.
        transform(reader, writer, options);
        if (logger.isDebugEnabled()) {
            logger.debug(TRANSFORM + "created " + renditionName);
        }
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug(TRANSFORM + "failed " + renditionName, e);
        }
        throw e;
    }
}
Also used : TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Example 18 with TransformationOptions

use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.

the class LegacyTransformServiceRegistry method findTransformerName.

@Override
public String findTransformerName(String sourceMimetype, long sourceSizeInBytes, String targetMimetype, Map<String, String> actualOptions, String renditionName) {
    String name = null;
    try {
        TransformationOptions transformationOptions = converter.getTransformationOptions(renditionName, actualOptions);
        List<ContentTransformer> transformers = legacySynchronousTransformClient.getActiveTransformers(sourceMimetype, sourceSizeInBytes, targetMimetype, transformationOptions);
        if (!transformers.isEmpty()) {
            name = legacySynchronousTransformClient.getName() + ":" + transformers.get(0).getName();
        }
    } catch (IllegalArgumentException ignore) {
    // Typically if the mimetype is invalid.
    }
    return name;
}
Also used : ContentTransformer(org.alfresco.repo.content.transform.ContentTransformer) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Example 19 with TransformationOptions

use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.

the class LegacyTransformServiceRegistry method findMaxSize.

@Override
public long findMaxSize(String sourceMimetype, String targetMimetype, Map<String, String> options, String renditionName) {
    // This message is not logged if placed in afterPropertiesSet
    if (firstTime) {
        firstTime = false;
        transformerDebug.debug("Legacy transforms are " + (enabled ? "enabled" : "disabled"));
    }
    long maxSize = 0;
    if (enabled) {
        try {
            TransformationOptions transformationOptions = converter.getTransformationOptions(renditionName, options);
            maxSize = legacySynchronousTransformClient.getMaxSourceSizeBytes(sourceMimetype, targetMimetype, transformationOptions);
        } catch (IllegalArgumentException ignore) {
        // Typically if the mimetype is invalid.
        }
    }
    return maxSize;
}
Also used : TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Example 20 with TransformationOptions

use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.

the class ImageMagickContentTransformerTest method testReliability.

public void testReliability() throws Exception {
    if (!this.transformer.getWorker().isAvailable()) {
        return;
    }
    boolean reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_IMAGE_GIF, -1, MimetypeMap.MIMETYPE_TEXT_PLAIN, new TransformationOptions());
    assertEquals("Mimetype should not be supported", false, reliability);
    reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_IMAGE_GIF, -1, MimetypeMap.MIMETYPE_IMAGE_JPEG, new TransformationOptions());
    assertEquals("Mimetype should be supported", true, reliability);
}
Also used : TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Aggregations

TransformationOptions (org.alfresco.service.cmr.repository.TransformationOptions)44 ContentReader (org.alfresco.service.cmr.repository.ContentReader)10 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)8 ImageTransformationOptions (org.alfresco.repo.content.transform.magick.ImageTransformationOptions)6 SWFTransformationOptions (org.alfresco.repo.content.transform.swf.SWFTransformationOptions)6 ContentTransformer (org.alfresco.repo.content.transform.ContentTransformer)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Serializable (java.io.Serializable)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 FileContentReader (org.alfresco.repo.content.filestore.FileContentReader)3 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 TransformationOptionLimits (org.alfresco.service.cmr.repository.TransformationOptionLimits)3 QName (org.alfresco.service.namespace.QName)3 HashMap (java.util.HashMap)2 StringJoiner (java.util.StringJoiner)2 ExecutionException (java.util.concurrent.ExecutionException)2 FileContentWriter (org.alfresco.repo.content.filestore.FileContentWriter)2 ImageResizeOptions (org.alfresco.repo.content.transform.magick.ImageResizeOptions)2