use of org.alfresco.transform.client.registry.SupportedTransform in project alfresco-repository by Alfresco.
the class AbstractRenditionTest method logSourceTarget.
private void logSourceTarget(StringBuilder sourceTargetList, StringBuilder sourceTargetPriorityList, AtomicInteger count, String sourceMimetype, String targetMimetype) {
count.incrementAndGet();
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
String targetExtension = mimetypeService.getExtension(targetMimetype);
String line = String.format("%4d %4s %4s\n", count.get(), sourceExtension, targetExtension);
sourceTargetList.append(line);
if (sourceTargetPriorityList != null) {
AbstractTransformRegistry registry = getAbstractTransformRegistry();
if (registry != null) {
Map<String, List<SupportedTransform>> supportedTransformsByTargetMimetype = registry.getData().retrieveTransforms(sourceMimetype);
List<SupportedTransform> supportedTransforms = new ArrayList<>(supportedTransformsByTargetMimetype.get(targetMimetype));
supportedTransforms.sort((t1, t2) -> t1.getPriority() - t2.getPriority());
char a = 'a';
int prevPriority = Integer.MAX_VALUE;
for (SupportedTransform supportedTransform : supportedTransforms) {
int priority = supportedTransform.getPriority();
long maxSourceSizeBytes = supportedTransform.getMaxSourceSizeBytes();
String priorityUnchanged = prevPriority == priority ? "*" : "";
String transformName = supportedTransform.getName();
line = String.format("%4d %4s %4s %c) [%d%s] %s %d\n", count.get(), sourceExtension, targetExtension, a++, priority, priorityUnchanged, transformName, maxSourceSizeBytes);
sourceTargetPriorityList.append(line);
prevPriority = priority;
}
}
}
}
use of org.alfresco.transform.client.registry.SupportedTransform in project alfresco-repository by Alfresco.
the class AdminUiTransformerDebug method transformationsByExtension.
/**
* Returns a String and /or debug that provides a list of supported transformations
* sorted by source and target mimetype extension. Used in the Test Transforms Admin UI.
* @param sourceExtension restricts the list to one source extension. Unrestricted if null.
* @param targetExtension restricts the list to one target extension. Unrestricted if null.
* @param toString indicates that a String value should be returned in addition to any debug.
* @param format42 ignored
* @param onlyNonDeterministic ignored
* @param renditionName ignored
*/
public String transformationsByExtension(String sourceExtension, String targetExtension, boolean toString, boolean format42, boolean onlyNonDeterministic, String renditionName) {
// (for example a test transform).
if (getStringBuilder() != null) {
return null;
}
Collection<String> sourceMimetypes = format42 || sourceExtension != null ? getSourceMimetypes(sourceExtension) : mimetypeService.getMimetypes();
Collection<String> targetMimetypes = format42 || targetExtension != null ? getTargetMimetypes(sourceExtension, targetExtension, sourceMimetypes) : mimetypeService.getMimetypes();
StringBuilder sb = null;
try {
if (toString) {
sb = new StringBuilder();
setStringBuilder(sb);
}
pushMisc();
for (String sourceMimetype : sourceMimetypes) {
for (String targetMimetype : targetMimetypes) {
// Log the transformers
boolean supportedByTransformService = remoteTransformServiceRegistry == null || remoteTransformServiceRegistry instanceof DummyTransformServiceRegistry ? false : remoteTransformServiceRegistry.isSupported(sourceMimetype, -1, targetMimetype, Collections.emptyMap(), null);
List<SupportedTransform> localTransformers = localTransformServiceRegistryImpl == null ? Collections.emptyList() : localTransformServiceRegistryImpl.findTransformers(sourceMimetype, targetMimetype, Collections.emptyMap(), null);
if (!localTransformers.isEmpty() || supportedByTransformService) {
try {
pushMisc();
int transformerCount = 0;
if (supportedByTransformService) {
long maxSourceSizeKBytes = remoteTransformServiceRegistry.findMaxSize(sourceMimetype, targetMimetype, Collections.emptyMap(), null);
activeTransformer(sourceMimetype, targetMimetype, transformerCount, " ", TRANSFORM_SERVICE_NAME, maxSourceSizeKBytes, transformerCount++ == 0);
}
for (SupportedTransform localTransformer : localTransformers) {
long maxSourceSizeKBytes = localTransformer.getMaxSourceSizeBytes();
String transformName = "Local:" + localTransformer.getName();
String transformerPriority = "[" + localTransformer.getPriority() + ']';
transformerPriority = spaces(5 - transformerPriority.length()) + transformerPriority;
activeTransformer(sourceMimetype, targetMimetype, transformerCount, transformerPriority, transformName, maxSourceSizeKBytes, transformerCount++ == 0);
}
} finally {
popMisc();
}
}
}
}
} finally {
popMisc();
setStringBuilder(null);
}
stripFinishedLine(sb);
return stripLeadingNumber(sb);
}
use of org.alfresco.transform.client.registry.SupportedTransform in project alfresco-repository by Alfresco.
the class LegacyTransformerDebug method transformationsByExtension.
/**
* Returns a String and /or debug that provides a list of supported transformations
* sorted by source and target mimetype extension.
* @param sourceExtension restricts the list to one source extension. Unrestricted if null.
* @param targetExtension restricts the list to one target extension. Unrestricted if null.
* @param toString indicates that a String value should be returned in addition to any debug.
* @param format42 indicates the new 4.2 rather than older 4.1.4 format should be used.
* The 4.1.4 format did not order the transformers or mimetypes and only included top
* level transformers.
* @param onlyNonDeterministic if true only report transformations where there is more than
* one transformer available with the same priority.
* @param renditionName to which the transformation will be put (such as "Index", "Preview", null).
* @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
@Deprecated
@Override
public String transformationsByExtension(String sourceExtension, String targetExtension, boolean toString, boolean format42, boolean onlyNonDeterministic, String renditionName) {
// (for example a test transform).
if (getStringBuilder() != null) {
return null;
}
Collection<ContentTransformer> transformers = format42 && !onlyNonDeterministic ? sortTransformersByName(null) : transformerRegistry.getTransformers();
Collection<String> sourceMimetypes = format42 || sourceExtension != null ? getSourceMimetypes(sourceExtension) : mimetypeService.getMimetypes();
Collection<String> targetMimetypes = format42 || targetExtension != null ? getTargetMimetypes(sourceExtension, targetExtension, sourceMimetypes) : mimetypeService.getMimetypes();
TransformationOptions options = new TransformationOptions();
options.setUse(renditionName);
StringBuilder sb = null;
try {
if (toString) {
sb = new StringBuilder();
setStringBuilder(sb);
}
pushMisc();
for (String sourceMimetype : sourceMimetypes) {
for (String targetMimetype : targetMimetypes) {
// Find available transformers
List<ContentTransformer> availableTransformer = new ArrayList<ContentTransformer>();
for (ContentTransformer transformer : transformers) {
if (transformer.isTransformable(sourceMimetype, -1, targetMimetype, options)) {
availableTransformer.add(transformer);
}
}
// Sort by priority
final String currSourceMimetype = sourceExtension;
final String currTargetMimetype = targetExtension;
Collections.sort(availableTransformer, new Comparator<ContentTransformer>() {
@Override
public int compare(ContentTransformer transformer1, ContentTransformer transformer2) {
return transformerConfig.getPriority(transformer1, currSourceMimetype, currTargetMimetype) - transformerConfig.getPriority(transformer2, currSourceMimetype, currTargetMimetype);
}
});
// Do we need to produce any output?
int size = availableTransformer.size();
int priority = size >= 2 ? transformerConfig.getPriority(availableTransformer.get(0), sourceMimetype, targetMimetype) : -1;
if (!onlyNonDeterministic || (size >= 2 && priority == transformerConfig.getPriority(availableTransformer.get(1), sourceMimetype, targetMimetype))) {
// Log the transformers
boolean supportedByTransformService = remoteTransformServiceRegistry == null || remoteTransformServiceRegistry instanceof DummyTransformServiceRegistry ? false : remoteTransformServiceRegistry.isSupported(sourceMimetype, -1, targetMimetype, Collections.emptyMap(), null);
List<SupportedTransform> localTransformers = localTransformServiceRegistryImpl == null ? Collections.emptyList() : localTransformServiceRegistryImpl.findTransformers(sourceMimetype, targetMimetype, Collections.emptyMap(), null);
if (!localTransformers.isEmpty() || supportedByTransformService || size >= 1) {
try {
pushMisc();
int transformerCount = 0;
if (supportedByTransformService) {
long maxSourceSizeKBytes = remoteTransformServiceRegistry.findMaxSize(sourceMimetype, targetMimetype, Collections.emptyMap(), null);
activeTransformer(sourceMimetype, targetMimetype, transformerCount, " ", TRANSFORM_SERVICE_NAME, maxSourceSizeKBytes, transformerCount++ == 0);
}
for (SupportedTransform localTransformer : localTransformers) {
long maxSourceSizeKBytes = localTransformer.getMaxSourceSizeBytes();
String transformName = "Local:" + localTransformer.getName();
String transformerPriority = "[" + localTransformer.getPriority() + ']';
transformerPriority = spaces(5 - transformerPriority.length()) + transformerPriority;
activeTransformer(sourceMimetype, targetMimetype, transformerCount, transformerPriority, transformName, maxSourceSizeKBytes, transformerCount++ == 0);
}
for (ContentTransformer transformer : availableTransformer) {
if (!onlyNonDeterministic || transformerCount < 2 || priority == transformerConfig.getPriority(transformer, sourceMimetype, targetMimetype)) {
long maxSourceSizeKBytes = transformer.getMaxSourceSizeKBytes(sourceMimetype, targetMimetype, options);
activeTransformer(sourceMimetype, targetMimetype, transformerCount, transformer, maxSourceSizeKBytes, transformerCount++ == 0);
}
}
} finally {
popMisc();
}
}
}
}
}
} finally {
popMisc();
setStringBuilder(null);
}
stripFinishedLine(sb);
return stripLeadingNumber(sb);
}
use of org.alfresco.transform.client.registry.SupportedTransform in project alfresco-repository by Alfresco.
the class TransformServiceRegistryConfigTest method testJsonPipeline.
@Test
public void testJsonPipeline() throws IOException {
register(getTransformServiceConfigPipeline());
// Check the count of transforms supported
int expectedTransforms = getExpectedTransformsForTestJsonPipeline();
assertEquals("The number of UNIQUE source to target mimetypes transforms has changed. Config change?", expectedTransforms, countSupportedTransforms(true));
assertEquals("The number of source to target mimetypes transforms has changed. " + "There may be multiple transformers for the same combination. Config change?", expectedTransforms, countSupportedTransforms(false));
// Check required and optional default correctly
Map<String, List<SupportedTransform>> transformsToWord = registry.getData().getTransforms().get(DOC);
List<SupportedTransform> supportedTransforms = transformsToWord.get(GIF);
SupportedTransform supportedTransform = supportedTransforms.get(0);
Set<TransformOption> transformOptionsSet = supportedTransform.getTransformOptions().getTransformOptions();
Iterator<TransformOption> iterator = transformOptionsSet.iterator();
assertTrue("Expected transform values", iterator.hasNext());
// Because Set is unordered we don't know which TransformOptionGroup we retrieve
TransformOptionGroup transformOptions1 = (TransformOptionGroup) iterator.next();
assertTrue("Expected transform values", iterator.hasNext());
TransformOptionGroup transformOptions2 = (TransformOptionGroup) iterator.next();
TransformOptionGroup imagemagick;
TransformOptionGroup pdf;
if (containsTransformOptionValueName(transformOptions1, "alphaRemove")) {
imagemagick = transformOptions1;
pdf = transformOptions2;
} else {
imagemagick = transformOptions2;
pdf = transformOptions1;
}
TransformOptionValue alphaRemove = (TransformOptionValue) retrieveTransformOptionByPropertyName(imagemagick, "alphaRemove", "TransformOptionValue");
TransformOptionGroup crop = (TransformOptionGroup) retrieveTransformOptionByPropertyName(imagemagick, "crop", "TransformOptionGroup");
TransformOptionValue cropGravity = (TransformOptionValue) retrieveTransformOptionByPropertyName(crop, "cropGravity", "TransformOptionValue");
TransformOptionValue cropWidth = (TransformOptionValue) retrieveTransformOptionByPropertyName(crop, "cropWidth", "TransformOptionValue");
assertTrue("The holding group should be required", supportedTransform.getTransformOptions().isRequired());
assertFalse("imagemagick should be optional as it is not set", imagemagick.isRequired());
assertFalse("pdf should be optional as required is not set", pdf.isRequired());
assertEquals("alphaRemove", alphaRemove.getName());
assertEquals("cropGravity", cropGravity.getName());
assertEquals("cropWidth", cropWidth.getName());
assertFalse("alphaRemove should be optional as required is not set", alphaRemove.isRequired());
assertFalse("crop should be optional as required is not set", crop.isRequired());
assertTrue("cropGravity should be required as it is set", cropGravity.isRequired());
assertFalse("cropWidth should be optional as required is not set", cropWidth.isRequired());
// Check a supported transform for each transformer.
assertSupported(DOC, 1234, GIF, emptyMap(), null, "");
assertSupported(DOC, 1234, PNG, emptyMap(), null, "");
assertSupported(DOC, 1234, JPEG, emptyMap(), null, "");
assertSupported(DOC, 1234, TIFF, emptyMap(), null, "");
Map<String, String> actualOptions = new HashMap<>();
actualOptions.put("thumbnail", "true");
actualOptions.put("resizeWidth", "100");
actualOptions.put("resizeHeight", "100");
actualOptions.put("allowEnlargement", "false");
actualOptions.put("maintainAspectRatio", "true");
assertSupported(DOC, 1234, PNG, actualOptions, null, "");
}
Aggregations