Search in sources :

Example 6 with PagedSourceOptions

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

the class TransformationOptionsConverter method getOptions.

public Map<String, String> getOptions(TransformationOptions options, String sourceMimetype, String targetMimetype) {
    boolean sourceIsPdf = MIMETYPE_PDF.equals(sourceMimetype);
    Map<String, String> map = new HashMap<>();
    map.put(TIMEOUT, "-1");
    if (options != null) {
        if (options instanceof ImageTransformationOptions) {
            ImageTransformationOptions opts = (ImageTransformationOptions) options;
            // TODO We don't support this any more for security reasons, however it might be possible to
            // extract some of the well know values and add them to the newer ImageMagick transform options.
            String commandOptions = opts.getCommandOptions();
            if (commandOptions != null && !commandOptions.isBlank()) {
                logger.error("ImageMagick commandOptions are no longer supported for security reasons: " + commandOptions);
            }
            ImageResizeOptions imageResizeOptions = opts.getResizeOptions();
            if (imageResizeOptions != null) {
                int width = imageResizeOptions.getWidth();
                int height = imageResizeOptions.getHeight();
                ifSet(width != -1, map, RESIZE_WIDTH, width);
                ifSet(height != -1, map, RESIZE_HEIGHT, height);
                ifSet(imageResizeOptions.isResizeToThumbnail(), map, THUMBNAIL, true);
                ifSet(imageResizeOptions.isPercentResize(), map, RESIZE_PERCENTAGE, true);
                map.put(ALLOW_ENLARGEMENT, Boolean.toString(imageResizeOptions.getAllowEnlargement()));
                map.put(MAINTAIN_ASPECT_RATIO, Boolean.toString(imageResizeOptions.isMaintainAspectRatio()));
            }
            ifSet(MimetypeMap.MIMETYPE_IMAGE_JPEG.equalsIgnoreCase(targetMimetype), map, ALPHA_REMOVE, true);
            map.put(AUTO_ORIENT, Boolean.toString(opts.isAutoOrient()));
            Collection<TransformationSourceOptions> sourceOptionsList = opts.getSourceOptionsList();
            if (sourceOptionsList != null) {
                for (TransformationSourceOptions transformationSourceOptions : sourceOptionsList) {
                    if (transformationSourceOptions instanceof PagedSourceOptions) {
                        PagedSourceOptions pagedSourceOptions = (PagedSourceOptions) transformationSourceOptions;
                        // The legacy transformer options start at page 1, where as image magick and the local
                        // transforms start at 0;
                        Integer startPageNumber = pagedSourceOptions.getStartPageNumber() - 1;
                        Integer endPageNumber = pagedSourceOptions.getEndPageNumber() - 1;
                        // PAGE is not an imagemagick option, but pdfRederer was incorrectly created initially using these options
                        if (startPageNumber == endPageNumber && sourceIsPdf) {
                            map.put(PAGE, Integer.toString(startPageNumber));
                        } else {
                            map.put(START_PAGE, Integer.toString(startPageNumber));
                            map.put(END_PAGE, Integer.toString(endPageNumber));
                        }
                    } else if (transformationSourceOptions instanceof CropSourceOptions) {
                        CropSourceOptions cropSourceOptions = (CropSourceOptions) transformationSourceOptions;
                        String gravity = cropSourceOptions.getGravity();
                        boolean percentageCrop = cropSourceOptions.isPercentageCrop();
                        int height = cropSourceOptions.getHeight();
                        int width = cropSourceOptions.getWidth();
                        int xOffset = cropSourceOptions.getXOffset();
                        int yOffset = cropSourceOptions.getYOffset();
                        ifSet(gravity != null, map, CROP_GRAVITY, gravity);
                        ifSet(percentageCrop, map, CROP_PERCENTAGE, percentageCrop);
                        ifSet(width != -1, map, CROP_WIDTH, width);
                        ifSet(height != -1, map, CROP_HEIGHT, height);
                        map.put(CROP_X_OFFSET, Integer.toString(xOffset));
                        map.put(CROP_Y_OFFSET, Integer.toString(yOffset));
                    } else if (transformationSourceOptions instanceof TemporalSourceOptions) {
                        TemporalSourceOptions temporalSourceOptions = (TemporalSourceOptions) transformationSourceOptions;
                        String duration = temporalSourceOptions.getDuration();
                        String offset = temporalSourceOptions.getOffset();
                        ifSet(duration != null, map, DURATION, duration);
                        ifSet(offset != null, map, OFFSET, offset);
                    } else {
                        logger.error("TransformationOption sourceOptionsList contained a " + transformationSourceOptions.getClass().getName() + ". It is not know how to convert this into newer transform options.");
                    }
                }
            }
        } else if (options instanceof SWFTransformationOptions) {
            SWFTransformationOptions opts = (SWFTransformationOptions) options;
            map.put(FLASH_VERSION, opts.getFlashVersion());
        } else if (options instanceof RuntimeExecutableContentTransformerOptions) {
            RuntimeExecutableContentTransformerOptions opts = (RuntimeExecutableContentTransformerOptions) options;
            map.putAll(opts.getPropertyValues());
        } else if (!options.getClass().equals(TransformationOptions.class)) {
            throw new IllegalArgumentException("Unable to convert " + options.getClass().getSimpleName() + " to new transform options held in a Map<String,String>.\n" + "The TransformOptionConverter may need to be sub classed to support this conversion.");
        }
    }
    return map;
}
Also used : TemporalSourceOptions(org.alfresco.service.cmr.repository.TemporalSourceOptions) HashMap(java.util.HashMap) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) CropSourceOptions(org.alfresco.service.cmr.repository.CropSourceOptions) SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) RuntimeExecutableContentTransformerOptions(org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerOptions) TransformationSourceOptions(org.alfresco.service.cmr.repository.TransformationSourceOptions)

