Search in sources :

Example 21 with TransformationOptions

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

the class RenditionsTest method isOpenOfficeAvailable.

/**
 * Returns <code>true</code> if OpenOffice-based transformations are currently known to
 * be available, else <code>false</code>.
 */
protected boolean isOpenOfficeAvailable() {
    ContentTransformer transformer = contentService.getTransformer(null, MimetypeMap.MIMETYPE_WORD, -1, MimetypeMap.MIMETYPE_PDF, new TransformationOptions());
    // A transformer may not be returned here if it is unavailable.
    if (transformer == null) {
        return false;
    }
    // Maybe it's non-null, but not available.
    boolean isTransformable = transformer.isTransformable(MimetypeMap.MIMETYPE_WORD, -1, MimetypeMap.MIMETYPE_PDF, null);
    return isTransformable;
}
Also used : ContentTransformer(org.alfresco.repo.content.transform.ContentTransformer) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Example 22 with TransformationOptions

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

the class ContentTransformServiceAdaptor method transform.

@Deprecated
@Override
public void transform(ContentReader reader, ContentWriter writer, Map<String, Object> legacyOptionsMap) throws NoTransformerException, ContentIOException {
    TransformationOptions transformationOptions = new TransformationOptions(legacyOptionsMap);
    Map<String, String> options = converter.getOptions(transformationOptions, null, null);
    synchronousTransformClient.transform(reader, writer, options, null, null);
}
Also used : TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Example 23 with TransformationOptions

use of org.alfresco.service.cmr.repository.TransformationOptions 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 24 with TransformationOptions

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

the class TransformationOptionsConverter method getTransformationOptions.

/**
 * @deprecated as we do not plan to use TransformationOptions moving forwards as local transformations will also
 * use the same options as the Transform Service.
 */
