Search in sources :

Example 31 with TransformationOptions

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

the class TextToPdfContentTransformerTest method testReliability.

public void testReliability() throws Exception {
    transformer.setPageLimit(-1);
    transformer.register();
    boolean reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_PDF, -1, MimetypeMap.MIMETYPE_TEXT_PLAIN, new TransformationOptions());
    assertEquals("Mimetype should not be supported", false, reliability);
    reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_TEXT_PLAIN, -1, MimetypeMap.MIMETYPE_PDF, new TransformationOptions());
    assertEquals("Mimetype should be supported", true, reliability);
    reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_XML, -1, MimetypeMap.MIMETYPE_PDF, new TransformationOptions());
    assertEquals("Mimetype should be supported", true, reliability);
}
Also used : TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Example 32 with TransformationOptions

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

the class TransformationOptionsConverterTest method assertConverterToMapAndBack.

private void assertConverterToMapAndBack(TransformationOptions oldOptions, String sourceMimetype, String targetMimetype, String expectedOldOptionsToString, String expectedArgs, boolean checkImageMagickContentTransformerWorkerResult) {
    String sortedOldOptions = getSortedOptions(oldOptions, sourceMimetype, targetMimetype);
    assertEquals("oldOptions was not set up correctly", expectedOldOptionsToString, oldOptions.toString());
    // It is really checking that the supplied expectedArgs (just used to check the sortedNewOptions) are correct.
    if (checkImageMagickContentTransformerWorkerResult) {
        String[] tEngineArgs = getOptionalTEngineArgs(oldOptions, sourceMimetype, targetMimetype);
        String sortedTEngineOptions = getSortedOptions(tEngineArgs) + "timeout=-1 ";
        assertEquals("Test error: expectedArgs are not what is generated by ImageMagickContentTransformerWorker", expectedArgs, sortedTEngineOptions);
    }
    Map<String, String> newOptions = converter.getOptions(oldOptions, sourceMimetype, targetMimetype);
    Map<String, String> newOptionsWithoutDiscards = discardNoopOptions(newOptions);
    String sortedNewOptions = getSortedOptions(newOptionsWithoutDiscards);
    assertEquals("Conversion to a map appears to be wrong", expectedArgs, sortedNewOptions);
    TransformationOptions backToOldOptions = converter.getTransformationOptions("null", newOptions);
    String sortedBackToOldOptions = getSortedOptions(backToOldOptions, sourceMimetype, targetMimetype);
    assertEquals("Having converted twice the toString is different", expectedOldOptionsToString, backToOldOptions.toString());
    assertEquals("Having converted twice the map is different", sortedOldOptions, sortedBackToOldOptions);
}
Also used : SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions)

Example 33 with TransformationOptions

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

the class RenditionDefinitionTest method testGetRenderingEngineDefinition.

@Test
public void testGetRenderingEngineDefinition() throws Exception {
    ThumbnailRenditionConvertor converter = new ThumbnailRenditionConvertor();
    List<RenditionDefinition> renditionDefinitions = new ArrayList(renditionService.loadRenditionDefinitions());
    Set<String> renditionNames = renditionDefinitionRegistry2.getRenditionNames();
    for (String renditionName : renditionNames) {
        System.out.println("renditionName=" + renditionName);
        RenditionDefinition definition = getRenditionDefinition(renditionDefinitions, renditionName);
        assertNotNull("There is no RenditionDefinition for " + renditionName, definition);
        renditionDefinitions.remove(definition);
        ThumbnailDefinition thumbnailDefinition = converter.convert(definition);
        TransformationOptions transformationOptions = thumbnailDefinition.getTransformationOptions();
        RenditionDefinition2 definition2 = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
        Map<String, String> options = definition2.getTransformOptions();
        TransformationOptions transformationOptions2 = transformationOptionsConverter.getTransformationOptions(renditionName, options);
        Map<String, String> options2 = transformationOptionsConverter.getOptions(transformationOptions2, null, null);
        // The use is not set in the original until much later
        transformationOptions2.setUse(null);
        // than checking transformationOptions is equal to transformationOptions2.
        if (!renditionName.equals("pdf") && !renditionName.equals("webpreview")) {
            assertEquals("The TransformationOptions used in transforms for " + renditionName + " should be the same", transformationOptions.toStringAll(), transformationOptions2.toStringAll());
            assertEquals("The transformationOptionsConverter back to the newer format was not the same for " + renditionName, options, options2);
        } else {
            assertEquals("The converted class for " + renditionName + " should be the same as before", transformationOptions.getClass(), transformationOptions2.getClass());
            assertEquals("The converted class for " + renditionName + " should be SWFTransformationOptions", SWFTransformationOptions.class, transformationOptions2.getClass());
        }
    }
    if (!renditionDefinitions.isEmpty()) {
        StringJoiner sj = new StringJoiner(", ");
        for (RenditionDefinition renditionDefinition : renditionDefinitions) {
            String name = renditionDefinition.getRenditionName().getLocalName();
            sj.add(name);
        }
        fail("There is no RenditionDefinition2 for existing RenditionDefinitions " + sj);
    }
}
Also used : ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) ArrayList(java.util.ArrayList) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) StringJoiner(java.util.StringJoiner) ThumbnailRenditionConvertor(org.alfresco.repo.thumbnail.ThumbnailRenditionConvertor) SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 34 with TransformationOptions

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