Example 7 with PagedSourceOptions

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

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

the class TransformationOptionsConverterTest method testResize.

// ImageTransformationOptions [commandOptions=, resizeOptions=ImageResizeOptions [width=20, height=30, maintainAspectRatio=true, percentResize=false,
// resizeToThumbnail=false, allowEnlargement=true], autoOrient=true], sourceOptions={ PagedSourceOptionsPagedSourceOptions {1, 1}} ]
@Test
public void testResize() {
    ImageTransformationOptions oldOptions = new ImageTransformationOptions();
    ImageResizeOptions imageResizeOptions = new ImageResizeOptions();
    imageResizeOptions.setAllowEnlargement(false);
    imageResizeOptions.setWidth(20);
    imageResizeOptions.setHeight(30);
    oldOptions.setResizeOptions(imageResizeOptions);
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber(1);
    pagedSourceOptions.setEndPageNumber(1);
    oldOptions.addSourceOptions(pagedSourceOptions);
    assertConverterToMapAndBack(oldOptions, MIMETYPE_IMAGE_JPEG, MIMETYPE_IMAGE_PNG, "ImageTransformationOptions [commandOptions=, " + "resizeOptions=ImageResizeOptions [width=20, height=30, maintainAspectRatio=true, " + "percentResize=false, resizeToThumbnail=false, allowEnlargement=false], autoOrient=true], " + "sourceOptions={ PagedSourceOptionsPagedSourceOptions {1, 1}} ]", "allowEnlargement=false " + "autoOrient=true " + "endPage=0 " + "resizeHeight=30 " + "resizeWidth=20 " + "startPage=0 " + "timeout=-1 ", true);
}
Also used : ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) Test(org.junit.Test)

Example 9 with PagedSourceOptions

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

the class ThumbnailServiceImplTest method testCreateRenditionThumbnailFromPdfPage2.

@Test
public void testCreateRenditionThumbnailFromPdfPage2() throws Exception {
    ImageTransformationOptions options = new ImageTransformationOptions();
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber(new Integer(2));
    pagedSourceOptions.setEndPageNumber(new Integer(2));
    options.addSourceOptions(pagedSourceOptions);
    ThumbnailDefinition thumbnailDefinition = new ThumbnailDefinition(MimetypeMap.MIMETYPE_PDF, options, "doclib_2");
    thumbnailService.getThumbnailRegistry().addThumbnailDefinition(thumbnailDefinition);
    checkTransformer();
    NodeRef pdfOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_PDF);
    NodeRef thumbnail0 = this.thumbnailService.createThumbnail(pdfOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, thumbnailDefinition.getTransformationOptions(), "doclib_2");
    assertNotNull(thumbnail0);
    checkRenditioned(pdfOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "doclib_2", 1)));
    checkRendition("doclib_2", thumbnail0);
    // Check the length
    File tempFile = TempFileProvider.createTempFile("thumbnailServiceImplTest", ".jpg");
    ContentReader reader = this.contentService.getReader(thumbnail0, ContentModel.PROP_CONTENT);
    long size = reader.getSize();
    reader.getContent(tempFile);
    assertTrue("Page 2 should be blank and less than 4500 bytes. It was " + size + " bytes. tempFile=" + tempFile.getPath(), size < 4500);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) File(java.io.File) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Example 10 with PagedSourceOptions

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

the class ThumbnailServiceImplParameterTest method createThumbnailPassesParametersToActionService.

/**
 * This test method ensures that the parameters on thumbnail-create are
 * passed through the RenditionService to the ActionService
 */
