Search in sources :

Example 1 with TransformationOptionLimits

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

the class ThumbnailRenditionConvertor method convert.

public ThumbnailDefinition convert(RenditionDefinition renditionDefinition) {
    ThumbnailDefinition thDefn = new ThumbnailDefinition();
    Map<String, Serializable> params = renditionDefinition.getParameterValues();
    // parameters common to all the built-in thumbnail definitions
    Serializable mimeTypeParam = params.get(AbstractRenderingEngine.PARAM_MIME_TYPE);
    thDefn.setMimetype((String) mimeTypeParam);
    thDefn.setName(renditionDefinition.getRenditionName().getLocalName());
    Serializable placeHolderResourcePathParam = params.get(AbstractRenderingEngine.PARAM_PLACEHOLDER_RESOURCE_PATH);
    if (placeHolderResourcePathParam != null) {
        thDefn.setPlaceHolderResourcePath((String) placeHolderResourcePathParam);
    }
    TransformationOptions transformationOptions = null;
    Serializable flashVersion = renditionDefinition.getParameterValue(ReformatRenderingEngine.PARAM_FLASH_VERSION);
    if (flashVersion != null) {
        // Thumbnails based on SWFTransformationOptions
        transformationOptions = new SWFTransformationOptions();
        SWFTransformationOptions swfTranOpts = (SWFTransformationOptions) transformationOptions;
        swfTranOpts.setFlashVersion((String) flashVersion);
    } else {
        // Thumbnails based on ImageTransformationOptions
        transformationOptions = new ImageTransformationOptions();
        ImageTransformationOptions imgTrOpts = (ImageTransformationOptions) transformationOptions;
        ImageResizeOptions resizeOptions = new ImageResizeOptions();
        Serializable xsize = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_RESIZE_WIDTH);
        if (xsize != null) {
            resizeOptions.setWidth(((Integer) xsize).intValue());
        }
        Serializable ysize = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_RESIZE_HEIGHT);
        if (ysize != null) {
            resizeOptions.setHeight(((Integer) ysize).intValue());
        }
        Serializable maintainAspectRatio = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO);
        if (maintainAspectRatio != null) {
            resizeOptions.setMaintainAspectRatio((Boolean) maintainAspectRatio);
        }
        Serializable resizeToThumbnail = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL);
        if (resizeToThumbnail != null) {
            resizeOptions.setResizeToThumbnail((Boolean) resizeToThumbnail);
        }
        Serializable allowEnlargement = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT);
        if (allowEnlargement != null) {
            resizeOptions.setAllowEnlargement((Boolean) allowEnlargement);
        }
        imgTrOpts.setResizeOptions(resizeOptions);
    }
    thDefn.setTransformationOptions(transformationOptions);
    TransformationOptionLimits limits = transformationOptions.getLimits();
    Serializable v = params.get(OPT_TIMEOUT_MS);
    if (v != null) {
        limits.setTimeoutMs((Long) v);
    }
    v = params.get(OPT_READ_LIMIT_TIME_MS);
    if (v != null) {
        limits.setReadLimitTimeMs((Long) v);
    }
    v = params.get(OPT_MAX_SOURCE_SIZE_K_BYTES);
    if (v != null) {
        limits.setMaxSourceSizeKBytes((Long) v);
    }
    v = params.get(OPT_READ_LIMIT_K_BYTES);
    if (v != null) {
        limits.setReadLimitKBytes((Long) v);
    }
    v = params.get(OPT_MAX_PAGES);
    if (v != null) {
        limits.setMaxPages((Integer) v);
    }
    v = params.get(OPT_PAGE_LIMIT);
    if (v != null) {
        limits.setPageLimit((Integer) v);
    }
    return thDefn;
}
Also used : Serializable(java.io.Serializable) TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Example 2 with TransformationOptionLimits

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

the class AbstractContentTransformerLimitsTest method setUp.

@Before
public void setUp() throws Exception {
    ApplicationContext ctx = MiscContextTestSuite.getMinimalContext();
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    MimetypeService mimetypeService = serviceRegistry.getMimetypeService();
    TransformerDebug transformerDebug = (TransformerDebug) ctx.getBean("transformerDebug");
    TransformerConfig transformerConfig = (TransformerConfig) ctx.getBean("transformerConfig");
    transformer = new AbstractContentTransformer2() {

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

        @Override
        protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception {
        }
    };
    transformer.setMimetypeService(mimetypeService);
    transformer.setTransformerDebug(transformerDebug);
    transformer.setTransformerConfig(transformerConfig);
    transformer.setBeanName("transformer.test" + System.currentTimeMillis() % 100000);
    limits = new TransformationOptionLimits();
    options = new TransformationOptions();
}
Also used : AbstractContentReader(org.alfresco.repo.content.AbstractContentReader) ContentReader(org.alfresco.service.cmr.repository.ContentReader) IOException(java.io.IOException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions) ApplicationContext(org.springframework.context.ApplicationContext) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) MimetypeService(org.alfresco.service.cmr.repository.MimetypeService) ServiceRegistry(org.alfresco.service.ServiceRegistry) Before(org.junit.Before)

Example 3 with TransformationOptionLimits

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

the class TransformerConfigLimits method setLimits.

/**
 * Sets the transformer limits for a single use from properties. Method extracted so that
 * it is possible to write a simpler unit test, that changes to the order of the
 * properties. The order changed between Java 6, 7 and 8, resulting in MNT-14295. The original
 * outer method cannot be used as it creates the list from a map (allUseMap) that it also
 * creates and the order of values from that map cannot be controlled from a test.
 */