the class TransformationOptionsConverterTest method testRenditionImagepreview.

@Test
public // Check conversion to TransformationOptions from options found in rendition definitions
void testRenditionImagepreview() {
    String sourceMimetype = null;
    String targetMimetype = null;
    Map<String, String> newOptions = new HashMap<>();
    newOptions.put("thumbnail", "true");
    newOptions.put("resizeWidth", "960");
    newOptions.put("autoOrient", "true");
    newOptions.put("resizeHeight", "960");
    newOptions.put("allowEnlargement", "true");
    newOptions.put("maintainAspectRatio", "true");
    String sortedNewOptions = getSortedOptions(newOptions);
    TransformationOptions oldOptions = converter.getTransformationOptions("null", newOptions);
    String sortedOldOptions = getSortedOptions(oldOptions, sourceMimetype, targetMimetype);
    if (sortedOldOptions.endsWith("timeout=-1 ")) {
        sortedOldOptions = sortedOldOptions.substring(0, sortedOldOptions.length() - "timeout=-1 ".length());
    }
    assertEquals("Maps are different", sortedNewOptions, sortedOldOptions);
}
Also used : HashMap(java.util.HashMap) SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) Test(org.junit.Test)

Example 35 with TransformationOptions

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

the class ThumbnailServiceImplTest method testHTMLToImageAndSWF.

@Test
@Ignore("The test was never run and fails on remote transformer")
public void testHTMLToImageAndSWF() throws Exception {
    NodeRef nodeRef = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_HTML);
    ThumbnailDefinition def = this.thumbnailService.getThumbnailRegistry().getThumbnailDefinition("medium");
    TransformationOptions transformationOptions = def.getTransformationOptions();
    Map<String, String> options = converter.getOptions(transformationOptions, MimetypeMap.MIMETYPE_HTML, def.getMimetype());
    String targetMimetype = def.getMimetype();
    boolean supported = synchronousTransformClient.isSupported(MimetypeMap.MIMETYPE_HTML, -1, null, targetMimetype, options, null, null);
    if (supported) {
        NodeRef thumb = this.thumbnailService.createThumbnail(nodeRef, ContentModel.PROP_CONTENT, def.getMimetype(), def.getTransformationOptions(), def.getName());
        assertNotNull(thumb);
        ContentReader reader = this.contentService.getReader(thumb, ContentModel.PROP_CONTENT);
        assertNotNull(reader);
        assertEquals(def.getMimetype(), reader.getMimetype());
        assertTrue(reader.getSize() != 0);
    }
    def = this.thumbnailService.getThumbnailRegistry().getThumbnailDefinition("webpreview");
    if (supported) {
        NodeRef thumb = this.thumbnailService.createThumbnail(nodeRef, ContentModel.PROP_CONTENT, def.getMimetype(), def.getTransformationOptions(), def.getName());
        assertNotNull(thumb);
        ContentReader reader = this.contentService.getReader(thumb, ContentModel.PROP_CONTENT);
        assertNotNull(reader);
        assertEquals(def.getMimetype(), reader.getMimetype());
        assertTrue(reader.getSize() != 0);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentReader(org.alfresco.service.cmr.repository.ContentReader) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) Ignore(org.junit.Ignore) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

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