MNT-7158: Investigating adding priorities to transformers

- addition of methods to support the admin ui such as list of test file extensions,
     property names for custom properties and 'uses'
   - NPE if on removeProperties(...) if no value is supplied
   - Allow * transformer name to be used in a pipeline property in a setProperties(...) call

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@55771 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2013-09-20 20:08:01 +00:00
parent c5fafd6ad4
commit 543eb16c2c
5 changed files with 110 additions and 31 deletions

View File

@@ -1,7 +1,7 @@
# Debug and Log buffer sizes
# ==========================
transformer.debug.entries=0
transformer.log.entries=50
transformer.log.entries=0
# Base setting for all transformers

View File

@@ -93,6 +93,21 @@ public interface TransformerConfigMBean
*/
public String testTransform(String transformerName, String sourceExtension, String targetExtension, String use);
/**
* Lists the names of the contexts or uses.
*/
public String[] getContextNames();
/**
* Lists custom (non default) property names.
*/
public String[] getCustomePropertyNames();
/**
* Lists the extensions of available test files.
*/
public String[] getTestFileExtensionsAndMimetypes();
/**
* Returns a description of each method and its parameters.
*/

View File

@@ -288,8 +288,11 @@ public class TransformerConfigMBeanImpl implements TransformerConfigMBean
{
try
{
propertyNames = nullDefaultParam(propertyNames);
return "Properties removed: "+
transformerConfig.removeProperties(nullDefaultParam(propertyNames));
(propertyNames == null
? 0
: transformerConfig.removeProperties(propertyNames));
}
catch (IllegalArgumentException e)
{
@@ -315,6 +318,38 @@ public class TransformerConfigMBeanImpl implements TransformerConfigMBean
}
}
@Override
public String[] getContextNames()
{
return new String[] {"", "doclib", "index", "webpreview", "syncRule", "asyncRule"};
}
@Override
public String[] getCustomePropertyNames()
{
List<String> propertyNames = new ArrayList<String>();
String[] lines = getProperties(false).split("\\n");
for (String line: lines)
{
if (!line.isEmpty() && !line.startsWith("#") && line.indexOf(" # default=") == -1)
{
int i = line.indexOf('=');
if (i != 0)
{
String propertyName = line.substring(0, i);
propertyNames.add(propertyName);
}
}
}
return propertyNames.toArray(new String[propertyNames.size()]);
}
@Override
public String[] getTestFileExtensionsAndMimetypes()
{
return transformerDebug.getTestFileExtensionsAndMimetypes();
}
/**
* Returns a full transformer name given a simple transformer name parameter.
* @param simpleTransformerName the name of the transformer without the
@@ -427,6 +462,15 @@ public class TransformerConfigMBeanImpl implements TransformerConfigMBean
" - transformerName to be checked. If blank all transformers are included\n" +
" - use or context in which the transformation will be used (\"doclib\",\n" +
" \"index\", \"webpreview\", \"syncRule\", \"asyncRule\"...) or blank for\n" +
" the default.";
" the default.\n"+
"\n" +
"getCustomePropertyNames()\n" +
" Lists custom (non default) property names\n" +
"\n" +
"getContextNames()\n" +
" Lists the names of the contexts or uses\n" +
"\n" +
"getTestFileExtensionsAndMimetypes()\n" +
" Lists the extensions of available test files";
}
}

View File

@@ -1353,14 +1353,53 @@ public class TransformerDebug
}.run(sourceExtension, targetExtension, use);
}
public String[] getTestFileExtensionsAndMimetypes()
{
List<String> sourceExtensions = new ArrayList<String>();
Collection<String> sourceMimetypes = mimetypeService.getMimetypes(null);
for (String sourceMimetype: sourceMimetypes)
{
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
if (loadQuickTestFile(sourceExtension) != null)
{
sourceExtensions.add(sourceExtension+" - "+sourceMimetype);
}
}
return sourceExtensions.toArray(new String[sourceExtensions.size()]);
}
/**
* Load one of the "The quick brown fox" files from the classpath.
* @param extension required, eg <b>txt</b> for the file quick.txt
* @return Returns a test resource loaded from the classpath or <tt>null</tt> if
* no resource could be found.
*/
private File loadQuickTestFile(String extension)
{
try
{
URL url = this.getClass().getClassLoader().getResource("quick/quick." + extension);
if (url == null)
{
return null;
}
return ResourceUtils.getFile(url);
}
catch (IOException e)
{
return null;
}
}
private abstract class TestTransform
{
String run(String sourceExtension, String targetExtension, String use)
{
String debug;
String sourceMimetype = getMimetype(sourceExtension, true);
String targetMimetype = getMimetype(targetExtension, false);
String sourceMimetype = getMimetype(sourceExtension, true);
File sourceFile = loadQuickTestFile(sourceExtension);
if (sourceFile == null)
{
@@ -1424,28 +1463,5 @@ public class TransformerDebug
}
protected abstract void transform(ContentReader reader, ContentWriter writer, TransformationOptions options);
/**
* Load one of the "The quick brown fox" files from the classpath.
* @param extension required, eg <b>txt</b> for the file quick.txt
* @return Returns a test resource loaded from the classpath or <tt>null</tt> if
* no resource could be found.
*/
private File loadQuickTestFile(String extension)
{
try
{
URL url = this.getClass().getClassLoader().getResource("quick/quick." + extension);
if (url == null)
{
return null;
}
return ResourceUtils.getFile(url);
}
catch (IOException e)
{
return null;
}
}
}
}

View File

@@ -18,6 +18,7 @@
*/
package org.alfresco.repo.content.transform;
import static org.alfresco.repo.content.transform.TransformerConfig.ANY;
import static org.alfresco.repo.content.transform.TransformerConfig.AVAILABLE;
import static org.alfresco.repo.content.transform.TransformerConfig.CONTENT;
import static org.alfresco.repo.content.transform.TransformerConfig.ERROR_TIME;
@@ -138,6 +139,8 @@ public class TransformerPropertySetter
allTransformerNames.add(TransformerConfig.DEFAULT_TRANSFORMER);
for (String transformerSimpleName: transformerReferences.keySet())
{
if (!ANY.equals(transformerSimpleName))
{
String name = TRANSFORMER+transformerSimpleName;
if (!allTransformerNames.contains(name))
@@ -147,6 +150,7 @@ public class TransformerPropertySetter
}
}
}
}
/**
* Removes transformer properties from the supplied multi line propertyNames.