mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-05-12 17:04:48 +00:00
ATS-777 / REPO-4334: Move metadata extraction into T-Engines (#256)
* REPO-4334 Move metadata extraction into T-Engines - new "transformImpl" required (processTransform deprecated) - JavaDoc Co-authored-by: Jan Vonka <jan.vonka@alfresco.com>
This commit is contained in:
parent
401fcaf2ca
commit
d495459b9b
@ -82,7 +82,7 @@ public class AIOController extends AbstractTransformerController
|
||||
{
|
||||
Map<String, String> parameters = new HashMap<>();
|
||||
parameters.put(SOURCE_ENCODING, "UTF-8");
|
||||
transform("html", MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, parameters, sourceFile, targetFile);
|
||||
transformImpl("html", MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, parameters, sourceFile, targetFile);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -96,8 +96,8 @@ public class AIOController extends AbstractTransformerController
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void transform(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
{
|
||||
logger.debug("Processing transform with: transformName; '{}', sourceFile '{}', targetFile '{}', transformOptions" +
|
||||
" {}", transformName, sourceFile, targetFile, transformOptions);
|
||||
|
@ -110,7 +110,7 @@ public class ImageMagickController extends AbstractTransformerController
|
||||
@Override
|
||||
protected void executeTransformCommand(File sourceFile, File targetFile)
|
||||
{
|
||||
transform(null, null, null, Collections.emptyMap(), sourceFile, targetFile);
|
||||
transformImpl(null, null, null, Collections.emptyMap(), sourceFile, targetFile);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -123,8 +123,8 @@ public class ImageMagickController extends AbstractTransformerController
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void transform(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
{
|
||||
commandExecutor.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class LibreOfficeController extends AbstractTransformerController
|
||||
@Override
|
||||
protected void executeTransformCommand(File sourceFile, File targetFile)
|
||||
{
|
||||
transform(null, null, null, Collections.emptyMap(), sourceFile, targetFile);
|
||||
transformImpl(null, null, null, Collections.emptyMap(), sourceFile, targetFile);
|
||||
javaExecutor.call(sourceFile, targetFile);
|
||||
}
|
||||
};
|
||||
@ -110,8 +110,8 @@ public class LibreOfficeController extends AbstractTransformerController
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void transform(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
{
|
||||
javaExecutor.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
}
|
||||
|
@ -74,14 +74,14 @@ public class MiscController extends AbstractTransformerController
|
||||
{
|
||||
Map<String, String> parameters = new HashMap<>();
|
||||
parameters.put(SOURCE_ENCODING, "UTF-8");
|
||||
transform("html", MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, parameters, sourceFile, targetFile);
|
||||
transformImpl("html", MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, parameters, sourceFile, targetFile);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void transform(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
{
|
||||
transformOptions.put(TRANSFORM_NAME_PARAMETER, transformName);
|
||||
transformer.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
|
@ -97,7 +97,7 @@ public class AlfrescoPdfRendererController extends AbstractTransformerController
|
||||
@Override
|
||||
protected void executeTransformCommand(File sourceFile, File targetFile)
|
||||
{
|
||||
transform(null, null, null, Collections.emptyMap(), sourceFile, targetFile);
|
||||
transformImpl(null, null, null, Collections.emptyMap(), sourceFile, targetFile);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -110,8 +110,8 @@ public class AlfrescoPdfRendererController extends AbstractTransformerController
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void transform(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
{
|
||||
commandExecutor.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
}
|
||||
|
@ -92,14 +92,14 @@ public class TikaController extends AbstractTransformerController
|
||||
@Override
|
||||
protected void executeTransformCommand(File sourceFile, File targetFile)
|
||||
{
|
||||
transform(PDF_BOX, MIMETYPE_PDF, MIMETYPE_TEXT_PLAIN, Collections.emptyMap(), sourceFile, targetFile);
|
||||
transformImpl(PDF_BOX, MIMETYPE_PDF, MIMETYPE_TEXT_PLAIN, Collections.emptyMap(), sourceFile, targetFile);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void transform(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
{
|
||||
transformOptions.put(TRANSFORM_NAME_PARAMETER, transformName);
|
||||
javaExecutor.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
|
@ -87,7 +87,9 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
|
||||
import static org.springframework.util.StringUtils.getFilenameExtension;
|
||||
|
||||
/**
|
||||
* <p>Abstract Controller, provides structure and helper methods to sub-class transformer controllers.</p>
|
||||
* <p>Abstract Controller, provides structure and helper methods to sub-class transformer controllers. Sub classes
|
||||
* should implement {@link #transformImpl(String, String, String, Map, File, File)} and unimplemented methods from
|
||||
* {@link TransformController}.</p>
|
||||
*
|
||||
* <p>Status Codes:</p>
|
||||
* <ul>
|
||||
@ -168,7 +170,7 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
|
||||
Map<String, String> transformOptions = getTransformOptions(requestParameters);
|
||||
String transformName = getTransformerName(sourceMimetype, targetMimetype, requestTransformName, sourceFile, transformOptions);
|
||||
transform(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
transformImpl(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
|
||||
final ResponseEntity<Resource> body = createAttachment(targetFilename, targetFile);
|
||||
LogEntry.setTargetSize(targetFile.length());
|
||||
@ -264,8 +266,12 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
// Run the transformation
|
||||
try
|
||||
{
|
||||
processTransform(sourceFile, targetFile, request.getSourceMediaType(),
|
||||
request.getTargetMediaType(), request.getTransformRequestOptions(), timeout);
|
||||
|
||||
String targetMimetype = request.getTargetMediaType();
|
||||
String sourceMimetype = request.getSourceMediaType();
|
||||
Map<String, String> transformOptions = request.getTransformRequestOptions();
|
||||
String transformName = getTransformerName(sourceFile, sourceMimetype, targetMimetype, transformOptions);
|
||||
transformImpl(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
}
|
||||
catch (TransformException e)
|
||||
{
|
||||
@ -403,21 +409,6 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void processTransform(final File sourceFile, final File targetFile,
|
||||
final String sourceMimetype, final String targetMimetype,
|
||||
final Map<String, String> transformOptions, final Long timeout)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(
|
||||
"Processing request with: sourceFile '{}', targetFile '{}', transformOptions" +
|
||||
" '{}', timeout {} ms", sourceFile, targetFile, transformOptions, timeout);
|
||||
}
|
||||
|
||||
String transformName = getTransformerName(sourceFile, sourceMimetype, targetMimetype, transformOptions);
|
||||
transform(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
}
|
||||
|
||||
private String getTransformerName(String sourceMimetype, String targetMimetype,
|
||||
String requestTransformName, File sourceFile,
|
||||
Map<String, String> transformOptions)
|
||||
@ -483,7 +474,4 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
}
|
||||
return transformOptions;
|
||||
}
|
||||
|
||||
protected abstract void transform(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile);
|
||||
}
|
||||
|
@ -63,37 +63,86 @@ public interface TransformController
|
||||
{
|
||||
Logger logger = LoggerFactory.getLogger(TransformController.class);
|
||||
|
||||
/**
|
||||
* Should be overridden in subclasses to initiate the transformation.
|
||||
*
|
||||
* @param transformName the name of the transformer in the engine_config.json file
|
||||
* @param sourceMimetype mimetype of the source
|
||||
* @param targetMimetype mimetype of the target
|
||||
* @param transformOptions transform options from the client
|
||||
* @param sourceFile the source file
|
||||
* @param targetFile the target file
|
||||
*/
|
||||
void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile);
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #transformImpl(String, String, String, Map, File, File)} and timeout should be part of
|
||||
* the transformOptions created from the TransformRequest.
|
||||
*/
|
||||
@Deprecated
|
||||
ResponseEntity<TransformReply> transform(TransformRequest transformRequest, Long timeout);
|
||||
|
||||
void processTransform(final File sourceFile, final File targetFile,
|
||||
/**
|
||||
* @deprecated use {@link #transformImpl(String, String, String, Map, File, File)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default void processTransform(final File sourceFile, final File targetFile,
|
||||
final String sourceMimetype, final String targetMimetype,
|
||||
final Map<String, String> transformOptions, final Long timeout);
|
||||
final Map<String, String> transformOptions, final Long timeout)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a friendly name for the T-Engine.
|
||||
*/
|
||||
String getTransformerName();
|
||||
|
||||
/**
|
||||
* Provides the Kubernetes pod probes.
|
||||
*/
|
||||
ProbeTestTransform getProbeTestTransform();
|
||||
|
||||
/**
|
||||
* Method used by Kubernetes pod probes.
|
||||
*/
|
||||
default String probe(HttpServletRequest request, boolean isLiveProbe)
|
||||
{
|
||||
return getProbeTestTransform().doTransformOrNothing(request, isLiveProbe);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a string that may be used by clients in debug. It need not include the version.
|
||||
*/
|
||||
@RequestMapping("/version")
|
||||
@ResponseBody
|
||||
String version();
|
||||
|
||||
/**
|
||||
* @return the name of a template to test the T-Engine. Defaults to {@code "transformForm"}.
|
||||
*/
|
||||
@GetMapping("/")
|
||||
default String transformForm(Model model)
|
||||
{
|
||||
return "transformForm"; // the name of the template
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of a template to display when there is an error when using the test UI for the T-Engine.
|
||||
* Defaults to {@code "error"}.
|
||||
* @See #transformForm
|
||||
*/
|
||||
@GetMapping("/error")
|
||||
default String error()
|
||||
{
|
||||
return "error"; // the name of the template
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of a template to display log messages when using the test UI for the T-Engine.
|
||||
* Defaults to {@code "log"}.
|
||||
* @See #transformForm
|
||||
*/
|
||||
@GetMapping("/log")
|
||||
default String log(Model model)
|
||||
{
|
||||
@ -106,6 +155,9 @@ public interface TransformController
|
||||
return "log"; // the name of the template
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used by Kubernetes ready pod probes.
|
||||
*/
|
||||
@GetMapping("/ready")
|
||||
@ResponseBody
|
||||
default String ready(HttpServletRequest request)
|
||||
@ -113,6 +165,9 @@ public interface TransformController
|
||||
return probe(request, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used by Kubernetes live pod probes.
|
||||
*/
|
||||
@GetMapping("/live")
|
||||
@ResponseBody
|
||||
default String live(HttpServletRequest request)
|
||||
|
Loading…
x
Reference in New Issue
Block a user