mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
ACS-2498 Switch to using a configVersion parameter on the /transform/config endpoint (#530)
* Fixed the config returned by the AIO as it did not include the coreVersion even though the individual ones did.
This commit is contained in:
@@ -64,7 +64,10 @@ import java.util.Map;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static org.alfresco.transform.client.model.config.CoreVersionDecorator.setOrClearCoreVersion;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.INCLUDE_CORE_VERSION;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION_DEFAULT;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG;
|
||||
import static org.alfresco.transformer.fs.FileManager.TempFileProvider.createTempFile;
|
||||
import static org.alfresco.transformer.fs.FileManager.buildFile;
|
||||
import static org.alfresco.transformer.fs.FileManager.createAttachment;
|
||||
@@ -141,17 +144,17 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
@Autowired
|
||||
private TransformerDebug transformerDebug;
|
||||
|
||||
@GetMapping(value = "/transform/config")
|
||||
@GetMapping(value = ENDPOINT_TRANSFORM_CONFIG)
|
||||
public ResponseEntity<TransformConfig> info(
|
||||
@RequestParam(value = INCLUDE_CORE_VERSION, required = false) Boolean includeCoreVersion)
|
||||
@RequestParam(value = CONFIG_VERSION, defaultValue = CONFIG_VERSION_DEFAULT) int configVersion)
|
||||
{
|
||||
logger.info("GET Transform Config" + (includeCoreVersion != null && includeCoreVersion ? " including coreVersion" : ""));
|
||||
logger.info("GET Transform Config version: " + configVersion);
|
||||
TransformConfig transformConfig = ((TransformRegistryImpl) transformRegistry).getTransformConfig();
|
||||
transformConfig = setOrClearCoreVersion(transformConfig, includeCoreVersion);
|
||||
transformConfig = setOrClearCoreVersion(transformConfig, configVersion);
|
||||
return new ResponseEntity<>(transformConfig, OK);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/transform", consumes = MULTIPART_FORM_DATA_VALUE)
|
||||
@PostMapping(value = ENDPOINT_TRANSFORM, consumes = MULTIPART_FORM_DATA_VALUE)
|
||||
public ResponseEntity<Resource> transform(HttpServletRequest request,
|
||||
@RequestParam(FILE) MultipartFile sourceMultipartFile,
|
||||
@RequestParam(TARGET_EXTENSION) String targetExtension,
|
||||
@@ -206,7 +209,7 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
* @param timeout Transformation timeout
|
||||
* @return A transformation reply
|
||||
*/
|
||||
@PostMapping(value = "/transform", produces = APPLICATION_JSON_VALUE)
|
||||
@PostMapping(value = ENDPOINT_TRANSFORM, produces = APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public ResponseEntity<TransformReply> transform(@RequestBody TransformRequest request,
|
||||
@RequestParam(value = "timeout", required = false) Long timeout)
|
||||
|
@@ -38,6 +38,8 @@ import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
|
||||
@Configuration
|
||||
public class WebApplicationConfig implements WebMvcConfigurer
|
||||
{
|
||||
@@ -46,7 +48,7 @@ public class WebApplicationConfig implements WebMvcConfigurer
|
||||
{
|
||||
registry
|
||||
.addInterceptor(transformInterceptor())
|
||||
.addPathPatterns("/transform", "/live", "/ready");
|
||||
.addPathPatterns(ENDPOINT_TRANSFORM, "/live", "/ready");
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
@@ -26,6 +26,7 @@
|
||||
*/
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
|
||||
@@ -125,7 +126,7 @@ public abstract class AbstractHttpRequestTest
|
||||
protected void sendTranformationRequest(
|
||||
final HttpEntity<LinkedMultiValueMap<String, Object>> entity, final String errorMessage)
|
||||
{
|
||||
final ResponseEntity<String> response = restTemplate.exchange("/transform", POST, entity,
|
||||
final ResponseEntity<String> response = restTemplate.exchange(ENDPOINT_TRANSFORM, POST, entity,
|
||||
String.class, "");
|
||||
assertEquals(errorMessage, getErrorMessage(response.getBody()));
|
||||
}
|
||||
|
@@ -27,6 +27,9 @@
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG_LATEST;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
@@ -105,7 +108,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
protected TransformServiceRegistry transformRegistry;
|
||||
|
||||
@Value("${transform.core.version}")
|
||||
private String currentCoreVersion;
|
||||
private String coreVersion;
|
||||
|
||||
protected String sourceExtension;
|
||||
protected String targetExtension;
|
||||
@@ -213,7 +216,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
|
||||
String... params)
|
||||
{
|
||||
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.multipart("/transform").file(
|
||||
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.multipart(ENDPOINT_TRANSFORM).file(
|
||||
sourceFile);
|
||||
|
||||
if (params.length % 2 != 0)
|
||||
@@ -256,7 +259,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
public void simpleTransformTest() throws Exception
|
||||
{
|
||||
mockMvc.perform(
|
||||
mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension))
|
||||
mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
@@ -267,7 +270,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
public void testDelayTest() throws Exception
|
||||
{
|
||||
long start = System.currentTimeMillis();
|
||||
mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension,
|
||||
mockMvc.perform(mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension,
|
||||
"testDelay", "400"))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
@@ -282,7 +285,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
@Test
|
||||
public void noTargetFileTest() throws Exception
|
||||
{
|
||||
mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", "xxx"))
|
||||
mockMvc.perform(mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", "xxx"))
|
||||
.andExpect(status().is(INTERNAL_SERVER_ERROR.value()));
|
||||
}
|
||||
|
||||
@@ -294,7 +297,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
expectedSourceFileBytes);
|
||||
|
||||
mockMvc.perform(
|
||||
mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension))
|
||||
mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
@@ -309,7 +312,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
expectedSourceFileBytes);
|
||||
|
||||
mockMvc.perform(
|
||||
mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension))
|
||||
mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
@@ -323,7 +326,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
sourceFile = new MockMultipartFile("file", "abc/", sourceMimetype, expectedSourceFileBytes);
|
||||
|
||||
mockMvc.perform(
|
||||
mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension))
|
||||
mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension))
|
||||
.andExpect(status().is(BAD_REQUEST.value()))
|
||||
.andExpect(status().reason(containsString("The source filename was not supplied")));
|
||||
}
|
||||
@@ -334,14 +337,14 @@ public abstract class AbstractTransformerControllerTest
|
||||
sourceFile = new MockMultipartFile("file", "", sourceMimetype, expectedSourceFileBytes);
|
||||
|
||||
mockMvc.perform(
|
||||
mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension))
|
||||
mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension))
|
||||
.andExpect(status().is(BAD_REQUEST.value()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noTargetExtensionTest() throws Exception
|
||||
{
|
||||
mockMvc.perform(mockMvcRequest("/transform", sourceFile))
|
||||
mockMvc.perform(mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile))
|
||||
.andExpect(status().is(BAD_REQUEST.value()))
|
||||
.andExpect(status().reason(
|
||||
containsString("Request parameter 'targetExtension' is missing")));
|
||||
@@ -386,7 +389,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
String tr = objectMapper.writeValueAsString(transformRequest);
|
||||
String transformationReplyAsString = mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post("/transform")
|
||||
.post(ENDPOINT_TRANSFORM)
|
||||
.header(ACCEPT, APPLICATION_JSON_VALUE)
|
||||
.header(CONTENT_TYPE, APPLICATION_JSON_VALUE)
|
||||
.content(tr))
|
||||
@@ -415,13 +418,13 @@ public abstract class AbstractTransformerControllerTest
|
||||
TransformConfig expectedTransformConfig = objectMapper
|
||||
.readValue(getTestFile(getEngineConfigName(), true),
|
||||
TransformConfig.class);
|
||||
expectedTransformConfig.getTransformers().forEach(transformer -> transformer.setCoreVersion(currentCoreVersion));
|
||||
expectedTransformConfig.getTransformers().forEach(transformer -> transformer.setCoreVersion(coreVersion));
|
||||
|
||||
ReflectionTestUtils.setField(transformRegistry, "engineConfig",
|
||||
new ClassPathResource(getEngineConfigName()));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config?includeCoreVersion=true"))
|
||||
.perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG_LATEST))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
@@ -442,7 +445,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
new ClassPathResource(getEngineConfigName()));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
.perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
@@ -460,7 +463,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
new ClassPathResource("engine_config_with_duplicates.json"));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
.perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
@@ -487,7 +490,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
new ClassPathResource("engine_config_incomplete.json"));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
.perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
@@ -510,7 +513,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
new ClassPathResource("engine_config_no_transform_options.json"));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
.perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2019 Alfresco Software, Ltd. All rights reserved.
|
||||
* Copyright 2015-2022 Alfresco Software, Ltd. All rights reserved.
|
||||
*
|
||||
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||
* pursuant to a written agreement and any use of this program without such an
|
||||
@@ -8,6 +8,7 @@
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -63,6 +64,6 @@ public class EngineClient
|
||||
|
||||
final HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(body, headers);
|
||||
|
||||
return REST_TEMPLATE.postForEntity(engineUrl + "/transform", entity, Resource.class);
|
||||
return REST_TEMPLATE.postForEntity(engineUrl + ENDPOINT_TRANSFORM, entity, Resource.class);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user