From cd947c25544559eb2b4e52bc32ed419c12a8c0d8 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com.> Date: Mon, 6 Jan 2025 12:38:13 +0000 Subject: [PATCH] formatting --- .../software/SPDF/SPdfApplication.java | 12 +++--- .../SPDF/config/ConfigInitializer.java | 4 -- .../SPDF/config/EndpointConfiguration.java | 38 +++++++++---------- .../config/YamlPropertySourceFactory.java | 20 +++++----- .../SPDF/model/ApplicationProperties.java | 5 +-- .../software/SPDF/utils/GeneralUtils.java | 17 +++++---- 6 files changed, 46 insertions(+), 50 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/SPdfApplication.java b/src/main/java/stirling/software/SPDF/SPdfApplication.java index 752c9801..eabe017c 100644 --- a/src/main/java/stirling/software/SPDF/SPdfApplication.java +++ b/src/main/java/stirling/software/SPDF/SPdfApplication.java @@ -78,14 +78,14 @@ public class SPdfApplication { props.put("spring.main.web-application-type", "servlet"); } app.setAdditionalProfiles("default"); - + ConfigInitializer initializer = new ConfigInitializer(); try { - initializer.ensureConfigExists(); - } catch (IOException | URISyntaxException e) { - log.error("Error initialising configuration", e); - } - + initializer.ensureConfigExists(); + } catch (IOException | URISyntaxException e) { + log.error("Error initialising configuration", e); + } + Map propertyFiles = new HashMap<>(); // External config files log.info("Settings file: {}", InstallationPathConfig.getSettingsPath()); diff --git a/src/main/java/stirling/software/SPDF/config/ConfigInitializer.java b/src/main/java/stirling/software/SPDF/config/ConfigInitializer.java index 6598ff06..b8c101af 100644 --- a/src/main/java/stirling/software/SPDF/config/ConfigInitializer.java +++ b/src/main/java/stirling/software/SPDF/config/ConfigInitializer.java @@ -16,16 +16,12 @@ import org.simpleyaml.configuration.comments.CommentType; import org.simpleyaml.configuration.file.YamlFile; import org.simpleyaml.configuration.implementation.SimpleYamlImplementation; import org.simpleyaml.configuration.implementation.snakeyaml.lib.DumperOptions; -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; import lombok.extern.slf4j.Slf4j; @Slf4j public class ConfigInitializer { - - public void ensureConfigExists() throws IOException, URISyntaxException { // Define the path to the external config directory Path destPath = Paths.get(InstallationPathConfig.getSettingsPath()); diff --git a/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java b/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java index 50fb4d04..967c6063 100644 --- a/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java +++ b/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java @@ -266,28 +266,28 @@ public class EndpointConfiguration { } private void processEnvironmentConfigs() { - if(applicationProperties != null && applicationProperties.getEndpoints() != null) { - List endpointsToRemove = applicationProperties.getEndpoints().getToRemove(); - List groupsToRemove = applicationProperties.getEndpoints().getGroupsToRemove(); - - if (!bookAndHtmlFormatsInstalled) { - if(groupsToRemove == null) { - groupsToRemove = new ArrayList<>(); - } - groupsToRemove.add("Calibre"); - } - if (endpointsToRemove != null) { - for (String endpoint : endpointsToRemove) { - disableEndpoint(endpoint.trim()); - } - } + if (applicationProperties != null && applicationProperties.getEndpoints() != null) { + List endpointsToRemove = applicationProperties.getEndpoints().getToRemove(); + List groupsToRemove = applicationProperties.getEndpoints().getGroupsToRemove(); - if (groupsToRemove != null) { - for (String group : groupsToRemove) { - disableGroup(group.trim()); + if (!bookAndHtmlFormatsInstalled) { + if (groupsToRemove == null) { + groupsToRemove = new ArrayList<>(); + } + groupsToRemove.add("Calibre"); + } + if (endpointsToRemove != null) { + for (String endpoint : endpointsToRemove) { + disableEndpoint(endpoint.trim()); + } + } + + if (groupsToRemove != null) { + for (String group : groupsToRemove) { + disableGroup(group.trim()); + } } } - } } public Set getEndpointsForGroup(String group) { diff --git a/src/main/java/stirling/software/SPDF/config/YamlPropertySourceFactory.java b/src/main/java/stirling/software/SPDF/config/YamlPropertySourceFactory.java index 5f655d54..e2818e89 100644 --- a/src/main/java/stirling/software/SPDF/config/YamlPropertySourceFactory.java +++ b/src/main/java/stirling/software/SPDF/config/YamlPropertySourceFactory.java @@ -11,14 +11,14 @@ import org.springframework.core.io.support.PropertySourceFactory; public class YamlPropertySourceFactory implements PropertySourceFactory { - @Override - public PropertySource createPropertySource(String name, EncodedResource encodedResource) - throws IOException { - YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); - factory.setResources(encodedResource.getResource()); - Properties properties = factory.getObject(); - - return new PropertiesPropertySource( - encodedResource.getResource().getFilename(), properties); - } + @Override + public PropertySource createPropertySource(String name, EncodedResource encodedResource) + throws IOException { + YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); + factory.setResources(encodedResource.getResource()); + Properties properties = factory.getObject(); + + return new PropertiesPropertySource( + encodedResource.getResource().getFilename(), properties); + } } diff --git a/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java b/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java index d37eaba5..9ff700c9 100644 --- a/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java +++ b/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java @@ -15,7 +15,6 @@ import java.util.List; import java.util.stream.Collectors; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; @@ -66,9 +65,9 @@ public class ApplicationProperties { PropertySource propertySource = new YamlPropertySourceFactory().createPropertySource(null, encodedResource); environment.getPropertySources().addFirst(propertySource); - + log.debug("Loaded properties: " + propertySource.getSource()); - + return propertySource; } diff --git a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java index 53c845ed..ff6e334c 100644 --- a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java +++ b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java @@ -13,8 +13,6 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.UUID; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.simpleyaml.configuration.file.YamlFile; import org.simpleyaml.configuration.file.YamlFileWrapper; @@ -230,8 +228,7 @@ public class GeneralUtils { Double result = evaluator.evaluate(sanitizedExpression); // Check if the result is null or not within bounds - if (result == null) - break; + if (result == null) break; if (result.intValue() > 0 && result.intValue() <= maxValue) results.add(result.intValue()); @@ -242,11 +239,15 @@ public class GeneralUtils { private static String sanitizeNFunction(String expression, int nValue) { String sanitizedExpression = expression.replace(" ", ""); - String multiplyByOpeningRoundBracketPattern = "([0-9n)])\\("; // example: n(n-1), 9(n-1), (n-1)(n-2) - sanitizedExpression = sanitizedExpression.replaceAll(multiplyByOpeningRoundBracketPattern, "$1*("); + String multiplyByOpeningRoundBracketPattern = + "([0-9n)])\\("; // example: n(n-1), 9(n-1), (n-1)(n-2) + sanitizedExpression = + sanitizedExpression.replaceAll(multiplyByOpeningRoundBracketPattern, "$1*("); - String multiplyByClosingRoundBracketPattern = "\\)([0-9n)])"; // example: (n-1)n, (n-1)9, (n-1)(n-2) - sanitizedExpression = sanitizedExpression.replaceAll(multiplyByClosingRoundBracketPattern, ")*$1"); + String multiplyByClosingRoundBracketPattern = + "\\)([0-9n)])"; // example: (n-1)n, (n-1)9, (n-1)(n-2) + sanitizedExpression = + sanitizedExpression.replaceAll(multiplyByClosingRoundBracketPattern, ")*$1"); sanitizedExpression = insertMultiplicationBeforeN(sanitizedExpression, nValue); return sanitizedExpression;