Search in sources :

Example 1 with PagedSourceOptions

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

the class AlfrescoPdfRendererContentTransformerWorker method getSourcePageRange.

/**
 * Gets the page range from the source to use in the command line.
 *
 * @param options the transformation options
 * @param sourceMimetype the source mimetype
 * @param targetMimetype the target mimetype
 * @return the source page range for the command line
 */
private String getSourcePageRange(TransformationOptions options, String sourceMimetype, String targetMimetype) {
    if (options instanceof ImageTransformationOptions) {
        ImageTransformationOptions imageOptions = (ImageTransformationOptions) options;
        PagedSourceOptions pagedSourceOptions = imageOptions.getSourceOptions(PagedSourceOptions.class);
        if (pagedSourceOptions != null) {
            if (pagedSourceOptions.getStartPageNumber() != null && pagedSourceOptions.getEndPageNumber() != null) {
                if (pagedSourceOptions.getStartPageNumber().equals(pagedSourceOptions.getEndPageNumber())) {
                    return "" + (pagedSourceOptions.getStartPageNumber() - 1);
                } else {
                    throw new AlfrescoRuntimeException("The alfresco-pdf-renderer can only convert single pages, no page ranges.");
                }
            } else {
                throw new AlfrescoRuntimeException("The alfresco-pdf-renderer can only convert single pages, no page ranges.");
            }
        }
    }
    return "0";
}
Also used : ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions)

Example 2 with PagedSourceOptions

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

the class TransformationOptionsConverterTest method testSWFTransformationOptionsPage.

@Test
public // is no longer used as there are o transformers for it.
void testSWFTransformationOptionsPage() {
    SWFTransformationOptions oldOptions = new SWFTransformationOptions();
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber(1);
    pagedSourceOptions.setEndPageNumber(1);
    oldOptions.addSourceOptions(pagedSourceOptions);
    assertConverterToMapAndBack(oldOptions, MIMETYPE_IMAGE_JPEG, MIMETYPE_IMAGE_PNG, "{maxSourceSizeKBytes=-1, use=null, contentReaderNodeRef=null, readLimitKBytes=-1, " + "contentWriterNodeRef=null, pageLimit=-1, flashVersion=9, timeoutMs=-1, maxPages=-1, " + "sourceContentProperty=null, targetContentProperty=null, includeEmbedded=null, readLimitTimeMs=-1}", "flashVersion=9 " + "timeout=-1 ", // SWFTransformationOptions are not used by ImageMagickContentTransformerWorker
    false);
}
Also used : SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) Test(org.junit.Test)

Example 3 with PagedSourceOptions

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

the class TransformationOptionsConverterTest method testCompositeReformatAndResizeRendition.

@Test
public void testCompositeReformatAndResizeRendition() {
    ImageTransformationOptions oldOptions = new ImageTransformationOptions();
    ImageResizeOptions imageResizeOptions = new ImageResizeOptions();
    imageResizeOptions.setHeight(30);
    imageResizeOptions.setWidth(20);
    oldOptions.setResizeOptions(imageResizeOptions);
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber(1);
    pagedSourceOptions.setEndPageNumber(1);
    oldOptions.addSourceOptions(pagedSourceOptions);
    assertConverterToMapAndBack(oldOptions, MIMETYPE_IMAGE_JPEG, MIMETYPE_IMAGE_JPEG, "ImageTransformationOptions [commandOptions=, resizeOptions=" + "ImageResizeOptions [width=20, height=30, maintainAspectRatio=true, percentResize=false, " + "resizeToThumbnail=false, allowEnlargement=true], autoOrient=true], " + "sourceOptions={ PagedSourceOptionsPagedSourceOptions {1, 1}} ]", "alphaRemove=true " + "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 4 with PagedSourceOptions

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

the class TransformationOptionsConverterTest method testImageTransformationOptionsPage.

@Test
public // Checks we do what was in the legacy ImageMagickContentTransformerWorker
void testImageTransformationOptionsPage() {
    ImageTransformationOptions oldOptions = new ImageTransformationOptions();
    oldOptions.setAutoOrient(false);
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber(1);
    pagedSourceOptions.setEndPageNumber(1);
    oldOptions.addSourceOptions(pagedSourceOptions);
    assertConverterToMapAndBack(oldOptions, MIMETYPE_IMAGE_JPEG, MIMETYPE_IMAGE_PNG, "ImageTransformationOptions [commandOptions=, " + "resizeOptions=null, autoOrient=false], " + "sourceOptions={ PagedSourceOptionsPagedSourceOptions {1, 1}} ]", "endPage=0 startPage=0 " + "timeout=-1 ", true);
}
Also used : ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) Test(org.junit.Test)

Example 5 with PagedSourceOptions

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

the class ImageMagickContentTransformerTest method ignoreTestPageSourceOptions.

// This fails with remote transformers
// The thumbnails actually have parameters in real life
public void ignoreTestPageSourceOptions() throws Exception {
    // Test empty source options
    ImageTransformationOptions options = new ImageTransformationOptions();
    this.transform(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
    // Test first page
    options = new ImageTransformationOptions();
    List<TransformationSourceOptions> sourceOptionsList = new ArrayList<TransformationSourceOptions>();
    sourceOptionsList.add(PagedSourceOptions.getPage1Instance());
    options.setSourceOptionsList(sourceOptionsList);
    this.transform(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
    // Test second page
    options = new ImageTransformationOptions();
    sourceOptionsList = new ArrayList<TransformationSourceOptions>();
    PagedSourceOptions sourceOptions = new PagedSourceOptions();
    sourceOptions.setStartPageNumber(2);
    sourceOptions.setEndPageNumber(2);
    sourceOptionsList.add(sourceOptions);
    options.setSourceOptionsList(sourceOptionsList);
    this.transform(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
    // Test page range invalid for target type
    options = new ImageTransformationOptions();
    sourceOptionsList = new ArrayList<TransformationSourceOptions>();
    sourceOptions = new PagedSourceOptions();
    sourceOptions.setStartPageNumber(1);
    sourceOptions.setEndPageNumber(2);
    sourceOptionsList.add(sourceOptions);
    options.setSourceOptionsList(sourceOptionsList);
    try {
        this.transform(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
        fail("An exception regarding an invalid page range should have been thrown");
    } catch (Exception e) {
    // failure expected
    }
    // Test page out of range
    options = new ImageTransformationOptions();
    sourceOptionsList = new ArrayList<TransformationSourceOptions>();
    sourceOptions = new PagedSourceOptions();
    sourceOptions.setStartPageNumber(3);
    sourceOptions.setEndPageNumber(3);
    sourceOptionsList.add(sourceOptions);
    options.setSourceOptionsList(sourceOptionsList);
    try {
        this.transform(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
        fail("An exception regarding an invalid page range should have been thrown");
    } catch (Exception e) {
    // failure expected
    }
}
Also used : ArrayList(java.util.ArrayList) TransformationSourceOptions(org.alfresco.service.cmr.repository.TransformationSourceOptions) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) IOException(java.io.IOException)

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