Skip to content

Commit

Permalink
Merge branch 'main' into bump_googleJavaFormat_1_25_2
Browse files Browse the repository at this point in the history
  • Loading branch information
Frooodle authored Dec 17, 2024
2 parents 343e38a + 7f045db commit 64f8348
Show file tree
Hide file tree
Showing 53 changed files with 255 additions and 365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.github.pixee.security.SystemCommand;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LibreOfficeListener {

private static final Logger logger = LoggerFactory.getLogger(LibreOfficeListener.class);
private static final long ACTIVITY_TIMEOUT = 20L * 60 * 1000; // 20 minutes

private static final LibreOfficeListener INSTANCE = new LibreOfficeListener();
Expand Down Expand Up @@ -87,7 +83,7 @@ public void start() throws IOException {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.error("exception", e);
log.error("exception", e);
} // Check every 1 second
}
}
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/stirling/software/SPDF/SPdfApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

import javax.swing.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
Expand All @@ -23,6 +21,7 @@
import org.springframework.scheduling.annotation.EnableScheduling;

import io.github.pixee.security.SystemCommand;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -35,8 +34,6 @@
@Slf4j
public class SPdfApplication {

private static final Logger logger = LoggerFactory.getLogger(SPdfApplication.class);

@Autowired private Environment env;
@Autowired ApplicationProperties applicationProperties;

Expand Down Expand Up @@ -95,7 +92,7 @@ public static void main(String[] args) throws IOException, InterruptedException
if (Files.exists(Paths.get("configs/settings.yml"))) {
propertyFiles.put("spring.config.additional-location", "file:configs/settings.yml");
} else {
logger.warn("External configuration file 'configs/settings.yml' does not exist.");
log.warn("External configuration file 'configs/settings.yml' does not exist.");
}

if (Files.exists(Paths.get("configs/custom_settings.yml"))) {
Expand All @@ -108,7 +105,7 @@ public static void main(String[] args) throws IOException, InterruptedException
"spring.config.additional-location",
existingLocation + "file:configs/custom_settings.yml");
} else {
logger.warn("Custom configuration file 'configs/custom_settings.yml' does not exist.");
log.warn("Custom configuration file 'configs/custom_settings.yml' does not exist.");
}
Properties finalProps = new Properties();

Expand All @@ -131,16 +128,16 @@ public static void main(String[] args) throws IOException, InterruptedException
Files.createDirectories(Path.of("customFiles/static/"));
Files.createDirectories(Path.of("customFiles/templates/"));
} catch (Exception e) {
logger.error("Error creating directories: {}", e.getMessage());
log.error("Error creating directories: {}", e.getMessage());
}

printStartupLogs();
}

private static void printStartupLogs() {
logger.info("Stirling-PDF Started.");
log.info("Stirling-PDF Started.");
String url = baseUrlStatic + ":" + getStaticPort();
logger.info("Navigate to {}", url);
log.info("Navigate to {}", url);
}

@Autowired(required = false)
Expand All @@ -154,7 +151,7 @@ public void init() {
&& Boolean.parseBoolean(System.getProperty("STIRLING_PDF_DESKTOP_UI", "false"))) {
webBrowser.initWebUI(url);
} else {
String browserOpenEnv = env.getProperty("BROWSER_OPEN");
String browserOpenEnv = env.getProperty("BROWSER_OPEN");
boolean browserOpen = browserOpenEnv != null && "true".equalsIgnoreCase(browserOpenEnv);
if (browserOpen) {
try {
Expand All @@ -169,11 +166,11 @@ public void init() {
SystemCommand.runCommand(rt, "xdg-open " + url);
}
} catch (Exception e) {
logger.error("Error opening browser: {}", e.getMessage());
log.error("Error opening browser: {}", e.getMessage());
}
}
}
logger.info("Running configs {}", applicationProperties.toString());
log.info("Running configs {}", applicationProperties.toString());
}

