mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-07-31 17:38:33 +00:00
ATS-545: Code formatting and small improvements (#113)
This commit is contained in:
@@ -116,7 +116,8 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
public ResponseEntity<TransformConfig> info()
|
||||
{
|
||||
logger.info("GET Transform Config.");
|
||||
TransformConfig transformConfig = ((TransformRegistryImpl)transformRegistry).getTransformConfig();
|
||||
final TransformConfig transformConfig =
|
||||
((TransformRegistryImpl) transformRegistry).getTransformConfig();
|
||||
return new ResponseEntity<>(transformConfig, OK);
|
||||
}
|
||||
|
||||
@@ -337,15 +338,16 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected String getTransformerName(File sourceFile, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions)
|
||||
protected String getTransformerName(final File sourceFile, final String sourceMimetype,
|
||||
final String targetMimetype, final Map<String, String> transformOptions)
|
||||
{
|
||||
long sourceSizeInBytes = sourceFile.length();
|
||||
String transformerName = transformRegistry.findTransformerName(sourceMimetype, sourceSizeInBytes,
|
||||
targetMimetype, transformOptions, null);
|
||||
final long sourceSizeInBytes = sourceFile.length();
|
||||
final String transformerName = transformRegistry.findTransformerName(sourceMimetype,
|
||||
sourceSizeInBytes, targetMimetype, transformOptions, null);
|
||||
if (transformerName == null)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST.value(), "No transforms were able to handle the request");
|
||||
throw new TransformException(BAD_REQUEST.value(),
|
||||
"No transforms were able to handle the request");
|
||||
}
|
||||
return transformerName;
|
||||
}
|
||||
@@ -354,11 +356,12 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
{
|
||||
if (namesAndValues.length % 2 != 0)
|
||||
{
|
||||
logger.error("Incorrect number of parameters. Should have an even number as they are names and values.");
|
||||
logger.error(
|
||||
"Incorrect number of parameters. Should have an even number as they are names and values.");
|
||||
}
|
||||
|
||||
Map<String, String> transformOptions = new HashMap<>();
|
||||
for (int i=0; i<namesAndValues.length; i+=2)
|
||||
for (int i = 0; i < namesAndValues.length; i += 2)
|
||||
{
|
||||
String name = namesAndValues[i].toString();
|
||||
Object value = namesAndValues[i + 1];
|
||||
|
@@ -25,7 +25,15 @@
|
||||
*/
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.alfresco.transform.client.model.config.TransformConfig;
|
||||
import org.alfresco.transform.client.registry.AbstractTransformRegistry;
|
||||
import org.alfresco.transform.client.registry.TransformCache;
|
||||
@@ -35,13 +43,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* Used by clients to work out if a transformation is supported based on the engine_config.json.
|
||||
@@ -70,7 +72,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 " + ENGINE_CONFIG_JSON, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -28,8 +28,8 @@ package org.alfresco.transformer.config;
|
||||
|
||||
import org.alfresco.transform.client.model.TransformRequestValidator;
|
||||
import org.alfresco.transform.client.registry.TransformServiceRegistry;
|
||||
import org.alfresco.transformer.TransformRegistryImpl;
|
||||
import org.alfresco.transformer.TransformInterceptor;
|
||||
import org.alfresco.transformer.TransformRegistryImpl;
|
||||
import org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -44,8 +44,9 @@ public class WebApplicationConfig implements WebMvcConfigurer
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry)
|
||||
{
|
||||
registry.addInterceptor(transformInterceptor()).addPathPatterns("/transform", "/live",
|
||||
"/ready");
|
||||
registry
|
||||
.addInterceptor(transformInterceptor())
|
||||
.addPathPatterns("/transform", "/live", "/ready");
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@@ -37,18 +37,18 @@ public class Util
|
||||
* @param param String to be converted
|
||||
* @return Null if param is null or converted value as {@link Integer}
|
||||
*/
|
||||
public static Integer stringToInteger(String param)
|
||||
public static Integer stringToInteger(final String param)
|
||||
{
|
||||
return param == null ? null : Integer.parseInt(param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely converts a {@link String} to an {@link Integer}
|
||||
* Safely converts a {@link String} to a {@link Boolean}
|
||||
*
|
||||
* @param param String to be converted
|
||||
* @return Null if param is null or converted value as {@link Boolean}
|
||||
*/
|
||||
public static Boolean stringToBoolean(String param)
|
||||
public static Boolean stringToBoolean(final String param)
|
||||
{
|
||||
return param == null ? null : Boolean.parseBoolean(param);
|
||||
}
|
||||
|
@@ -95,7 +95,7 @@ public abstract class AbstractHttpRequestTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noTargetExtensionError() throws Exception
|
||||
public void noTargetExtensionError()
|
||||
{
|
||||
assertMissingParameter("targetExtension");
|
||||
}
|
||||
@@ -122,10 +122,11 @@ public abstract class AbstractHttpRequestTest
|
||||
sendTranformationRequest(entity, errorMessage);
|
||||
}
|
||||
|
||||
protected void sendTranformationRequest(HttpEntity<LinkedMultiValueMap<String, Object>> entity, String errorMessage)
|
||||
protected void sendTranformationRequest(
|
||||
final HttpEntity<LinkedMultiValueMap<String, Object>> entity, final String errorMessage)
|
||||
{
|
||||
ResponseEntity<String> response = restTemplate.exchange("/transform", POST, entity,
|
||||
String.class, "");
|
||||
final ResponseEntity<String> response = restTemplate.exchange("/transform", POST, entity,
|
||||
String.class, "");
|
||||
assertEquals(errorMessage, getErrorMessage(response.getBody()));
|
||||
}
|
||||
|
||||
|
@@ -59,8 +59,8 @@ import org.alfresco.transform.client.model.config.TransformConfig;
|
||||
import org.alfresco.transform.client.model.config.TransformOption;
|
||||
import org.alfresco.transform.client.model.config.TransformOptionGroup;
|
||||
import org.alfresco.transform.client.model.config.TransformOptionValue;
|
||||
import org.alfresco.transform.client.registry.TransformServiceRegistry;
|
||||
import org.alfresco.transform.client.model.config.Transformer;
|
||||
import org.alfresco.transform.client.registry.TransformServiceRegistry;
|
||||
import org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient;
|
||||
import org.alfresco.transformer.probes.ProbeTestTransform;
|
||||
import org.junit.Test;
|
||||
@@ -68,7 +68,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
@@ -111,7 +110,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
* The expected result. Taken resting target quick file's bytes.
|
||||
*
|
||||
* Note: These checks generally don't work on Windows (Mac and Linux are okay). Possibly to do with byte order
|
||||
* loading.
|
||||
* loading.
|
||||
*/
|
||||
protected byte[] expectedTargetFileBytes;
|
||||
|
||||
@@ -347,8 +346,8 @@ public abstract class AbstractTransformerControllerTest
|
||||
.readValue(new ClassPathResource("engine_config.json").getFile(),
|
||||
TransformConfig.class);
|
||||
|
||||
ReflectionTestUtils.setField(transformRegistry,"engineConfig",
|
||||
new ClassPathResource("engine_config.json"));
|
||||
ReflectionTestUtils.setField(transformRegistry, "engineConfig",
|
||||
new ClassPathResource("engine_config.json"));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
@@ -366,8 +365,8 @@ public abstract class AbstractTransformerControllerTest
|
||||
{
|
||||
TransformConfig expectedResult = buildCompleteTransformConfig();
|
||||
|
||||
ReflectionTestUtils.setField(transformRegistry,"engineConfig",
|
||||
new ClassPathResource("engine_config_with_duplicates.json"));
|
||||
ReflectionTestUtils.setField(transformRegistry, "engineConfig",
|
||||
new ClassPathResource("engine_config_with_duplicates.json"));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
@@ -393,8 +392,8 @@ public abstract class AbstractTransformerControllerTest
|
||||
TransformConfig expectedResult = new TransformConfig();
|
||||
expectedResult.setTransformers(ImmutableList.of(transformer));
|
||||
|
||||
ReflectionTestUtils.setField(transformRegistry,"engineConfig",
|
||||
new ClassPathResource("engine_config_incomplete.json"));
|
||||
ReflectionTestUtils.setField(transformRegistry, "engineConfig",
|
||||
new ClassPathResource("engine_config_incomplete.json"));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
@@ -416,8 +415,8 @@ public abstract class AbstractTransformerControllerTest
|
||||
TransformConfig expectedResult = new TransformConfig();
|
||||
expectedResult.setTransformers(ImmutableList.of(transformer));
|
||||
|
||||
ReflectionTestUtils.setField(transformRegistry,"engineConfig",
|
||||
new ClassPathResource("engine_config_no_transform_options.json"));
|
||||
ReflectionTestUtils.setField(transformRegistry, "engineConfig",
|
||||
new ClassPathResource("engine_config_no_transform_options.json"));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
|
Reference in New Issue
Block a user