void setLimits(String use, Collection<TransformerSourceTargetSuffixValue> properties) {
    // Add the system wide default just in case it is not included, as we always need this one
    getOrCreateTransformerOptionLimits(DEFAULT_TRANSFORMER, ANY, ANY, use);
    TransformationOptionLimits limits;
    for (int pass = 0; pass <= 3; pass++) {
        for (TransformerSourceTargetSuffixValue property : properties) {
            int origLevel = getLevel(property.transformerName, property.sourceMimetype);
            if (pass == origLevel) {
                logger.debug(property);
                String transformerName = (property.transformerName == null) ? DEFAULT_TRANSFORMER : property.transformerName;
                limits = getOrCreateTransformerOptionLimits(transformerName, property.sourceMimetype, property.targetMimetype, use);
                setTransformationLimitsFromProperties(limits, property.value, property.suffix);
                debug("V", transformerName, property.sourceMimetype, property.targetMimetype, use, limits);
            }
        }
    }
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits)

Example 4 with TransformationOptionLimits

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

the class TransformerConfigLimits method setLimits.

/**
 * Sets the transformer limits created from properties.
 */
private void setLimits(TransformerProperties transformerProperties, MimetypeService mimetypeService) {
    limitsMap = new ConcurrentHashMap<String, Map<String, DoubleMap<String, String, TransformationOptionLimits>>>();
    uses = new HashSet<String>();
    // Gets all the transformer, source and target combinations in properties that define limits.
    Map<TransformerSourceTargetSuffixKey, TransformerSourceTargetSuffixValue> allUseMap = getTransformerSourceTargetValuesMap(LIMIT_SUFFIXES, true, true, true, transformerProperties, mimetypeService);
    // Get the set 'use' values.
    uses.add(ANY);
    for (TransformerSourceTargetSuffixValue property : allUseMap.values()) {
        String propertyUse = property.use == null ? ANY : property.use;
        uses.add(propertyUse);
    }
    // Populate the limitsMap for each 'use'.
    for (String use : uses) {
        Collection<TransformerSourceTargetSuffixValue> properties = getPropertiesForUse(use, allUseMap);
        // Add the system wide default just in case it is not included, as we always need this one
        getOrCreateTransformerOptionLimits(DEFAULT_TRANSFORMER, ANY, ANY, use);
        TransformationOptionLimits limits;
        for (int pass = 0; pass <= 3; pass++) {
            for (TransformerSourceTargetSuffixValue property1 : properties) {
                int origLevel = getLevel(property1.transformerName, property1.sourceMimetype);
                if (pass == origLevel) {
                    logger.debug(property1);
                    String transformerName = (property1.transformerName == null) ? DEFAULT_TRANSFORMER : property1.transformerName;
                    limits = getOrCreateTransformerOptionLimits(transformerName, property1.sourceMimetype, property1.targetMimetype, use);
                    setTransformationLimitsFromProperties(limits, property1.value, property1.suffix);
                    debug("V", transformerName, property1.sourceMimetype, property1.targetMimetype, use, limits);
                }
            }
        }
    }
    logger.debug(this);
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 5 with TransformationOptionLimits

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

the class TransformerConfigLimitsTest method systemWideWildcardUseTest.

@Test
public // Checks wildcard usage at the system wide level
void systemWideWildcardUseTest() {
    mockProperties(transformerProperties, "content.transformer.default.extensions.txt.*.pageLimit", "1", "content.transformer.default.extensions.txt.*.pageLimit.use.index", "2", "content.transformer.default.extensions.pdf.*.pageLimit.use.index", "3", "content.transformer.default.extensions.pdf.txt.pageLimit.use.index", "4");
    extractor = new TransformerConfigLimits(transformerProperties, mimetypeService);
    TransformationOptionLimits txtToPngLimits = extractor.getLimits(transformer1, "text/plain", "image/png", null);
    assertEquals(1, txtToPngLimits.getPageLimit());
    txtToPngLimits = extractor.getLimits(transformer1, "text/plain", "image/png", "index");
    assertEquals(2, txtToPngLimits.getPageLimit());
    TransformationOptionLimits pdfToPngLimits = extractor.getLimits(transformer1, "application/pdf", "image/png", "index");
    assertEquals(3, pdfToPngLimits.getPageLimit());
    TransformationOptionLimits pdfToTxtLimits = extractor.getLimits(transformer1, "application/pdf", "text/plain", "index");
    assertEquals(4, pdfToTxtLimits.getPageLimit());
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) Test(org.junit.Test)

Aggregations

TransformationOptionLimits (org.alfresco.service.cmr.repository.TransformationOptionLimits)39 Test (org.junit.Test)22 Map (java.util.Map)3 TransformationOptions (org.alfresco.service.cmr.repository.TransformationOptions)3 TimeoutException (java.util.concurrent.TimeoutException)2 AbstractContentReader (org.alfresco.repo.content.AbstractContentReader)2 ImageResizeOptions (org.alfresco.repo.content.transform.magick.ImageResizeOptions)2 ImageTransformationOptions (org.alfresco.repo.content.transform.magick.ImageTransformationOptions)2 SWFTransformationOptions (org.alfresco.repo.content.transform.swf.SWFTransformationOptions)2 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)2 TransformationOptionPair (org.alfresco.service.cmr.repository.TransformationOptionPair)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1