@Test
public void createThumbnailPassesParametersToActionService() {
    // As most of the services are mocked out, the actual values used here
    // don't matter.
    final Map<String, Serializable> parametersUnderTest = new HashMap<String, Serializable>();
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_WIDTH, new Integer(42));
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, new Integer(93));
    parametersUnderTest.put(ImageRenderingEngine.PARAM_COMMAND_OPTIONS, "foo");
    parametersUnderTest.put(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO, Boolean.TRUE);
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL, Boolean.FALSE);
    parametersUnderTest.put(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT, Boolean.TRUE);
    parametersUnderTest.put(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, ContentModel.PROP_CONTENT);
    parametersUnderTest.put(RenditionService.PARAM_DESTINATION_NODE, dummyNodeRef2);
    parametersUnderTest.put(PagedSourceOptionsSerializer.PARAM_SOURCE_START_PAGE, new Integer(2));
    parametersUnderTest.put(PagedSourceOptionsSerializer.PARAM_SOURCE_END_PAGE, new Integer(2));
    parametersUnderTest.put(TemporalSourceOptionsSerializer.PARAM_SOURCE_TIME_OFFSET, "00:00:00.5");
    ImageTransformationOptions imageTransOpts = new ImageTransformationOptions();
    imageTransOpts.setTargetNodeRef(dummyNodeRef2);
    imageTransOpts.setTargetContentProperty((QName) parametersUnderTest.get(ImageRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY));
    imageTransOpts.setCommandOptions((String) parametersUnderTest.get(ImageRenderingEngine.PARAM_COMMAND_OPTIONS));
    ImageResizeOptions resizeOptions = new ImageResizeOptions();
    resizeOptions.setHeight((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_HEIGHT));
    resizeOptions.setWidth((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_WIDTH));
    resizeOptions.setMaintainAspectRatio((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO));
    resizeOptions.setResizeToThumbnail((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL));
    resizeOptions.setAllowEnlargement((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT));
    imageTransOpts.setResizeOptions(resizeOptions);
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber((Integer) parametersUnderTest.get(PagedSourceOptionsSerializer.PARAM_SOURCE_START_PAGE));
    pagedSourceOptions.setEndPageNumber((Integer) parametersUnderTest.get(PagedSourceOptionsSerializer.PARAM_SOURCE_END_PAGE));
    imageTransOpts.addSourceOptions(pagedSourceOptions);
    TemporalSourceOptions temporalSourceOptions = new TemporalSourceOptions();
    temporalSourceOptions.setOffset((String) parametersUnderTest.get(TemporalSourceOptionsSerializer.PARAM_SOURCE_TIME_OFFSET));
    imageTransOpts.addSourceOptions(temporalSourceOptions);
    ThumbnailParentAssociationDetails assocDetails = new ThumbnailParentAssociationDetails(dummyNodeRef3, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "homerSimpson"));
    // Now request the creation of the the thumbnail.
    thumbnailService.createThumbnail(dummyNodeRef1, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransOpts, "bartSimpson", assocDetails);
    ArgumentCaptor<Action> argument = ArgumentCaptor.forClass(Action.class);
    verify(mockActionService).executeAction(argument.capture(), any(NodeRef.class), anyBoolean(), anyBoolean());
    final Action action = argument.getValue();
    final RenditionDefinition renditionDefn = (RenditionDefinition) action;
    Map<String, Serializable> parameters = renditionDefn.getParameterValues();
    for (String s : parametersUnderTest.keySet()) {
        if (parameters.keySet().contains(s) == false || parameters.get(s) == null || parameters.get(s).toString().length() == 0) {
            fail("Missing parameter " + s);
        }
        assertEquals("Parameter " + s + " had wrong value.", parametersUnderTest.get(s), parameters.get(s));
    }
}
Also used : TemporalSourceOptions(org.alfresco.service.cmr.repository.TemporalSourceOptions) Serializable(java.io.Serializable) Action(org.alfresco.service.cmr.action.Action) HashMap(java.util.HashMap) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) ThumbnailParentAssociationDetails(org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) Test(org.junit.Test)

Aggregations

PagedSourceOptions (org.alfresco.service.cmr.repository.PagedSourceOptions)10 ImageTransformationOptions (org.alfresco.repo.content.transform.magick.ImageTransformationOptions)8 Test (org.junit.Test)6 ImageResizeOptions (org.alfresco.repo.content.transform.magick.ImageResizeOptions)5 HashMap (java.util.HashMap)3 SWFTransformationOptions (org.alfresco.repo.content.transform.swf.SWFTransformationOptions)3 TemporalSourceOptions (org.alfresco.service.cmr.repository.TemporalSourceOptions)3 TransformationSourceOptions (org.alfresco.service.cmr.repository.TransformationSourceOptions)3 ArrayList (java.util.ArrayList)2 RuntimeExecutableContentTransformerOptions (org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerOptions)2 CropSourceOptions (org.alfresco.service.cmr.repository.CropSourceOptions)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 File (java.io.File)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1