@Deprecated
TransformationOptions getTransformationOptions(String renditionName, Map<String, String> options) {
    TransformationOptions transformationOptions = null;
    Set<String> optionNames = options.keySet();
    // The "pdf" rendition is special as it was incorrectly set up as an SWFTransformationOptions in 6.0
    // It should have been simply a TransformationOptions.
    boolean isPdfRendition = "pdf".equals(renditionName);
    Set<String> subclassOptionNames = new HashSet<>(optionNames);
    subclassOptionNames.removeAll(LIMIT_OPTIONS);
    subclassOptionNames.remove(INCLUDE_CONTENTS);
    boolean hasOptions = !subclassOptionNames.isEmpty();
    if (isPdfRendition || hasOptions) {
        // The "pdf" rendition used the wrong TransformationOptions subclass.
        if (isPdfRendition || FLASH_OPTIONS.containsAll(subclassOptionNames)) {
            SWFTransformationOptions opts = new SWFTransformationOptions();
            transformationOptions = opts;
            opts.setFlashVersion(isPdfRendition ? "9" : options.get(FLASH_VERSION));
        } else // that use ImageTransformOptions to specify width, height etc.
        if (IMAGE_OPTIONS.containsAll(subclassOptionNames) || PDF_OPTIONS.containsAll(subclassOptionNames)) {
            ImageTransformationOptions opts = new ImageTransformationOptions();
            transformationOptions = opts;
            if (containsAny(subclassOptionNames, RESIZE_OPTIONS)) {
                ImageResizeOptions imageResizeOptions = new ImageResizeOptions();
                opts.setResizeOptions(imageResizeOptions);
                // PDF
                ifSet(options, WIDTH, (v) -> imageResizeOptions.setWidth(Integer.parseInt(v)));
                ifSet(options, HEIGHT, (v) -> imageResizeOptions.setHeight(Integer.parseInt(v)));
                // ImageMagick
                ifSet(options, RESIZE_WIDTH, (v) -> imageResizeOptions.setWidth(Integer.parseInt(v)));
                ifSet(options, RESIZE_HEIGHT, (v) -> imageResizeOptions.setHeight(Integer.parseInt(v)));
                ifSet(options, THUMBNAIL, (v) -> imageResizeOptions.setResizeToThumbnail(Boolean.parseBoolean(v)));
                ifSet(options, RESIZE_PERCENTAGE, (v) -> imageResizeOptions.setPercentResize(Boolean.parseBoolean(v)));
                set(options, ALLOW_ENLARGEMENT, (v) -> imageResizeOptions.setAllowEnlargement(Boolean.parseBoolean(v == null ? "true" : v)));
                set(options, MAINTAIN_ASPECT_RATIO, (v) -> imageResizeOptions.setMaintainAspectRatio(Boolean.parseBoolean(v == null ? "true" : v)));
            }
            // ALPHA_REMOVE can be ignored as it is automatically added in the legacy code if the sourceMimetype is jpeg
            set(options, AUTO_ORIENT, (v) -> opts.setAutoOrient(Boolean.parseBoolean(v == null ? "true" : v)));
            boolean containsPaged = containsAny(subclassOptionNames, PAGED_OPTIONS);
            boolean containsCrop = containsAny(subclassOptionNames, CROP_OPTIONS);
            boolean containsTemporal = containsAny(subclassOptionNames, TEMPORAL_OPTIONS);
            if (containsPaged || containsCrop || containsTemporal) {
                List<TransformationSourceOptions> sourceOptionsList = new ArrayList<>();
                if (containsPaged) {
                    // The legacy transformer options start at page 1, where as image magick and the local
                    // transforms start at 0;
                    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
                    sourceOptionsList.add(pagedSourceOptions);
                    ifSet(options, START_PAGE, (v) -> pagedSourceOptions.setStartPageNumber(Integer.parseInt(v) + 1));
                    ifSet(options, END_PAGE, (v) -> pagedSourceOptions.setEndPageNumber(Integer.parseInt(v) + 1));
                    ifSet(options, PAGE, (v) -> {
                        int i = Integer.parseInt(v) + 1;
                        pagedSourceOptions.setStartPageNumber(i);
                        pagedSourceOptions.setEndPageNumber(i);
                    });
                }
                if (containsCrop) {
                    CropSourceOptions cropSourceOptions = new CropSourceOptions();
                    sourceOptionsList.add(cropSourceOptions);
                    ifSet(options, CROP_GRAVITY, (v) -> cropSourceOptions.setGravity(v));
                    ifSet(options, CROP_PERCENTAGE, (v) -> cropSourceOptions.setPercentageCrop(Boolean.parseBoolean(v)));
                    ifSet(options, CROP_WIDTH, (v) -> cropSourceOptions.setWidth(Integer.parseInt(v)));
                    ifSet(options, CROP_HEIGHT, (v) -> cropSourceOptions.setHeight(Integer.parseInt(v)));
                    ifSet(options, CROP_X_OFFSET, (v) -> cropSourceOptions.setXOffset(Integer.parseInt(v)));
                    ifSet(options, CROP_Y_OFFSET, (v) -> cropSourceOptions.setYOffset(Integer.parseInt(v)));
                }
                if (containsTemporal) {
                    TemporalSourceOptions temporalSourceOptions = new TemporalSourceOptions();
                    sourceOptionsList.add(temporalSourceOptions);
                    ifSet(options, DURATION, (v) -> temporalSourceOptions.setDuration(v));
                    ifSet(options, OFFSET, (v) -> temporalSourceOptions.setOffset(v));
                }
                opts.setSourceOptionsList(sourceOptionsList);
            }
        }
    } else {
        // This what the "pdf" rendition should have used in 6.0 and it is not unreasonable for a custom transformer
        // and rendition to do the same.
        transformationOptions = new TransformationOptions();
    }
    if (transformationOptions == null) {
        StringJoiner sj = new StringJoiner("\n    ");
        sj.add("The RenditionDefinition2 " + renditionName + " contains options that cannot be mapped to TransformationOptions used by local transformers. " + " The TransformOptionConverter may need to be sub classed to support this conversion.");
        HashSet<String> otherNames = new HashSet<>(optionNames);
        otherNames.removeAll(FLASH_OPTIONS);
        otherNames.removeAll(IMAGE_OPTIONS);
        otherNames.removeAll(PDF_OPTIONS);
        otherNames.removeAll(LIMIT_OPTIONS);
        otherNames.forEach(sj::add);
        sj.add("---");
        optionNames.forEach(sj::add);
        throw new IllegalArgumentException(sj.toString());
    }
    final TransformationOptions opts = transformationOptions;
    ifSet(options, INCLUDE_CONTENTS, (v) -> opts.setIncludeEmbedded(Boolean.parseBoolean(v)));
    if (containsAny(optionNames, LIMIT_OPTIONS)) {
        TransformationOptionLimits limits = new TransformationOptionLimits();
        transformationOptions.setLimits(limits);
        ifSet(options, TIMEOUT, (v) -> limits.setTimeoutMs(Long.parseLong(v)));
        limits.setMaxSourceSizeKBytes(maxSourceSizeKBytes);
        limits.setReadLimitKBytes(readLimitTimeMs);
        limits.setReadLimitTimeMs(readLimitKBytes);
        limits.setMaxPages(maxPages);
        limits.setPageLimit(pageLimit);
    }
    transformationOptions.setUse(renditionName);
    return transformationOptions;
}
Also used : Arrays(java.util.Arrays) MAINTAIN_PDF_ASPECT_RATIO(org.alfresco.repo.rendition2.RenditionDefinition2.MAINTAIN_PDF_ASPECT_RATIO) RESIZE_HEIGHT(org.alfresco.repo.rendition2.RenditionDefinition2.RESIZE_HEIGHT) END_PAGE(org.alfresco.repo.rendition2.RenditionDefinition2.END_PAGE) TIMEOUT(org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT) MAINTAIN_ASPECT_RATIO(org.alfresco.repo.rendition2.RenditionDefinition2.MAINTAIN_ASPECT_RATIO) Map(java.util.Map) AUTO_ORIENT(org.alfresco.repo.rendition2.RenditionDefinition2.AUTO_ORIENT) START_PAGE(org.alfresco.repo.rendition2.RenditionDefinition2.START_PAGE) CROP_WIDTH(org.alfresco.repo.rendition2.RenditionDefinition2.CROP_WIDTH) DURATION(org.alfresco.repo.rendition2.RenditionDefinition2.DURATION) TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) Collection(java.util.Collection) MimetypeMap(org.alfresco.repo.content.MimetypeMap) Set(java.util.Set) CROP_GRAVITY(org.alfresco.repo.rendition2.RenditionDefinition2.CROP_GRAVITY) TransformationSourceOptions(org.alfresco.service.cmr.repository.TransformationSourceOptions) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions) CROP_HEIGHT(org.alfresco.repo.rendition2.RenditionDefinition2.CROP_HEIGHT) List(java.util.List) INCLUDE_CONTENTS(org.alfresco.repo.rendition2.RenditionDefinition2.INCLUDE_CONTENTS) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) LogFactory(org.apache.commons.logging.LogFactory) ALPHA_REMOVE(org.alfresco.repo.rendition2.RenditionDefinition2.ALPHA_REMOVE) ALLOW_PDF_ENLARGEMENT(org.alfresco.repo.rendition2.RenditionDefinition2.ALLOW_PDF_ENLARGEMENT) RESIZE_PERCENTAGE(org.alfresco.repo.rendition2.RenditionDefinition2.RESIZE_PERCENTAGE) CropSourceOptions(org.alfresco.service.cmr.repository.CropSourceOptions) THUMBNAIL(org.alfresco.repo.rendition2.RenditionDefinition2.THUMBNAIL) CROP_X_OFFSET(org.alfresco.repo.rendition2.RenditionDefinition2.CROP_X_OFFSET) CROP_Y_OFFSET(org.alfresco.repo.rendition2.RenditionDefinition2.CROP_Y_OFFSET) RuntimeExecutableContentTransformerOptions(org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerOptions) HashMap(java.util.HashMap) MIMETYPE_PDF(org.alfresco.repo.content.MimetypeMap.MIMETYPE_PDF) CROP_PERCENTAGE(org.alfresco.repo.rendition2.RenditionDefinition2.CROP_PERCENTAGE) WIDTH(org.alfresco.repo.rendition2.RenditionDefinition2.WIDTH) SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) CollectionUtils.containsAny(org.springframework.util.CollectionUtils.containsAny) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) InitializingBean(org.springframework.beans.factory.InitializingBean) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) RESIZE_WIDTH(org.alfresco.repo.rendition2.RenditionDefinition2.RESIZE_WIDTH) OFFSET(org.alfresco.repo.rendition2.RenditionDefinition2.OFFSET) FLASH_VERSION(org.alfresco.repo.rendition2.RenditionDefinition2.FLASH_VERSION) ALLOW_ENLARGEMENT(org.alfresco.repo.rendition2.RenditionDefinition2.ALLOW_ENLARGEMENT) PAGE(org.alfresco.repo.rendition2.RenditionDefinition2.PAGE) HEIGHT(org.alfresco.repo.rendition2.RenditionDefinition2.HEIGHT) MAX_SOURCE_SIZE_K_BYTES(org.alfresco.repo.rendition2.RenditionDefinition2.MAX_SOURCE_SIZE_K_BYTES) StringJoiner(java.util.StringJoiner) PropertyCheck(org.alfresco.util.PropertyCheck) TemporalSourceOptions(org.alfresco.service.cmr.repository.TemporalSourceOptions) Log(org.apache.commons.logging.Log) TemporalSourceOptions(org.alfresco.service.cmr.repository.TemporalSourceOptions) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) CropSourceOptions(org.alfresco.service.cmr.repository.CropSourceOptions) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions) SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) List(java.util.List) ArrayList(java.util.ArrayList) StringJoiner(java.util.StringJoiner) HashSet(java.util.HashSet)