@PreDestroy
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/stirling/software/SPDF/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.util.Properties;
import java.util.function.Predicate;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -21,14 +19,14 @@
import org.springframework.core.io.ResourceLoader;
import org.thymeleaf.spring6.SpringTemplateEngine;

import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.model.ApplicationProperties;

@Configuration
@Lazy
@Slf4j
public class AppConfig {

private static final Logger logger = LoggerFactory.getLogger(AppConfig.class);

@Autowired ApplicationProperties applicationProperties;

@Bean
Expand Down Expand Up @@ -61,7 +59,7 @@ public String appVersion() {
props.load(resource.getInputStream());
return props.getProperty("version");
} catch (IOException e) {
logger.error("exception", e);
log.error("exception", e);
}
return "0.0.0";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
import org.simpleyaml.configuration.file.YamlFile;
import org.simpleyaml.configuration.implementation.SimpleYamlImplementation;
import org.simpleyaml.configuration.implementation.snakeyaml.lib.DumperOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ConfigInitializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {

private static final Logger logger = LoggerFactory.getLogger(ConfigInitializer.class);

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
try {
Expand Down Expand Up @@ -149,7 +148,7 @@ private void changeConfigItemFromCommentToKeyValue(
.commentSide(settingsTemplateFile.getComment(path, CommentType.SIDE));
} else {
// Log if the key is not found in both YAML files
logger.info("Key not found in both YAML files: " + path);
log.info("Key not found in both YAML files: " + path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.model.ApplicationProperties;

@Service
@Slf4j
@DependsOn({"bookAndHtmlFormatsInstalled"})
public class EndpointConfiguration {
private static final Logger logger = LoggerFactory.getLogger(EndpointConfiguration.class);

private Map<String, Boolean> endpointStatuses = new ConcurrentHashMap<>();
private Map<String, Set<String>> endpointGroups = new ConcurrentHashMap<>();

Expand All @@ -43,7 +43,7 @@ public void enableEndpoint(String endpoint) {

public void disableEndpoint(String endpoint) {
if (!endpointStatuses.containsKey(endpoint) || endpointStatuses.get(endpoint) != false) {
logger.debug("Disabling {}", endpoint);
log.debug("Disabling {}", endpoint);
endpointStatuses.put(endpoint, false);
}
}
Expand Down Expand Up @@ -87,7 +87,7 @@ public void logDisabledEndpointsSummary() {
.collect(Collectors.toList());

if (!disabledList.isEmpty()) {
logger.info(
log.info(
"Total disabled endpoints: {}. Disabled endpoints: {}",
disabledList.size(),
String.join(", ", disabledList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.LockedException;
import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest;
import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserService;
Expand All @@ -13,13 +11,15 @@
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;

import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.config.security.LoginAttemptService;
import stirling.software.SPDF.config.security.UserService;
import stirling.software.SPDF.model.ApplicationProperties;
import stirling.software.SPDF.model.ApplicationProperties.Security.OAUTH2;
import stirling.software.SPDF.model.ApplicationProperties.Security.OAUTH2.Client;
import stirling.software.SPDF.model.User;

@Slf4j
public class CustomOAuth2UserService implements OAuth2UserService<OidcUserRequest, OidcUser> {

private final OidcUserService delegate = new OidcUserService();
Expand All @@ -30,8 +30,6 @@ public class CustomOAuth2UserService implements OAuth2UserService<OidcUserReques

private ApplicationProperties applicationProperties;

private static final Logger logger = LoggerFactory.getLogger(CustomOAuth2UserService.class);

public CustomOAuth2UserService(
ApplicationProperties applicationProperties,
UserService userService,
Expand Down Expand Up @@ -82,10 +80,10 @@ public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2Authenticatio
user.getUserInfo(),
usernameAttribute);
} catch (IllegalArgumentException e) {
logger.error("Error loading OIDC user: {}", e.getMessage());
log.error("Error loading OIDC user: {}", e.getMessage());
throw new OAuth2AuthenticationException(new OAuth2Error(e.getMessage()), e);
} catch (Exception e) {
logger.error("Unexpected error loading OIDC user", e);
log.error("Unexpected error loading OIDC user", e);
throw new OAuth2AuthenticationException("Unexpected error during authentication");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.apache.pdfbox.pdmodel.PDPageContentStream.AppendMode;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand All @@ -33,8 +31,6 @@
@Tag(name = "General", description = "General APIs")
public class CropController {

private static final Logger logger = LoggerFactory.getLogger(CropController.class);

private final CustomPDDocumentFactory pdfDocumentFactory;

private final PostHogService postHogService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDField;
import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand All @@ -33,18 +31,18 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.model.api.general.MergePdfsRequest;
import stirling.software.SPDF.service.CustomPDDocumentFactory;
import stirling.software.SPDF.utils.GeneralUtils;
import stirling.software.SPDF.utils.WebResponseUtils;

@RestController
@Slf4j
@RequestMapping("/api/v1/general")
@Tag(name = "General", description = "General APIs")
public class MergeController {

private static final Logger logger = LoggerFactory.getLogger(MergeController.class);

private final CustomPDDocumentFactory pdfDocumentFactory;

@Autowired
Expand Down Expand Up @@ -184,7 +182,7 @@ public ResponseEntity<byte[]> mergePdfs(@ModelAttribute MergePdfsRequest form)
baos.toByteArray(), mergedFileName); // Return the modified PDF

} catch (Exception ex) {
logger.error("Error in merge pdf process", ex);
log.error("Error in merge pdf process", ex);
throw ex;
} finally {
for (File file : filesToDelete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
import org.apache.pdfbox.util.Matrix;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand All @@ -35,8 +33,6 @@
@Tag(name = "General", description = "General APIs")
public class MultiPageLayoutController {

private static final Logger logger = LoggerFactory.getLogger(MultiPageLayoutController.class);

private final CustomPDDocumentFactory pdfDocumentFactory;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand All @@ -22,6 +20,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.model.SortTypes;
import stirling.software.SPDF.model.api.PDFWithPageNums;
import stirling.software.SPDF.model.api.general.RearrangePagesRequest;
Expand All @@ -31,11 +30,10 @@

@RestController
@RequestMapping("/api/v1/general")
@Slf4j
@Tag(name = "General", description = "General APIs")
public class RearrangePagesPDFController {

private static final Logger logger = LoggerFactory.getLogger(RearrangePagesPDFController.class);

private final CustomPDDocumentFactory pdfDocumentFactory;

@Autowired
Expand Down Expand Up @@ -202,7 +200,7 @@ private List<Integer> processSortTypes(String sortTypes, int totalPages) {
throw new IllegalArgumentException("Unsupported custom mode");
}
} catch (IllegalArgumentException e) {
logger.error("Unsupported custom mode", e);
log.error("Unsupported custom mode", e);
return null;
}
}
Expand Down Expand Up @@ -230,8 +228,8 @@ public ResponseEntity<byte[]> rearrangePages(@ModelAttribute RearrangePagesReque
} else {
newPageOrder = GeneralUtils.parsePageList(pageOrderArr, totalPages, false);
}
logger.info("newPageOrder = " + newPageOrder);
logger.info("totalPages = " + totalPages);
log.info("newPageOrder = " + newPageOrder);
log.info("totalPages = " + totalPages);
// Create a new list to hold the pages in the new order
List<PDPage> newPages = new ArrayList<>();
for (int i = 0; i < newPageOrder.size(); i++) {
Expand All @@ -254,7 +252,7 @@ public ResponseEntity<byte[]> rearrangePages(@ModelAttribute RearrangePagesReque
.replaceFirst("[.][^.]+$", "")
+ "_rearranged.pdf");
} catch (IOException e) {
logger.error("Failed rearranging documents", e);
log.error("Failed rearranging documents", e);
return null;
}
}
Expand Down
Loading

0 comments on commit 64f8348

Please sign in to comment.