From fe84b3ff156fe46fe0ea5b0844f99ec82c8e66f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Sz=C3=BCcs?= <127139797+balazs-szucs@users.noreply.github.com> Date: Thu, 4 Sep 2025 15:29:55 +0200 Subject: [PATCH] feat: Add Lombok @Getter and @Setter annotations to reduce boilerplate code in multiple classes (#4321) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description of Changes Update classes across the codebase to use Lombok's `@Getter` and `@Setter` annotations, replacing manually written getter and setter methods. This change streamlines the code, reduces boilerplate, and improves maintainability. --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --------- Signed-off-by: Balázs Szücs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../software/common/util/ProcessExecutor.java | 19 ++-------- .../software/common/util/TempFile.java | 6 +-- .../common/util/TempFileRegistry.java | 33 ++++++++-------- .../signature/CreateSignatureBase.java | 38 ++++++++----------- .../SPDF/config/EndpointConfiguration.java | 6 +-- .../api/EditTableOfContentsController.java | 27 ++----------- .../controller/web/GeneralWebController.java | 27 ++----------- .../controller/web/MetricsController.java | 19 ++-------- .../software/SPDF/model/ApiEndpoint.java | 6 +-- .../model/api/misc/ScannerEffectRequest.java | 4 -- .../software/SPDF/pdf/TextFinder.java | 6 +-- .../proprietary/audit/AuditEventType.java | 7 ++-- .../proprietary/audit/AuditLevel.java | 7 ++-- .../security/model/AttemptCounter.java | 11 ++---- 14 files changed, 63 insertions(+), 153 deletions(-) diff --git a/app/common/src/main/java/stirling/software/common/util/ProcessExecutor.java b/app/common/src/main/java/stirling/software/common/util/ProcessExecutor.java index ee7297153..0abf9ade7 100644 --- a/app/common/src/main/java/stirling/software/common/util/ProcessExecutor.java +++ b/app/common/src/main/java/stirling/software/common/util/ProcessExecutor.java @@ -15,6 +15,8 @@ import java.util.concurrent.TimeUnit; import io.github.pixee.security.BoundedLineReader; +import lombok.Getter; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import stirling.software.common.model.ApplicationProperties; @@ -303,6 +305,8 @@ public class ProcessExecutor { OCR_MY_PDF } + @Setter + @Getter public class ProcessExecutorResult { int rc; String messages; @@ -312,20 +316,5 @@ public class ProcessExecutor { this.messages = messages; } - public int getRc() { - return rc; - } - - public void setRc(int rc) { - this.rc = rc; - } - - public String getMessages() { - return messages; - } - - public void setMessages(String messages) { - this.messages = messages; - } } } diff --git a/app/common/src/main/java/stirling/software/common/util/TempFile.java b/app/common/src/main/java/stirling/software/common/util/TempFile.java index db859c431..ce948fdac 100644 --- a/app/common/src/main/java/stirling/software/common/util/TempFile.java +++ b/app/common/src/main/java/stirling/software/common/util/TempFile.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Path; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; /** @@ -14,6 +15,7 @@ import lombok.extern.slf4j.Slf4j; public class TempFile implements AutoCloseable { private final TempFileManager manager; + @Getter private final File file; public TempFile(TempFileManager manager, String suffix) throws IOException { @@ -21,10 +23,6 @@ public class TempFile implements AutoCloseable { this.file = manager.createTempFile(suffix); } - public File getFile() { - return file; - } - public Path getPath() { return file.toPath(); } diff --git a/app/common/src/main/java/stirling/software/common/util/TempFileRegistry.java b/app/common/src/main/java/stirling/software/common/util/TempFileRegistry.java index 323b3bff3..cfdba632c 100644 --- a/app/common/src/main/java/stirling/software/common/util/TempFileRegistry.java +++ b/app/common/src/main/java/stirling/software/common/util/TempFileRegistry.java @@ -11,6 +11,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.stream.Collectors; +import lombok.Getter; import org.springframework.stereotype.Component; import lombok.extern.slf4j.Slf4j; @@ -24,8 +25,22 @@ import lombok.extern.slf4j.Slf4j; public class TempFileRegistry { private final ConcurrentMap registeredFiles = new ConcurrentHashMap<>(); + /** + * -- GETTER -- + * Get all registered third-party temporary files. + * + * @return Set of third-party file paths + */ + @Getter private final Set thirdPartyTempFiles = Collections.newSetFromMap(new ConcurrentHashMap<>()); + /** + * -- GETTER -- + * Get all registered temporary directories. + * + * @return Set of temporary directory paths + */ + @Getter private final Set tempDirectories = Collections.newSetFromMap(new ConcurrentHashMap<>()); /** @@ -133,24 +148,6 @@ public class TempFileRegistry { .collect(Collectors.toSet()); } - /** - * Get all registered third-party temporary files. - * - * @return Set of third-party file paths - */ - public Set getThirdPartyTempFiles() { - return thirdPartyTempFiles; - } - - /** - * Get all registered temporary directories. - * - * @return Set of temporary directory paths - */ - public Set getTempDirectories() { - return tempDirectories; - } - /** * Check if a file is registered in the registry. * diff --git a/app/core/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java b/app/core/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java index aba11d9b0..ba8a2d458 100644 --- a/app/core/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java +++ b/app/core/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java @@ -31,6 +31,8 @@ import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.Enumeration; +import lombok.Getter; +import lombok.Setter; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface; import org.bouncycastle.cert.jcajce.JcaCertStore; import org.bouncycastle.cms.CMSException; @@ -44,8 +46,21 @@ import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder; public abstract class CreateSignatureBase implements SignatureInterface { private PrivateKey privateKey; + @Getter private Certificate[] certificateChain; + @Setter private String tsaUrl; + /** + * Specifies whether the external signing scenario should be used. + * If set to {@code true}, external signing will be performed and + * {@link SignatureInterface} will be used for signing. + * If set to {@code false}, internal signing will be performed. + *

Default: {@code false} + * + * @param externalSigning {@code true} if external signing should be performed; {@code false} for internal signing + */ + @Setter + @Getter private boolean externalSigning; /** @@ -97,18 +112,10 @@ public abstract class CreateSignatureBase implements SignatureInterface { this.privateKey = privateKey; } - public Certificate[] getCertificateChain() { - return certificateChain; - } - public final void setCertificateChain(final Certificate[] certificateChain) { this.certificateChain = certificateChain; } - public void setTsaUrl(String tsaUrl) { - this.tsaUrl = tsaUrl; - } - /** * SignatureInterface sample implementation. * @@ -152,19 +159,4 @@ public abstract class CreateSignatureBase implements SignatureInterface { } } - public boolean isExternalSigning() { - return externalSigning; - } - - /** - * Set if external signing scenario should be used. If {@code false}, SignatureInterface would - * be used for signing. - * - *

Default: {@code false} - * - * @param externalSigning {@code true} if external signing should be performed - */ - public void setExternalSigning(boolean externalSigning) { - this.externalSigning = externalSigning; - } } diff --git a/app/core/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java b/app/core/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java index dab00a89d..c6e66d836 100644 --- a/app/core/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java +++ b/app/core/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import lombok.Getter; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; @@ -19,6 +20,7 @@ public class EndpointConfiguration { private static final String REMOVE_BLANKS = "remove-blanks"; private final ApplicationProperties applicationProperties; + @Getter private Map endpointStatuses = new ConcurrentHashMap<>(); private Map> endpointGroups = new ConcurrentHashMap<>(); private Set disabledGroups = new HashSet<>(); @@ -46,10 +48,6 @@ public class EndpointConfiguration { endpointStatuses.put(endpoint, false); } - public Map getEndpointStatuses() { - return endpointStatuses; - } - public boolean isEndpointEnabled(String endpoint) { String original = endpoint; if (endpoint.startsWith("/")) { diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/api/EditTableOfContentsController.java b/app/core/src/main/java/stirling/software/SPDF/controller/api/EditTableOfContentsController.java index 6a30e6bb3..ca8a62cb0 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/api/EditTableOfContentsController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/api/EditTableOfContentsController.java @@ -6,6 +6,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import lombok.Getter; +import lombok.Setter; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline; @@ -234,33 +236,12 @@ public class EditTableOfContentsController { } // Inner class to represent bookmarks in JSON + @Setter + @Getter public static class BookmarkItem { private String title; private int pageNumber; private List children = new ArrayList<>(); - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public int getPageNumber() { - return pageNumber; - } - - public void setPageNumber(int pageNumber) { - this.pageNumber = pageNumber; - } - - public List getChildren() { - return children; - } - - public void setChildren(List children) { - this.children = children; - } } } diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java b/app/core/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java index 1084e2fe0..c0aec935a 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java @@ -9,6 +9,8 @@ import java.nio.file.Paths; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +import lombok.Setter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; @@ -317,6 +319,8 @@ public class GeneralWebController { return "remove-image-pdf"; } + @Setter + @Getter public class FontResource { private String name; @@ -331,28 +335,5 @@ public class GeneralWebController { this.type = getFormatFromExtension(extension); } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getExtension() { - return extension; - } - - public void setExtension(String extension) { - this.extension = extension; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } } } diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/web/MetricsController.java b/app/core/src/main/java/stirling/software/SPDF/controller/web/MetricsController.java index e82acaffa..6b8049af6 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/web/MetricsController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/web/MetricsController.java @@ -4,6 +4,8 @@ import java.time.Duration; import java.time.LocalDateTime; import java.util.*; +import lombok.Getter; +import lombok.Setter; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -362,6 +364,8 @@ public class MetricsController { return String.format("%dd %dh %dm %ds", days, hours, minutes, seconds); } + @Setter + @Getter public static class EndpointCount { private String endpoint; @@ -373,20 +377,5 @@ public class MetricsController { this.count = count; } - public String getEndpoint() { - return endpoint; - } - - public void setEndpoint(String endpoint) { - this.endpoint = endpoint; - } - - public double getCount() { - return count; - } - - public void setCount(double count) { - this.count = count; - } } } diff --git a/app/core/src/main/java/stirling/software/SPDF/model/ApiEndpoint.java b/app/core/src/main/java/stirling/software/SPDF/model/ApiEndpoint.java index dfb06f0d8..09ceedc00 100644 --- a/app/core/src/main/java/stirling/software/SPDF/model/ApiEndpoint.java +++ b/app/core/src/main/java/stirling/software/SPDF/model/ApiEndpoint.java @@ -4,10 +4,12 @@ import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.databind.JsonNode; +import lombok.Getter; public class ApiEndpoint { private final String name; private Map parameters; + @Getter private final String description; public ApiEndpoint(String name, JsonNode postNode) { @@ -31,10 +33,6 @@ public class ApiEndpoint { return true; } - public String getDescription() { - return description; - } - @Override public String toString() { return "ApiEndpoint [name=" + name + ", parameters=" + parameters + "]"; diff --git a/app/core/src/main/java/stirling/software/SPDF/model/api/misc/ScannerEffectRequest.java b/app/core/src/main/java/stirling/software/SPDF/model/api/misc/ScannerEffectRequest.java index 72ecb42f6..330abbec3 100644 --- a/app/core/src/main/java/stirling/software/SPDF/model/api/misc/ScannerEffectRequest.java +++ b/app/core/src/main/java/stirling/software/SPDF/model/api/misc/ScannerEffectRequest.java @@ -79,10 +79,6 @@ public class ScannerEffectRequest { @Schema(description = "Whether advanced settings are enabled", example = "false") private boolean advancedEnabled = false; - public boolean isAdvancedEnabled() { - return advancedEnabled; - } - public int getQualityValue() { return switch (quality) { case low -> 30; diff --git a/app/core/src/main/java/stirling/software/SPDF/pdf/TextFinder.java b/app/core/src/main/java/stirling/software/SPDF/pdf/TextFinder.java index c99a2ade7..00a61a51d 100644 --- a/app/core/src/main/java/stirling/software/SPDF/pdf/TextFinder.java +++ b/app/core/src/main/java/stirling/software/SPDF/pdf/TextFinder.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import lombok.Getter; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.text.PDFTextStripper; import org.apache.pdfbox.text.TextPosition; @@ -20,6 +21,7 @@ public class TextFinder extends PDFTextStripper { private final String searchTerm; private final boolean useRegex; private final boolean wholeWordSearch; + @Getter private final List foundTexts = new ArrayList<>(); private final List pageTextPositions = new ArrayList<>(); @@ -187,10 +189,6 @@ public class TextFinder extends PDFTextStripper { super.endPage(page); } - public List getFoundTexts() { - return foundTexts; - } - public String getDebugInfo() { StringBuilder debug = new StringBuilder(); debug.append("Extracted text length: ").append(pageTextBuilder.length()).append("\n"); diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/audit/AuditEventType.java b/app/proprietary/src/main/java/stirling/software/proprietary/audit/AuditEventType.java index a18e83467..9ca3eaa5e 100644 --- a/app/proprietary/src/main/java/stirling/software/proprietary/audit/AuditEventType.java +++ b/app/proprietary/src/main/java/stirling/software/proprietary/audit/AuditEventType.java @@ -1,6 +1,9 @@ package stirling.software.proprietary.audit; +import lombok.Getter; + /** Standardized audit event types for the application. */ +@Getter public enum AuditEventType { // Authentication events - BASIC level USER_LOGIN("User login"), @@ -28,10 +31,6 @@ public enum AuditEventType { this.description = description; } - public String getDescription() { - return description; - } - /** * Get the enum value from a string representation. Useful for backward compatibility with * string-based event types. diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/audit/AuditLevel.java b/app/proprietary/src/main/java/stirling/software/proprietary/audit/AuditLevel.java index 136559a94..4a14773c4 100644 --- a/app/proprietary/src/main/java/stirling/software/proprietary/audit/AuditLevel.java +++ b/app/proprietary/src/main/java/stirling/software/proprietary/audit/AuditLevel.java @@ -1,6 +1,9 @@ package stirling.software.proprietary.audit; +import lombok.Getter; + /** Defines the different levels of audit logging available in the application. */ +@Getter public enum AuditLevel { /** * OFF - No audit logging (level 0) Disables all audit logging except for critical security @@ -33,10 +36,6 @@ public enum AuditLevel { this.level = level; } - public int getLevel() { - return level; - } - /** * Checks if this audit level includes the specified level * diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/security/model/AttemptCounter.java b/app/proprietary/src/main/java/stirling/software/proprietary/security/model/AttemptCounter.java index 18ca598ae..10cd8eeb7 100644 --- a/app/proprietary/src/main/java/stirling/software/proprietary/security/model/AttemptCounter.java +++ b/app/proprietary/src/main/java/stirling/software/proprietary/security/model/AttemptCounter.java @@ -1,5 +1,8 @@ package stirling.software.proprietary.security.model; +import lombok.Getter; + +@Getter public class AttemptCounter { private int attemptCount; private long lastAttemptTime; @@ -14,14 +17,6 @@ public class AttemptCounter { this.lastAttemptTime = System.currentTimeMillis(); } - public int getAttemptCount() { - return attemptCount; - } - - public long getLastAttemptTime() { - return lastAttemptTime; - } - public boolean shouldReset(long attemptIncrementTime) { return System.currentTimeMillis() - lastAttemptTime > attemptIncrementTime; }