Example 25 with TransformationOptions

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

the class ThumbnailRegistry method isThumbnailDefinitionAvailable.

/**
 * Checks to see if at this moment in time, the specified {@link ThumbnailDefinition}
 *  is able to thumbnail the source mimetype. Typically used with Thumbnail Definitions
 *  retrieved by name, and/or when dealing with transient {@link ContentTransformer}s.
 * @param sourceUrl The URL of the source (optional)
 * @param sourceMimetype The source mimetype
 * @param sourceSize the size (in bytes) of the source. Use -1 if unknown.
 * @param sourceNodeRef which is set in a copy of the thumbnailDefinition transformation options,
 *        so that it may be used by transformers and debug.
 * @param thumbnailDefinition The {@link ThumbnailDefinition} to check for
 */
public boolean isThumbnailDefinitionAvailable(String sourceUrl, String sourceMimetype, long sourceSize, NodeRef sourceNodeRef, ThumbnailDefinition thumbnailDefinition) {
    // Use RenditionService2 if it knows about the definition, otherwise use localTransformServiceRegistry.
    // Needed as disabling local transforms should not disable thumbnails if they can be done remotely.
    boolean supported = false;
    String targetMimetype = thumbnailDefinition.getMimetype();
    RenditionDefinition2 renditionDefinition = getEquivalentRenditionDefinition2(thumbnailDefinition);
    if (renditionDefinition != null) {
        Map<String, String> options = renditionDefinition.getTransformOptions();
        String renditionName = renditionDefinition.getRenditionName();
        supported = transformServiceRegistry.isSupported(sourceMimetype, sourceSize, targetMimetype, options, renditionName);
    } else {
        boolean orig = TransformerDebug.setDebugOutput(false);
        try {
            TransformationOptions transformationOptions = thumbnailDefinition.getTransformationOptions();
            String renditionName = thumbnailDefinition.getName();
            Map<String, String> options = converter.getOptions(transformationOptions, sourceMimetype, targetMimetype);
            supported = localTransformServiceRegistry.isSupported(sourceMimetype, sourceSize, targetMimetype, options, renditionName);
        } finally {
            TransformerDebug.setDebugOutput(orig);
        }
    }
    return supported;
}
Also used : RenditionDefinition2(org.alfresco.repo.rendition2.RenditionDefinition2) 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