Do the wiring

This commit is contained in:
Erik Knizat
2020-04-03 17:15:36 +01:00
parent 4a96e3aabd
commit fc96f9aa5f
13 changed files with 80 additions and 10 deletions

View File

@@ -50,6 +50,7 @@ import org.alfresco.transformer.probes.ProbeTestTransform;
import org.alfresco.transformer.transformers.AllInOneTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
@@ -74,7 +75,8 @@ public class AIOController extends AbstractTransformerController
TEST_DELAY
};
private AllInOneTransformer transformer = new AllInOneTransformer();
@Autowired
private AllInOneTransformer transformer;
@Override
public String getTransformerName()

View File

@@ -0,0 +1,47 @@
package org.alfresco.transformer;
import jdk.jfr.Name;
import org.alfresco.transform.client.model.config.TransformConfig;
import org.alfresco.transform.client.registry.TransformServiceRegistry;
import org.alfresco.transformer.transformers.AllInOneTransformer;
import org.alfresco.transformer.transformers.Transformer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
@Configuration
public class AIOCustomConfig
{
@Bean("AllInOneTransformer")
public Transformer aioTransformer()
{
return new AllInOneTransformer();
}
/**
*
* @return Override the TransformRegistryImpl used in {@link AbstractTransformerController}
*/
@Bean
@Primary
public TransformServiceRegistry transformRegistryOverride()
{
return new TransformRegistryImpl()
{
@Autowired
@Qualifier("AllInOneTransformer")
Transformer transformer;
@Override
TransformConfig getTransformConfig()
{
return transformer.getTransformConfig();
}
};
}
}

View File

@@ -32,14 +32,20 @@ import java.io.IOException;
import org.alfresco.transform.client.model.TransformRequest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@WebMvcTest(AIOController.class)
@Import(AIOCustomConfig.class)
public class AIOControllerTest //extends AbstractTransformerControllerTest
{
@Autowired
AIOController aioController;
//@Override
protected void mockTransformCommand(String sourceExtension, String targetExtension, String sourceMimetype,
boolean readTargetFileBytes) throws IOException {
@@ -62,6 +68,6 @@ public class AIOControllerTest //extends AbstractTransformerControllerTest
@Test
public void emptyTest()
{
aioController.info();
}
}

View File

@@ -62,6 +62,9 @@ public class AllInOneTransformer implements Transformer
{
this.registerTransformer(new MiscAdapter());
this.registerTransformer(new TikaAdapter());
this.registerTransformer(new ImageMagickAdapter());
this.registerTransformer(new LibreOfficeAdapter());
this.registerTransformer(new PdfRendererAdapter());
}
catch (Exception e)
{

View File

@@ -37,7 +37,7 @@ import org.alfresco.transformer.PdfRendererOptionsBuilder;
public class PdfRendererAdapter extends AbstractTransformer
{
private static String CONFIG_PREFIX = "pdf-renderer";
private static String CONFIG_PREFIX = "pdfrenderer";
private PdfRendererCommandExecutor pdfExecutor;
//TODO move key strings to a central class

View File

@@ -1,2 +1,5 @@
queue:
engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.imagemagick.acs}
engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.imagemagick.acs}
transform:
config:
location: classpath:imagemagick_engine_config.json

View File

@@ -1,2 +1,5 @@
queue:
engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.libreoffice.acs}
engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.libreoffice.acs}
transform:
config:
location: classpath:libreoffice_engine_config.json

View File

@@ -1,2 +1,5 @@
queue:
engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.alfresco-pdf-renderer.acs}
engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.alfresco-pdf-renderer.acs}
transform:
config:
location: classpath:pdfrenderer_config.json

View File

@@ -115,6 +115,7 @@ public abstract class AbstractTransformerController implements TransformControll
@GetMapping(value = "/transform/config")
public ResponseEntity<TransformConfig> info()
{
// TODO - This cast should not be here
logger.info("GET Transform Config.");
final TransformConfig transformConfig =
((TransformRegistryImpl) transformRegistry).getTransformConfig();

View File

@@ -52,9 +52,11 @@ public class TransformRegistryImpl extends AbstractTransformRegistry
{
private static final Logger log = LoggerFactory.getLogger(TransformRegistryImpl.class);
private static final String ENGINE_CONFIG_JSON = "classpath:engine_config.json";
// TODO - do we really need this string?
@Value("${transform.config.location:classpath:engine_config.json}")
private String locationFromProperty;
@Value(ENGINE_CONFIG_JSON)
@Value("${transform.config.location:classpath:engine_config.json}")
private Resource engineConfig;
// Holds the structures used by AbstractTransformRegistry to look up what is supported.
@@ -72,7 +74,7 @@ public class TransformRegistryImpl extends AbstractTransformRegistry
catch (IOException e)
{
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
"Could not read " + ENGINE_CONFIG_JSON, e);
"Could not read " + engineConfig.getDescription(), e);
}
}
@@ -80,7 +82,7 @@ public class TransformRegistryImpl extends AbstractTransformRegistry
public void afterPropertiesSet()
{
TransformConfig transformConfig = getTransformConfig();
registerAll(transformConfig, null, ENGINE_CONFIG_JSON);
registerAll(transformConfig, null, locationFromProperty);
}
@Override