Compare commits

...
Author SHA1 Message Date
Ludy87 7265d1b9fa Update PolicyExecutor.java 2026-07-09 22:52:21 +02:00
Ludy87 a1808b6c0f Update PortalInfraAuditService.java 2026-07-09 22:51:55 +02:00
LudyandGitHub e78b8fcd37 Merge branch 'main' into switch_expression 2026-07-09 22:41:35 +02:00
LudyandGitHub e263b9f507 Merge branch 'main' into switch_expression 2026-07-09 11:06:15 +02:00
Ludy87 16ac5e4822 Update MergeControllerGapTest.java 2026-07-03 16:15:00 +02:00
Ludy87 b4a1104902 more 2026-07-03 16:08:50 +02:00
LudyandGitHub 2581c11c9d Merge branch 'main' into switch_expression 2026-07-03 15:51:17 +02:00
LudyandGitHub b64f626926 Merge branch 'main' into switch_expression 2026-07-03 15:07:11 +02:00
Ludy87 76b129decb Remove unified credit interceptor system
Delete CreditErrorAdvice, UnifiedCreditInterceptor, and TeamCreditService. These classes implemented credit validation and consumption logic for the SaaS profile. This removal indicates a refactoring or replacement of the credit management system.
2026-07-03 15:06:49 +02:00
LudyandGitHub 6810155799 Merge branch 'main' into switch_expression 2026-06-14 17:33:00 +02:00
LudyandGitHub fe520d24a9 Delete CLAUDE.md~Stashed changes 2026-06-14 17:31:12 +02:00
Ludy87 351abf54a1 Warn on null form field instead of setting value
Split the combined 'case null, default' switch arm into distinct cases. Now a null PDF form field triggers a warning log, while the default branch continues to call setValue(value != null ? value : ""). This improves diagnostics and avoids attempting to set values on null fields.
2026-06-13 22:13:16 +02:00
Ludy87 cad2ac206a Update UIDataController.java 2026-06-12 13:27:58 +02:00
Ludy87 4598ae1e8d Use constructor injection in UploadLimitServiceTest
Replace reflective field injection with passing the mocked ApplicationProperties into UploadLimitService via its constructor. This simplifies the test setup, avoids reflection, and makes dependency injection explicit and more readable.
2026-06-12 13:14:41 +02:00
Ludy87 a6a6de960e Refactor switch statements to use switch expressions for improved readability and conciseness
Signed-off-by: Ludy87 <Ludy87@users.noreply.github.com>
2026-06-12 12:58:14 +02:00
LudyandGitHub 9a4af79c6d Merge branch 'main' into switch_expression 2026-06-12 12:43:49 +02:00
Ludy87 b43cd350f7 Merge branch 'Stirling-Tools:main' into main
Signed-off-by: Ludy87 <Ludy87@users.noreply.github.com>
2026-06-12 12:43:33 +02:00
LudyandGitHub 9a985abf46 Merge branch 'main' into switch_expression 2026-06-11 20:38:42 +02:00
Ludy87 837371cff0 del 2026-06-11 20:38:16 +02:00
Ludy87 da7b586313 Use deque accessors and add job ownership guard
Replace index-based List access with deque-style getFirst()/getLast() where appropriate, modernize switches to expression form, and update various small APIs (e.g. getFirst() on list-like structures). Remove an obsolete test file. Substantially enhance JobController to integrate cluster backplane and job store: add ownership cache, guardNonOwner/backplaneUnavailable helpers, sticky-410 handling, and backplane-aware flows for job status/result/file endpoints (returning 410 or retryable 503 as needed). Update tests and PDF-to-markdown flow to use PdfMarkdownConverter/TempFile/PdfDocument mocks. Misc fixes across controllers and services (SAML attribute access, audit file access, database backup handling, session registry, interceptors, and team credit service). These changes improve safety for clustered deployments and modernize collection usage and control flow.
2026-06-11 20:36:12 +02:00
Ludy87 33bfb18d7c Merge remote-tracking branch 'origin/main' into switch_expression 2026-06-11 20:28:12 +02:00
Ludy87 584fd0cb09 getFirst() 2026-05-09 20:44:13 +02:00
Ludy87 ecdb8160a9 getLast 2026-05-09 20:32:21 +02:00
Ludy87 0bd7d72d07 get(0) to getFirst 2026-05-09 20:20:12 +02:00
Ludy87 10eac6622c UIDataControllerTest 2026-05-09 20:14:25 +02:00
Ludy87 641114c5c2 expression 2026-05-09 20:11:24 +02:00
57 changed files with 333 additions and 410 deletions
@@ -73,7 +73,7 @@ public class RuntimePathConfig {
defaultWatchedFolders, defaultWatchedFolders,
watchedFoldersDirs, watchedFoldersDirs,
pipeline != null ? pipeline.getWatchedFoldersDir() : null); pipeline != null ? pipeline.getWatchedFoldersDir() : null);
this.pipelineWatchedFoldersPath = this.pipelineWatchedFoldersPaths.get(0); this.pipelineWatchedFoldersPath = this.pipelineWatchedFoldersPaths.getFirst();
this.pipelineFinishedFoldersPath = this.pipelineFinishedFoldersPath =
resolvePath( resolvePath(
defaultFinishedFolders, defaultFinishedFolders,
@@ -60,54 +60,40 @@ public class Provider {
} }
private UsernameAttribute validateUsernameAttribute(UsernameAttribute usernameAttribute) { private UsernameAttribute validateUsernameAttribute(UsernameAttribute usernameAttribute) {
switch (name) { return switch (name) {
case "google" -> { case "google" -> validateGoogleUsernameAttribute(usernameAttribute);
return validateGoogleUsernameAttribute(usernameAttribute); case "github" -> validateGitHubUsernameAttribute(usernameAttribute);
} case "keycloak" -> validateKeycloakUsernameAttribute(usernameAttribute);
case "github" -> { default -> usernameAttribute;
return validateGitHubUsernameAttribute(usernameAttribute); };
}
case "keycloak" -> {
return validateKeycloakUsernameAttribute(usernameAttribute);
}
default -> {
return usernameAttribute;
}
}
} }
private UsernameAttribute validateKeycloakUsernameAttribute( private UsernameAttribute validateKeycloakUsernameAttribute(
UsernameAttribute usernameAttribute) { UsernameAttribute usernameAttribute) {
switch (usernameAttribute) { return switch (usernameAttribute) {
case EMAIL, NAME, GIVEN_NAME, FAMILY_NAME, PREFERRED_USERNAME -> { case EMAIL, NAME, GIVEN_NAME, FAMILY_NAME, PREFERRED_USERNAME -> usernameAttribute;
return usernameAttribute;
}
default -> default ->
throw new UnsupportedClaimException( throw new UnsupportedClaimException(
String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName)); String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName));
} };
} }
private UsernameAttribute validateGoogleUsernameAttribute(UsernameAttribute usernameAttribute) { private UsernameAttribute validateGoogleUsernameAttribute(UsernameAttribute usernameAttribute) {
switch (usernameAttribute) { return switch (usernameAttribute) {
case EMAIL, NAME, GIVEN_NAME, FAMILY_NAME -> { case EMAIL, NAME, GIVEN_NAME, FAMILY_NAME -> usernameAttribute;
return usernameAttribute;
}
default -> default ->
throw new UnsupportedClaimException( throw new UnsupportedClaimException(
String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName)); String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName));
} };
} }
private UsernameAttribute validateGitHubUsernameAttribute(UsernameAttribute usernameAttribute) { private UsernameAttribute validateGitHubUsernameAttribute(UsernameAttribute usernameAttribute) {
switch (usernameAttribute) { return switch (usernameAttribute) {
case LOGIN, EMAIL, NAME -> { case LOGIN, EMAIL, NAME -> usernameAttribute;
return usernameAttribute;
}
default -> default ->
throw new UnsupportedClaimException( throw new UnsupportedClaimException(
String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName)); String.format(EXCEPTION_MESSAGE, usernameAttribute, clientName));
} };
} }
@Override @Override
@@ -361,8 +361,8 @@ public class PdfMarkdownConverter {
if (xs.isEmpty()) { if (xs.isEmpty()) {
return List.of(lines); return List.of(lines);
} }
float minX = xs.get(0); float minX = xs.getFirst();
float maxX = xs.get(xs.size() - 1); float maxX = xs.getLast();
float splitAt = (minX + maxX) / 2f; float splitAt = (minX + maxX) / 2f;
float biggestGap = 0; float biggestGap = 0;
for (int i = 1; i < xs.size(); i++) { for (int i = 1; i < xs.size(); i++) {
@@ -492,7 +492,7 @@ public class PdfMarkdownConverter {
List<List<Line>> anchorGroups = new ArrayList<>(); List<List<Line>> anchorGroups = new ArrayList<>();
List<Line> current = new ArrayList<>(); List<Line> current = new ArrayList<>();
current.add(cands.get(0)); current.add(cands.getFirst());
for (int i = 1; i < cands.size(); i++) { for (int i = 1; i < cands.size(); i++) {
float gap = cands.get(i - 1).y - cands.get(i).y; float gap = cands.get(i - 1).y - cands.get(i).y;
if (gap > splitThreshold) { if (gap > splitThreshold) {
@@ -513,8 +513,8 @@ public class PdfMarkdownConverter {
if (anchors.size() < 2) { if (anchors.size() < 2) {
continue; continue;
} }
float top = anchors.get(0).y; float top = anchors.getFirst().y;
float bottom = anchors.get(anchors.size() - 1).y; float bottom = anchors.getLast().y;
// Each anchor seeds a row; absorb wrapped continuation lines (non-anchors within the // Each anchor seeds a row; absorb wrapped continuation lines (non-anchors within the
// run's vertical span, with a little slack below the last row) into the anchor above. // run's vertical span, with a little slack below the last row) into the anchor above.
@@ -674,8 +674,8 @@ public class PdfMarkdownConverter {
float minGutter = Math.max(10f, charWidth * 2.5f); float minGutter = Math.max(10f, charWidth * 2.5f);
List<float[]> merged = new ArrayList<>(); List<float[]> merged = new ArrayList<>();
for (float[] band : columns) { for (float[] band : columns) {
if (!merged.isEmpty() && band[0] - merged.get(merged.size() - 1)[1] < minGutter) { if (!merged.isEmpty() && band[0] - merged.getLast()[1] < minGutter) {
merged.get(merged.size() - 1)[1] = band[1]; merged.getLast()[1] = band[1];
} else { } else {
merged.add(new float[] {band[0], band[1]}); merged.add(new float[] {band[0], band[1]});
} }
@@ -734,7 +734,7 @@ public class PdfMarkdownConverter {
} }
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(buildGfmRow(rows.get(0), widths, cols)).append('\n'); sb.append(buildGfmRow(rows.getFirst(), widths, cols)).append('\n');
sb.append('|'); sb.append('|');
for (int c = 0; c < cols; c++) { for (int c = 0; c < cols; c++) {
sb.append('-').append("-".repeat(widths[c])).append('-').append('|'); sb.append('-').append("-".repeat(widths[c])).append('-').append('|');
@@ -910,8 +910,8 @@ public class PdfMarkdownConverter {
} }
// Only merge a sentence continuation between two text paragraphs, never into/out of a // Only merge a sentence continuation between two text paragraphs, never into/out of a
// table. // table.
if (!(output.get(output.size() - 1) instanceof String last) if (!(output.getLast() instanceof String last)
|| !(pageItems.get(0) instanceof String first)) { || !(pageItems.getFirst() instanceof String first)) {
return; return;
} }
if (!first.isEmpty() if (!first.isEmpty()
@@ -932,13 +932,13 @@ public class PdfMarkdownConverter {
for (Object e : elements) { for (Object e : elements) {
if (e instanceof TableBlock tb if (e instanceof TableBlock tb
&& !out.isEmpty() && !out.isEmpty()
&& out.get(out.size() - 1) instanceof TableBlock prev && out.getLast() instanceof TableBlock prev
&& columnsMatch(flatten(prev.rows()), flatten(tb.rows()))) { && columnsMatch(flatten(prev.rows()), flatten(tb.rows()))) {
List<List<Line>> merged = new ArrayList<>(prev.rows()); List<List<Line>> merged = new ArrayList<>(prev.rows());
List<List<Line>> tail = tb.rows(); List<List<Line>> tail = tb.rows();
if (!tail.isEmpty() if (!tail.isEmpty()
&& !prev.rows().isEmpty() && !prev.rows().isEmpty()
&& rowText(tail.get(0)).equals(rowText(prev.rows().get(0)))) { && rowText(tail.getFirst()).equals(rowText(prev.rows().getFirst()))) {
tail = tail.subList(1, tail.size()); tail = tail.subList(1, tail.size());
} }
merged.addAll(tail); merged.addAll(tail);
@@ -971,7 +971,7 @@ public class PdfMarkdownConverter {
continue; continue;
} }
if (e instanceof TableBlock tb && !tb.rows().isEmpty()) { if (e instanceof TableBlock tb && !tb.rows().isEmpty()) {
return rowText(tb.rows().get(0)); return rowText(tb.rows().getFirst());
} }
return null; return null;
} }
@@ -119,7 +119,7 @@ public class InternalApiClient {
boolean hasFilePart = boolean hasFilePart =
body.values().stream() body.values().stream()
.flatMap(java.util.List::stream) .flatMap(java.util.List::stream)
.anyMatch(v -> v instanceof Resource); .anyMatch(Resource.class::isInstance);
if (isAiTool && !hasFilePart) { if (isAiTool && !hasFilePart) {
headers.setContentType(MediaType.MULTIPART_FORM_DATA); headers.setContentType(MediaType.MULTIPART_FORM_DATA);
} }
@@ -140,20 +140,25 @@ public class ChecksumUtils {
for (String algorithm : algorithms) { for (String algorithm : algorithms) {
String key = algorithm; // keep original key for output String key = algorithm; // keep original key for output
switch (algorithm.toUpperCase(Locale.ROOT)) { Object digestOrChecksum =
case "CRC32": switch (algorithm.toUpperCase(Locale.ROOT)) {
checksums.put(key, new CRC32()); case "CRC32" -> new CRC32();
break; case "ADLER32" -> new Adler32();
case "ADLER32": default -> {
checksums.put(key, new Adler32()); try {
break; // For MessageDigest, pass the original name (case-insensitive
default: // per JCA)
try { yield MessageDigest.getInstance(algorithm);
// For MessageDigest, pass the original name (case-insensitive per JCA) } catch (NoSuchAlgorithmException e) {
digests.put(key, MessageDigest.getInstance(algorithm)); throw new IllegalStateException(
} catch (NoSuchAlgorithmException e) { "Unsupported algorithm: " + algorithm, e);
throw new IllegalStateException("Unsupported algorithm: " + algorithm, e); }
} }
};
if (digestOrChecksum instanceof Checksum checksum) {
checksums.put(key, checksum);
} else {
digests.put(key, (MessageDigest) digestOrChecksum);
} }
} }
@@ -751,7 +751,7 @@ public class ExceptionUtils {
String targetDescription; String targetDescription;
if (errorInfo.affectedPages() != null && !errorInfo.affectedPages().isEmpty()) { if (errorInfo.affectedPages() != null && !errorInfo.affectedPages().isEmpty()) {
if (errorInfo.affectedPages().size() == 1) { if (errorInfo.affectedPages().size() == 1) {
targetDescription = "page " + errorInfo.affectedPages().get(0); targetDescription = "page " + errorInfo.affectedPages().getFirst();
} else { } else {
targetDescription = targetDescription =
"pages " "pages "
@@ -848,7 +848,7 @@ public class ExceptionUtils {
} }
// Use the first page number, or null if none found // Use the first page number, or null if none found
Integer pageNumber = affectedPages.isEmpty() ? null : affectedPages.get(0); Integer pageNumber = affectedPages.isEmpty() ? null : affectedPages.getFirst();
return new GhostscriptErrorInfo( return new GhostscriptErrorInfo(
ErrorCode.GHOSTSCRIPT_PAGE_DRAWING, ErrorCode.GHOSTSCRIPT_PAGE_DRAWING,
@@ -114,7 +114,7 @@ public enum FormFieldTypeSupport {
return; return;
} }
PDAnnotationWidget widget = checkBox.getWidgets().get(0); PDAnnotationWidget widget = checkBox.getWidgets().getFirst();
PDAppearanceCharacteristicsDictionary appearanceChars = PDAppearanceCharacteristicsDictionary appearanceChars =
widget.getAppearanceCharacteristics(); widget.getAppearanceCharacteristics();
@@ -88,28 +88,16 @@ public class FormUtils {
* text) * text)
*/ */
public String detectFieldType(PDField field) { public String detectFieldType(PDField field) {
if (field instanceof PDSignatureField) { return switch (field) {
return FIELD_TYPE_SIGNATURE; case PDSignatureField ignored -> FIELD_TYPE_SIGNATURE;
} case PDPushButton ignored -> FIELD_TYPE_BUTTON;
if (field instanceof PDPushButton) { case PDTextField ignored -> FIELD_TYPE_TEXT;
return FIELD_TYPE_BUTTON; case PDCheckBox ignored -> FIELD_TYPE_CHECKBOX;
} case PDComboBox ignored -> FIELD_TYPE_COMBOBOX;
if (field instanceof PDTextField) { case PDListBox ignored -> FIELD_TYPE_LISTBOX;
return FIELD_TYPE_TEXT; case PDRadioButton ignored -> FIELD_TYPE_RADIO;
} case null, default -> FIELD_TYPE_TEXT;
if (field instanceof PDCheckBox) { };
return FIELD_TYPE_CHECKBOX;
}
if (field instanceof PDComboBox) {
return FIELD_TYPE_COMBOBOX;
}
if (field instanceof PDListBox) {
return FIELD_TYPE_LISTBOX;
}
if (field instanceof PDRadioButton) {
return FIELD_TYPE_RADIO;
}
return FIELD_TYPE_TEXT;
} }
public List<FormFieldInfo> extractFormFields(PDDocument document) { public List<FormFieldInfo> extractFormFields(PDDocument document) {
@@ -583,22 +571,17 @@ public class FormUtils {
continue; continue;
} }
String type = info.type(); String type = info.type();
Object value; Object value =
switch (type) { switch (type) {
case FIELD_TYPE_CHECKBOX: case FIELD_TYPE_CHECKBOX ->
value = isChecked(info.value()) ? Boolean.TRUE : Boolean.FALSE; isChecked(info.value()) ? Boolean.TRUE : Boolean.FALSE;
break; case FIELD_TYPE_LISTBOX ->
case FIELD_TYPE_LISTBOX: info.multiSelect() ? new ArrayList<>() : safeDefault(info.value());
if (info.multiSelect()) { case FIELD_TYPE_BUTTON, FIELD_TYPE_SIGNATURE -> null;
value = new ArrayList<>(); default -> safeDefault(info.value());
} else { };
value = safeDefault(info.value()); if (value == null) {
} continue; // skip non-fillable
break;
case FIELD_TYPE_BUTTON, FIELD_TYPE_SIGNATURE:
continue; // skip non-fillable
default:
value = safeDefault(info.value());
} }
record.put(info.name(), value); record.put(info.name(), value);
} }
@@ -949,44 +932,44 @@ public class FormUtils {
if (selection == null || selection.trim().isEmpty()) return null; if (selection == null || selection.trim().isEmpty()) return null;
List<String> filtered = List<String> filtered =
filterChoiceSelections(List.of(selection), allowedOptions, fieldName); filterChoiceSelections(List.of(selection), allowedOptions, fieldName);
return filtered.isEmpty() ? null : filtered.get(0); return filtered.isEmpty() ? null : filtered.getFirst();
} }
private void applyValueToField(PDField field, String value, boolean strict) throws IOException { private void applyValueToField(PDField field, String value, boolean strict) throws IOException {
try { try {
if (field instanceof PDTextField textField) { switch (field) {
setTextValue(textField, value); case PDTextField textField -> setTextValue(textField, value);
} else if (field instanceof PDCheckBox checkBox) { case PDCheckBox checkBox -> {
LinkedHashSet<String> candidateStates = collectCheckBoxStates(checkBox); LinkedHashSet<String> candidateStates = collectCheckBoxStates(checkBox);
boolean shouldCheck = shouldCheckBoxBeChecked(value, candidateStates); boolean shouldCheck = shouldCheckBoxBeChecked(value, candidateStates);
try { try {
if (shouldCheck) { if (shouldCheck) {
checkBox.check(); checkBox.check();
} else { } else {
checkBox.unCheck(); checkBox.unCheck();
} }
} catch (IOException checkProblem) { } catch (IOException checkProblem) {
log.warn( log.warn(
"Failed to set checkbox state for '{}': {}", "Failed to set checkbox state for '{}': {}",
field.getFullyQualifiedName(), field.getFullyQualifiedName(),
checkProblem.getMessage(), checkProblem.getMessage(),
checkProblem); checkProblem);
if (strict) { if (strict) {
throw checkProblem; throw checkProblem;
}
} }
} }
} else if (field instanceof PDRadioButton radioButton) { case PDRadioButton radioButton -> {
if (value != null && !value.isBlank()) { if (value != null && !value.isBlank()) {
radioButton.setValue(value); radioButton.setValue(value);
}
} }
} else if (field instanceof PDChoice choiceField) { case PDChoice choiceField -> applyChoiceValue(choiceField, value);
applyChoiceValue(choiceField, value); case PDPushButton ignored -> log.debug("Ignore Push button");
} else if (field instanceof PDPushButton) { case PDSignatureField ignored ->
log.debug("Ignore Push button"); log.debug("Skipping signature field '{}'", field.getFullyQualifiedName());
} else if (field instanceof PDSignatureField) { case null -> log.warn("Attempted to set value on null field");
log.debug("Skipping signature field '{}'", field.getFullyQualifiedName()); default -> field.setValue(value != null ? value : "");
} else {
field.setValue(value != null ? value : "");
} }
} catch (Exception e) { } catch (Exception e) {
log.warn( log.warn(
@@ -1306,37 +1289,42 @@ public class FormUtils {
List<String> resolveOptions(PDTerminalField field) { List<String> resolveOptions(PDTerminalField field) {
try { try {
if (field instanceof PDChoice choice) { return switch (field) {
LinkedHashSet<String> allowed = new LinkedHashSet<>(); case PDChoice choice -> {
List<String> exportValues = choice.getOptionsExportValues(); LinkedHashSet<String> allowed = new LinkedHashSet<>();
List<String> displayValues = choice.getOptionsDisplayValues(); List<String> exportValues = choice.getOptionsExportValues();
List<String> displayValues = choice.getOptionsDisplayValues();
if (exportValues != null) { if (exportValues != null) {
exportValues.stream() exportValues.stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(String::trim) .map(String::trim)
.filter(s -> !s.isEmpty()) .filter(s -> !s.isEmpty())
.forEach(allowed::add); .forEach(allowed::add);
}
if (displayValues != null) {
displayValues.stream()
.filter(Objects::nonNull)
.map(String::trim)
.filter(s -> !s.isEmpty())
.forEach(allowed::add);
}
yield new ArrayList<>(allowed);
} }
if (displayValues != null) { case PDRadioButton radio -> {
displayValues.stream() List<String> exports = radio.getExportValues();
.filter(Objects::nonNull) yield exports != null && !exports.isEmpty()
.map(String::trim) ? new ArrayList<>(exports)
.filter(s -> !s.isEmpty()) : Collections.emptyList();
.forEach(allowed::add);
} }
return new ArrayList<>(allowed); case PDCheckBox checkBox -> {
} else if (field instanceof PDRadioButton radio) { List<String> exports = checkBox.getExportValues();
List<String> exports = radio.getExportValues(); yield exports != null && !exports.isEmpty()
if (exports != null && !exports.isEmpty()) { ? new ArrayList<>(exports)
return new ArrayList<>(exports); : Collections.emptyList();
} }
} else if (field instanceof PDCheckBox checkBox) { case null, default -> Collections.emptyList();
List<String> exports = checkBox.getExportValues(); };
if (exports != null && !exports.isEmpty()) {
return new ArrayList<>(exports);
}
}
} catch (Exception e) { } catch (Exception e) {
log.debug( log.debug(
"Failed to resolve options for field '{}': {}", "Failed to resolve options for field '{}': {}",
@@ -1465,7 +1453,7 @@ public class FormUtils {
// Only check options for choice-type fields (combobox, listbox, radio) // Only check options for choice-type fields (combobox, listbox, radio)
if (CHOICE_FIELD_TYPES.contains(type) && options != null && !options.isEmpty()) { if (CHOICE_FIELD_TYPES.contains(type) && options != null && !options.isEmpty()) {
String optionCandidate = cleanLabel(options.get(0)); String optionCandidate = cleanLabel(options.getFirst());
if (optionCandidate != null && !looksGeneric(optionCandidate)) { if (optionCandidate != null && !looksGeneric(optionCandidate)) {
return optionCandidate; return optionCandidate;
} }
@@ -1557,7 +1545,7 @@ public class FormUtils {
continue; continue;
} }
PDAnnotationWidget widget = widgets.get(0); PDAnnotationWidget widget = widgets.getFirst();
PDRectangle originalRectangle = cloneRectangle(widget.getRectangle()); PDRectangle originalRectangle = cloneRectangle(widget.getRectangle());
PDPage page = resolveWidgetPage(document, widget, null); PDPage page = resolveWidgetPage(document, widget, null);
if (page == null || originalRectangle == null) { if (page == null || originalRectangle == null) {
@@ -2446,19 +2434,19 @@ public class FormUtils {
private static int firstWidgetPageIndex(FormFieldWithCoordinates f) { private static int firstWidgetPageIndex(FormFieldWithCoordinates f) {
return (f.getWidgets() != null && !f.getWidgets().isEmpty()) return (f.getWidgets() != null && !f.getWidgets().isEmpty())
? f.getWidgets().get(0).getPageIndex() ? f.getWidgets().getFirst().getPageIndex()
: -1; : -1;
} }
private static float firstWidgetY(FormFieldWithCoordinates f) { private static float firstWidgetY(FormFieldWithCoordinates f) {
return (f.getWidgets() != null && !f.getWidgets().isEmpty()) return (f.getWidgets() != null && !f.getWidgets().isEmpty())
? f.getWidgets().get(0).getY() ? f.getWidgets().getFirst().getY()
: 0; : 0;
} }
private static float firstWidgetX(FormFieldWithCoordinates f) { private static float firstWidgetX(FormFieldWithCoordinates f) {
return (f.getWidgets() != null && !f.getWidgets().isEmpty()) return (f.getWidgets() != null && !f.getWidgets().isEmpty())
? f.getWidgets().get(0).getX() ? f.getWidgets().getFirst().getX()
: 0; : 0;
} }
@@ -26,29 +26,27 @@ import lombok.extern.slf4j.Slf4j;
public class ImageProcessingUtils { public class ImageProcessingUtils {
static BufferedImage convertColorType(BufferedImage sourceImage, String colorType) { static BufferedImage convertColorType(BufferedImage sourceImage, String colorType) {
BufferedImage convertedImage; return switch (colorType) {
switch (colorType) { case "greyscale" -> {
case "greyscale": BufferedImage convertedImage =
convertedImage =
new BufferedImage( new BufferedImage(
sourceImage.getWidth(), sourceImage.getWidth(),
sourceImage.getHeight(), sourceImage.getHeight(),
BufferedImage.TYPE_BYTE_GRAY); BufferedImage.TYPE_BYTE_GRAY);
convertedImage.getGraphics().drawImage(sourceImage, 0, 0, null); convertedImage.getGraphics().drawImage(sourceImage, 0, 0, null);
break; yield convertedImage;
case "blackwhite": }
convertedImage = case "blackwhite" -> {
BufferedImage convertedImage =
new BufferedImage( new BufferedImage(
sourceImage.getWidth(), sourceImage.getWidth(),
sourceImage.getHeight(), sourceImage.getHeight(),
BufferedImage.TYPE_BYTE_BINARY); BufferedImage.TYPE_BYTE_BINARY);
convertedImage.getGraphics().drawImage(sourceImage, 0, 0, null); convertedImage.getGraphics().drawImage(sourceImage, 0, 0, null);
break; yield convertedImage;
default: // full color }
convertedImage = sourceImage; default -> sourceImage;
break; };
}
return convertedImage;
} }
public static byte[] getImageData(BufferedImage image) { public static byte[] getImageData(BufferedImage image) {
@@ -330,7 +330,7 @@ public class PDFToFile {
if (outputFiles.size() == 1) { if (outputFiles.size() == 1) {
// Return single output file // Return single output file
File outputFile = outputFiles.get(0); File outputFile = outputFiles.getFirst();
if ("txt:Text".equals(outputFormat)) { if ("txt:Text".equals(outputFormat)) {
outputFormat = "txt"; outputFormat = "txt";
} }
@@ -307,7 +307,7 @@ public class ProcessExecutor {
boolean isQpdf = boolean isQpdf =
commandToRun != null commandToRun != null
&& !commandToRun.isEmpty() && !commandToRun.isEmpty()
&& commandToRun.get(0).contains("qpdf"); && commandToRun.getFirst().contains("qpdf");
if (!outputLines.isEmpty()) { if (!outputLines.isEmpty()) {
String outputMessage = String.join("\n", outputLines); String outputMessage = String.join("\n", outputLines);
@@ -370,7 +370,7 @@ public class ProcessExecutor {
} }
// Check if this is a UNO conversion by looking for unoconvert executable // Check if this is a UNO conversion by looking for unoconvert executable
String executable = command.get(0); String executable = command.getFirst();
if (executable != null) { if (executable != null) {
// Extract basename from path for matching // Extract basename from path for matching
String basename = executable; String basename = executable;
@@ -504,7 +504,7 @@ public class ProcessExecutor {
} }
// Validate executable (first argument) // Validate executable (first argument)
String executable = command.get(0); String executable = command.getFirst();
if (executable == null || executable.isBlank()) { if (executable == null || executable.isBlank()) {
throw new IllegalArgumentException("Command executable must not be empty"); throw new IllegalArgumentException("Command executable must not be empty");
} }
@@ -114,7 +114,7 @@ public class YamlHelper {
for (NodeTuple tuple : mappingNode.getValue()) { for (NodeTuple tuple : mappingNode.getValue()) {
ScalarNode keyNode = (tuple.getKeyNode() instanceof ScalarNode sk) ? sk : null; ScalarNode keyNode = (tuple.getKeyNode() instanceof ScalarNode sk) ? sk : null;
if (keyNode == null || !keyNode.getValue().equals(keys.get(0))) { if (keyNode == null || !keyNode.getValue().equals(keys.getFirst())) {
updatedTuples.add(tuple); updatedTuples.add(tuple);
continue; continue;
} }
@@ -721,7 +721,7 @@ class PDFToFileTest {
.thenAnswer( .thenAnswer(
invocation -> { invocation -> {
List<String> args = invocation.getArgument(0); List<String> args = invocation.getArgument(0);
String outputPath = args.get(args.size() - 1); String outputPath = args.getLast();
Files.write(Path.of(outputPath), "Fake DOCX content".getBytes()); Files.write(Path.of(outputPath), "Fake DOCX content".getBytes());
return mockExecutorResult; return mockExecutorResult;
}); });
@@ -1,6 +1,5 @@
package stirling.software.SPDF.config; package stirling.software.SPDF.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.servlet.MultipartConfigFactory; import org.springframework.boot.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@@ -22,7 +21,11 @@ import stirling.software.SPDF.controller.web.UploadLimitService;
@Slf4j @Slf4j
public class MultipartConfiguration { public class MultipartConfiguration {
@Autowired private UploadLimitService uploadLimitService; private final UploadLimitService uploadLimitService;
public MultipartConfiguration(UploadLimitService uploadLimitService) {
this.uploadLimitService = uploadLimitService;
}
/** /**
* Creates MultipartConfigElement that respects fileUploadLimit from settings.yml or environment * Creates MultipartConfigElement that respects fileUploadLimit from settings.yml or environment
@@ -294,24 +294,25 @@ public class BookletImpositionController {
// Apply rotation if needed (rotate about origin), then translate to keep in cell // Apply rotation if needed (rotate about origin), then translate to keep in cell
switch (rot) { switch (rot) {
case 90: case 90 -> {
cs.transform(Matrix.getRotateInstance(Math.PI / 2, 0, 0)); cs.transform(Matrix.getRotateInstance(Math.PI / 2, 0, 0));
// After 90° CCW, the content spans x in [-r.getHeight(), 0] and y in [0, // After 90° CCW, the content spans x in [-r.getHeight(), 0] and y in [0,
// r.getWidth()] // r.getWidth()]
cs.transform(Matrix.getTranslateInstance(0, -r.getWidth())); cs.transform(Matrix.getTranslateInstance(0, -r.getWidth()));
break; }
case 180: case 180 -> {
cs.transform(Matrix.getRotateInstance(Math.PI, 0, 0)); cs.transform(Matrix.getRotateInstance(Math.PI, 0, 0));
cs.transform(Matrix.getTranslateInstance(-r.getWidth(), -r.getHeight())); cs.transform(Matrix.getTranslateInstance(-r.getWidth(), -r.getHeight()));
break; }
case 270: case 270 -> {
cs.transform(Matrix.getRotateInstance(3 * Math.PI / 2, 0, 0)); cs.transform(Matrix.getRotateInstance(3 * Math.PI / 2, 0, 0));
// After 270° CCW, the content spans x in [0, r.getHeight()] and y in // After 270° CCW, the content spans x in [0, r.getHeight()] and y in
// [-r.getWidth(), 0] // [-r.getWidth(), 0]
cs.transform(Matrix.getTranslateInstance(-r.getHeight(), 0)); cs.transform(Matrix.getTranslateInstance(-r.getHeight(), 0));
break; }
default: default -> {
// 0°: no-op // 0°: no-op
}
} }
// Reuse LayerUtility passed from caller // Reuse LayerUtility passed from caller
@@ -9,7 +9,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
@@ -58,8 +57,6 @@ import stirling.software.jpdfium.doc.PdfBookmarkEditor.BookmarkTree;
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
public class MergeController { public class MergeController {
private static final Pattern QUOTE_WRAP_PATTERN = Pattern.compile("^\"|\"$");
private final CustomPDFDocumentFactory pdfDocumentFactory; private final CustomPDFDocumentFactory pdfDocumentFactory;
private final TempFileManager tempFileManager; private final TempFileManager tempFileManager;
@@ -161,30 +158,6 @@ public class MergeController {
}; };
} }
private String[] parseClientFileIds(String clientFileIds) {
if (clientFileIds == null || clientFileIds.trim().isEmpty()) {
return new String[0];
}
try {
String trimmed = clientFileIds.trim();
if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
String inside = trimmed.substring(1, trimmed.length() - 1).trim();
if (inside.isEmpty()) {
return new String[0];
}
String[] parts = inside.split(",");
String[] result = new String[parts.length];
for (int i = 0; i < parts.length; i++) {
result[i] = QUOTE_WRAP_PATTERN.matcher(parts[i].trim()).replaceAll("");
}
return result;
}
} catch (Exception e) {
log.warn("Failed to parse client file IDs: {}", clientFileIds, e);
}
return new String[0];
}
private void addTableOfContents(PDDocument mergedDocument, MultipartFile[] files) { private void addTableOfContents(PDDocument mergedDocument, MultipartFile[] files) {
PDDocumentOutline outline = new PDDocumentOutline(); PDDocumentOutline outline = new PDDocumentOutline();
mergedDocument.getDocumentCatalog().setDocumentOutline(outline); mergedDocument.getDocumentCatalog().setDocumentOutline(outline);
@@ -125,17 +125,14 @@ public class UIDataController {
pipelineConfigs.add(content); pipelineConfigs.add(content);
} }
for (String config : pipelineConfigs) { for (int i = 0; i < pipelineConfigs.size(); i++) {
String config = pipelineConfigs.get(i);
Map<String, Object> jsonContent = Map<String, Object> jsonContent =
objectMapper.readValue( objectMapper.readValue(
config, new TypeReference<Map<String, Object>>() {}); config, new TypeReference<Map<String, Object>>() {});
String name = (String) jsonContent.get("name"); String name = (String) jsonContent.get("name");
if (name == null || name.length() < 1) { if (name == null || name.length() < 1) {
String filename = String filename = jsonFiles.get(i).getFileName().toString();
jsonFiles
.get(pipelineConfigs.indexOf(config))
.getFileName()
.toString();
name = filename.substring(0, filename.lastIndexOf('.')); name = filename.substring(0, filename.lastIndexOf('.'));
} }
Map<String, String> configWithName = new HashMap<>(); Map<String, String> configWithName = new HashMap<>();
@@ -301,20 +298,14 @@ public class UIDataController {
} }
private static String getFormatFromExtension(String extension) { private static String getFormatFromExtension(String extension) {
switch (extension) { return switch (extension) {
case "ttf": case "ttf" -> "truetype";
return "truetype"; case "woff" -> "woff";
case "woff": case "woff2" -> "woff2";
return "woff"; case "eot" -> "embedded-opentype";
case "woff2": case "svg" -> "svg";
return "woff2"; default -> "";
case "eot": };
return "embedded-opentype";
case "svg":
return "svg";
default:
return "";
}
} }
} }
} }
@@ -187,7 +187,7 @@ public class ConvertImgPDFController {
} }
if (webpFiles.size() == 1) { if (webpFiles.size() == 1) {
Path webpFilePath = webpFiles.get(0); Path webpFilePath = webpFiles.getFirst();
byte[] webpBytes = Files.readAllBytes(webpFilePath); byte[] webpBytes = Files.readAllBytes(webpFilePath);
Files.deleteIfExists(tempFile); Files.deleteIfExists(tempFile);
tempFile = null; tempFile = null;
@@ -147,7 +147,7 @@ public class ConvertSvgToPDF {
String outputFilename = String outputFilename =
filenames.isEmpty() filenames.isEmpty()
? "combined_svgs.pdf" ? "combined_svgs.pdf"
: GeneralUtils.generateFilename(filenames.get(0), "_combined.pdf"); : GeneralUtils.generateFilename(filenames.getFirst(), "_combined.pdf");
log.info("Successfully combined {} SVGs into single PDF", sanitizedSvgs.size()); log.info("Successfully combined {} SVGs into single PDF", sanitizedSvgs.size());
@@ -203,7 +203,7 @@ public class ConvertSvgToPDF {
try { try {
if (convertedPdfs.size() == 1) { if (convertedPdfs.size() == 1) {
ConvertedPdf pdf = convertedPdfs.get(0); ConvertedPdf pdf = convertedPdfs.getFirst();
TempFile tempOut = tempFileManager.createManagedTempFile(".pdf"); TempFile tempOut = tempFileManager.createManagedTempFile(".pdf");
try { try {
Files.write(tempOut.getPath(), pdf.content); Files.write(tempOut.getPath(), pdf.content);
@@ -218,7 +218,7 @@ public class ConvertSvgToPDF {
filenames.isEmpty() filenames.isEmpty()
? "converted_svgs.zip" ? "converted_svgs.zip"
: GeneralUtils.generateFilename( : GeneralUtils.generateFilename(
filenames.get(0), "_converted_svgs.zip"); filenames.getFirst(), "_converted_svgs.zip");
TempFile zipFile = createZipFromPdfs(convertedPdfs); TempFile zipFile = createZipFromPdfs(convertedPdfs);
return WebResponseUtils.zipFileToWebResponse(zipFile, zipFilename); return WebResponseUtils.zipFileToWebResponse(zipFile, zipFilename);
} catch (IOException e) { } catch (IOException e) {
@@ -82,7 +82,7 @@ public class ExtractCSVController {
if (csvEntries.isEmpty()) { if (csvEntries.isEmpty()) {
return ResponseEntity.noContent().build(); return ResponseEntity.noContent().build();
} else if (csvEntries.size() == 1) { } else if (csvEntries.size() == 1) {
return createCsvResponse(csvEntries.get(0), baseName); return createCsvResponse(csvEntries.getFirst(), baseName);
} else { } else {
return createZipResponse(csvEntries, baseName); return createZipResponse(csvEntries, baseName);
} }
@@ -113,7 +113,9 @@ public class AutoRenameController {
mergedLineInfos.sort( mergedLineInfos.sort(
Comparator.comparing((LineInfo li) -> li.fontSize).reversed()); Comparator.comparing((LineInfo li) -> li.fontSize).reversed());
String title = String title =
mergedLineInfos.isEmpty() ? null : mergedLineInfos.get(0).text; mergedLineInfos.isEmpty()
? null
: mergedLineInfos.getFirst().text;
return title != null return title != null
? title ? title
@@ -333,7 +333,7 @@ public class AutoSplitPdfController {
} }
if (!splitDocuments.isEmpty() && !isValidQrCode) { if (!splitDocuments.isEmpty() && !isValidQrCode) {
splitDocuments.get(splitDocuments.size() - 1).addPage(document.getPage(page)); splitDocuments.getLast().addPage(document.getPage(page));
} else if (page == 0) { } else if (page == 0) {
PDDocument firstDocument = new PDDocument(); PDDocument firstDocument = new PDDocument();
firstDocument.addPage(document.getPage(page)); firstDocument.addPage(document.getPage(page));
@@ -267,7 +267,7 @@ public class CompressController {
if (references.isEmpty()) continue; if (references.isEmpty()) continue;
// Get the first instance of this image // Get the first instance of this image
PDImageXObject originalImage = getOriginalImage(doc, references.get(0)); PDImageXObject originalImage = getOriginalImage(doc, references.getFirst());
// Track original size // Track original size
int originalSize = (int) originalImage.getCOSObject().getLength(); int originalSize = (int) originalImage.getCOSObject().getLength();
@@ -1167,7 +1167,7 @@ public class CompressController {
List<ImageReference> references = entry.getValue(); List<ImageReference> references = entry.getValue();
if (references.isEmpty()) continue; if (references.isEmpty()) continue;
PDImageXObject originalImage = getOriginalImage(doc, references.get(0)); PDImageXObject originalImage = getOriginalImage(doc, references.getFirst());
int originalSize = (int) originalImage.getCOSObject().getLength(); int originalSize = (int) originalImage.getCOSObject().getLength();
stats.totalOriginalBytes += originalSize; stats.totalOriginalBytes += originalSize;
@@ -211,7 +211,7 @@ public class ExtractImageScansController {
} else { } else {
// Return the processed image as a response // Return the processed image as a response
byte[] imageBytes = processedImageBytes.get(0); byte[] imageBytes = processedImageBytes.getFirst();
finalOutput = tempFileManager.createManagedTempFile(".png"); finalOutput = tempFileManager.createManagedTempFile(".png");
try (OutputStream out = Files.newOutputStream(finalOutput.getPath())) { try (OutputStream out = Files.newOutputStream(finalOutput.getPath())) {
out.write(imageBytes); out.write(imageBytes);
@@ -404,7 +404,7 @@ public class CertSignController {
PDAcroForm acroForm = new PDAcroForm(doc); PDAcroForm acroForm = new PDAcroForm(doc);
doc.getDocumentCatalog().setAcroForm(acroForm); doc.getDocumentCatalog().setAcroForm(acroForm);
PDSignatureField signatureField = new PDSignatureField(acroForm); PDSignatureField signatureField = new PDSignatureField(acroForm);
PDAnnotationWidget widget = signatureField.getWidgets().get(0); PDAnnotationWidget widget = signatureField.getWidgets().getFirst();
List<PDField> acroFormFields = acroForm.getFields(); List<PDField> acroFormFields = acroForm.getFields();
acroForm.setSignaturesExist(true); acroForm.setSignaturesExist(true);
acroForm.setAppendOnly(true); acroForm.setAppendOnly(true);
@@ -634,7 +634,7 @@ class RedactExecuteService {
PageColumnLayout layout = PageColumnLayout layout =
PageColumnLayout.fromLineBoxes(extractor.getLineBoxes(), pageWidth); PageColumnLayout.fromLineBoxes(extractor.getLineBoxes(), pageWidth);
if (layout.columnCount() > 1) { if (layout.columnCount() > 1) {
float[] g = layout.gutters().get(0); float[] g = layout.gutters().getFirst();
log.info( log.info(
"[redact/execute] page {} layout: 2 cols, gutter x=[{}, {}]", "[redact/execute] page {} layout: 2 cols, gutter x=[{}, {}]",
pageIdx + 1, pageIdx + 1,
@@ -60,7 +60,7 @@ public class RemoveCertSignController {
// Remove signature fields safely // Remove signature fields safely
List<PDField> fieldsToRemove = List<PDField> fieldsToRemove =
acroForm.getFields().stream() acroForm.getFields().stream()
.filter(field -> field instanceof PDSignatureField) .filter(PDSignatureField.class::isInstance)
.toList(); .toList();
if (!fieldsToRemove.isEmpty()) { if (!fieldsToRemove.isEmpty()) {
@@ -2,7 +2,6 @@ package stirling.software.SPDF.controller.web;
import java.util.Locale; import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -13,7 +12,11 @@ import stirling.software.common.model.ApplicationProperties;
@Slf4j @Slf4j
public class UploadLimitService { public class UploadLimitService {
@Autowired private ApplicationProperties applicationProperties; private final ApplicationProperties applicationProperties;
public UploadLimitService(ApplicationProperties applicationProperties) {
this.applicationProperties = applicationProperties;
}
public long getUploadLimit() { public long getUploadLimit() {
String raw = String raw =
@@ -2688,7 +2688,7 @@ public class PdfJsonConversionService {
// Find which page the field is on // Find which page the field is on
PDAnnotationWidget widget = PDAnnotationWidget widget =
field.getWidgets().isEmpty() ? null : field.getWidgets().get(0); field.getWidgets().isEmpty() ? null : field.getWidgets().getFirst();
if (widget != null) { if (widget != null) {
PDPage fieldPage = widget.getPage(); PDPage fieldPage = widget.getPage();
if (fieldPage != null) { if (fieldPage != null) {
@@ -3164,7 +3164,7 @@ public class PdfJsonConversionService {
&& imageObjectNames != null && imageObjectNames != null
&& !imageObjectNames.isEmpty() && !imageObjectNames.isEmpty()
&& !targetTokens.isEmpty()) { && !targetTokens.isEmpty()) {
Object previous = targetTokens.get(targetTokens.size() - 1); Object previous = targetTokens.getLast();
if (previous instanceof COSName cosName if (previous instanceof COSName cosName
&& imageObjectNames.contains(cosName.getName())) { && imageObjectNames.contains(cosName.getName())) {
targetTokens.remove(targetTokens.size() - 1); targetTokens.remove(targetTokens.size() - 1);
@@ -5246,7 +5246,7 @@ public class PdfJsonConversionService {
throws IOException { throws IOException {
if (OperatorName.DRAW_OBJECT.equals(operator.getName()) if (OperatorName.DRAW_OBJECT.equals(operator.getName())
&& !operands.isEmpty() && !operands.isEmpty()
&& operands.get(0) instanceof COSName name) { && operands.getFirst() instanceof COSName name) {
currentXObjectName = name; currentXObjectName = name;
} }
super.processOperator(operator, operands); super.processOperator(operator, operands);
@@ -420,7 +420,7 @@ public class PdfJsonImageService {
throws IOException { throws IOException {
if (OperatorName.DRAW_OBJECT.equals(operator.getName()) if (OperatorName.DRAW_OBJECT.equals(operator.getName())
&& !operands.isEmpty() && !operands.isEmpty()
&& operands.get(0) instanceof COSName name) { && operands.getFirst() instanceof COSName name) {
currentXObjectName = name; currentXObjectName = name;
} }
super.processOperator(operator, operands); super.processOperator(operator, operands);
@@ -137,7 +137,7 @@ public class JobController {
if (result.hasFiles() && !result.hasMultipleFiles()) { if (result.hasFiles() && !result.hasMultipleFiles()) {
try { try {
List<ResultFile> files = result.getAllResultFiles(); List<ResultFile> files = result.getAllResultFiles();
ResultFile singleFile = files.get(0); ResultFile singleFile = files.getFirst();
byte[] fileContent = fileStorage.retrieveBytes(singleFile.getFileId()); byte[] fileContent = fileStorage.retrieveBytes(singleFile.getFileId());
return ResponseEntity.ok() return ResponseEntity.ok()
@@ -4,8 +4,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.lang.reflect.Field;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
@@ -24,10 +22,7 @@ class MultipartConfigurationTest {
void setUp() throws Exception { void setUp() throws Exception {
// Manually constructed config with a mocked service, so Spring env overrides do not apply. // Manually constructed config with a mocked service, so Spring env overrides do not apply.
uploadLimitService = mock(UploadLimitService.class); uploadLimitService = mock(UploadLimitService.class);
configuration = new MultipartConfiguration(); configuration = new MultipartConfiguration(uploadLimitService);
Field field = MultipartConfiguration.class.getDeclaredField("uploadLimitService");
field.setAccessible(true);
field.set(configuration, uploadLimitService);
} }
@Nested @Nested
@@ -84,12 +84,6 @@ class MergeControllerGapTest {
return (MultipartFile[]) m.invoke(null, files, fileOrder); return (MultipartFile[]) m.invoke(null, files, fileOrder);
} }
private String[] parseClientFileIds(String value) throws Exception {
Method m = MergeController.class.getDeclaredMethod("parseClientFileIds", String.class);
m.setAccessible(true);
return (String[]) m.invoke(mergeController, value);
}
private long getPdfDateTimeSafe(MultipartFile file) throws Exception { private long getPdfDateTimeSafe(MultipartFile file) throws Exception {
Method m = Method m =
MergeController.class.getDeclaredMethod("getPdfDateTimeSafe", MultipartFile.class); MergeController.class.getDeclaredMethod("getPdfDateTimeSafe", MultipartFile.class);
@@ -331,58 +325,6 @@ class MergeControllerGapTest {
} }
} }
// ---- parseClientFileIds -------------------------------------------------
@Nested
@DisplayName("parseClientFileIds")
class ParseClientFileIds {
@Test
@DisplayName("null input returns empty array")
void nullReturnsEmpty() throws Exception {
assertEquals(0, parseClientFileIds(null).length);
}
@Test
@DisplayName("blank input returns empty array")
void blankReturnsEmpty() throws Exception {
assertEquals(0, parseClientFileIds(" ").length);
}
@Test
@DisplayName("empty JSON array returns empty array")
void emptyArrayReturnsEmpty() throws Exception {
assertEquals(0, parseClientFileIds("[]").length);
assertEquals(0, parseClientFileIds("[ ]").length);
}
@Test
@DisplayName("non-array text returns empty array")
void nonArrayReturnsEmpty() throws Exception {
assertEquals(0, parseClientFileIds("not-an-array").length);
}
@Test
@DisplayName("parses quoted, comma-separated ids and strips surrounding quotes")
void parsesQuotedIds() throws Exception {
String[] result = parseClientFileIds("[\"id1\", \"id2\",\"id3\"]");
assertArrayEquals(new String[] {"id1", "id2", "id3"}, result);
}
@Test
@DisplayName("parses unquoted ids as-is after trimming")
void parsesUnquotedIds() throws Exception {
String[] result = parseClientFileIds("[a, b , c]");
assertArrayEquals(new String[] {"a", "b", "c"}, result);
}
@Test
@DisplayName("single element array yields a one-element result")
void singleElement() throws Exception {
assertArrayEquals(new String[] {"only"}, parseClientFileIds("[\"only\"]"));
}
}
// ---- reorderFilesByProvidedOrder ---------------------------------------- // ---- reorderFilesByProvidedOrder ----------------------------------------
@Nested @Nested
@@ -0,0 +1,66 @@
package stirling.software.SPDF.controller.api;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.http.ResponseEntity;
import stirling.software.SPDF.service.SharedSignatureService;
import stirling.software.common.configuration.RuntimePathConfig;
import stirling.software.common.model.ApplicationProperties;
import tools.jackson.databind.ObjectMapper;
class UIDataControllerTest {
@TempDir Path tempDir;
@Test
void getPipelineData_usesEachSourceFilenameWhenJsonContentIsIdentical() throws Exception {
Path configDir = tempDir.resolve("defaultWebUIConfigs");
Files.createDirectories(configDir);
String configJson = "{\"steps\":[]}";
Files.writeString(configDir.resolve("first-config.json"), configJson);
Files.writeString(configDir.resolve("second-config.json"), configJson);
ApplicationProperties applicationProperties = mock(ApplicationProperties.class);
SharedSignatureService signatureService = mock(SharedSignatureService.class);
RuntimePathConfig runtimePathConfig = mock(RuntimePathConfig.class);
when(runtimePathConfig.getPipelineDefaultWebUiConfigs()).thenReturn(configDir.toString());
UIDataController controller =
new UIDataController(
applicationProperties,
signatureService,
null,
new DefaultResourceLoader(),
runtimePathConfig,
new ObjectMapper());
ResponseEntity<UIDataController.PipelineData> response = controller.getPipelineData();
assertThat(response.getStatusCode().is2xxSuccessful()).isTrue();
UIDataController.PipelineData body = response.getBody();
assertThat(body).isNotNull();
List<Map<String, String>> configsWithNames = body.getPipelineConfigsWithNames();
assertThat(configsWithNames).hasSize(2);
assertThat(configsWithNames)
.extracting(entry -> entry.get("name"))
.containsExactlyInAnyOrder("first-config", "second-config");
assertThat(configsWithNames)
.extracting(entry -> entry.get("json"))
.containsOnly(configJson);
}
}
@@ -204,7 +204,7 @@ class ConvertOfficeControllerTest {
inv -> { inv -> {
// unoconvert writes directly to the output path (last arg) // unoconvert writes directly to the output path (last arg)
List<String> command = inv.getArgument(0); List<String> command = inv.getArgument(0);
Path out = Path.of(command.get(command.size() - 1)); Path out = Path.of(command.getLast());
Files.writeString(out, "%PDF-1.4 produced"); Files.writeString(out, "%PDF-1.4 produced");
return result; return result;
}); });
@@ -239,7 +239,7 @@ class ConvertOfficeControllerTest {
inv -> { inv -> {
// soffice writes <basename>.pdf into the --outdir (workDir) // soffice writes <basename>.pdf into the --outdir (workDir)
List<String> command = inv.getArgument(0); List<String> command = inv.getArgument(0);
Path inputPath = Path.of(command.get(command.size() - 1)); Path inputPath = Path.of(command.getLast());
Path out = inputPath.getParent().resolve("report.pdf"); Path out = inputPath.getParent().resolve("report.pdf");
Files.writeString(out, "%PDF soffice"); Files.writeString(out, "%PDF soffice");
return result; return result;
@@ -311,7 +311,7 @@ class ConvertOfficeControllerTest {
.thenAnswer( .thenAnswer(
inv -> { inv -> {
List<String> command = inv.getArgument(0); List<String> command = inv.getArgument(0);
Path inputPath = Path.of(command.get(command.size() - 1)); Path inputPath = Path.of(command.getLast());
Path out = inputPath.getParent().resolve("report.pdf"); Path out = inputPath.getParent().resolve("report.pdf");
Files.write(out, new byte[0]); Files.write(out, new byte[0]);
return result; return result;
@@ -344,7 +344,7 @@ class ConvertOfficeControllerTest {
.thenAnswer( .thenAnswer(
inv -> { inv -> {
List<String> command = inv.getArgument(0); List<String> command = inv.getArgument(0);
Path inputPath = Path.of(command.get(command.size() - 1)); Path inputPath = Path.of(command.getLast());
Path out = inputPath.getParent().resolve("page.pdf"); Path out = inputPath.getParent().resolve("page.pdf");
Files.writeString(out, "%PDF html"); Files.writeString(out, "%PDF html");
return result; return result;
@@ -398,7 +398,7 @@ class ConvertOfficeControllerTest {
.thenAnswer( .thenAnswer(
inv -> { inv -> {
List<String> command = inv.getArgument(0); List<String> command = inv.getArgument(0);
Path inputPath = Path.of(command.get(command.size() - 1)); Path inputPath = Path.of(command.getLast());
Path out = inputPath.getParent().resolve("report.pdf"); Path out = inputPath.getParent().resolve("report.pdf");
Files.writeString(out, "%PDF produced"); Files.writeString(out, "%PDF produced");
return result; return result;
@@ -197,7 +197,7 @@ class ConvertPDFToPDFAMoreTest {
// qpdf normalize/clean writes its (last-arg) output file // qpdf normalize/clean writes its (last-arg) output file
if (command.contains("--normalize-content=y")) { if (command.contains("--normalize-content=y")) {
// qpdf produced file is the last argument // qpdf produced file is the last argument
Path out = Path.of(command.get(command.size() - 1)); Path out = Path.of(command.getLast());
Files.write(out, simplePdfBytes()); Files.write(out, simplePdfBytes());
} }
return okResult; return okResult;
@@ -262,7 +262,7 @@ class ConvertPdfToVideoControllerTest {
assertTrue(command.contains("+faststart")); assertTrue(command.contains("+faststart"));
assertFalse(command.contains("libvpx-vp9")); assertFalse(command.contains("libvpx-vp9"));
// Output path is always the last argument. // Output path is always the last argument.
assertEquals(backing.getAbsolutePath(), command.get(command.size() - 1)); assertEquals(backing.getAbsolutePath(), command.getLast());
} }
@Test @Test
@@ -278,7 +278,7 @@ class ConvertPdfToVideoControllerTest {
assertTrue(command.contains("30")); assertTrue(command.contains("30"));
assertFalse(command.contains("libx264")); assertFalse(command.contains("libx264"));
assertFalse(command.contains("+faststart")); assertFalse(command.contains("+faststart"));
assertEquals(backing.getAbsolutePath(), command.get(command.size() - 1)); assertEquals(backing.getAbsolutePath(), command.getLast());
} }
@Test @Test
@@ -195,7 +195,7 @@ class CompressControllerMoreTest {
// The qpdf output path is the last argument of the command. // The qpdf output path is the last argument of the command.
private static Path qpdfOutputPath(List<String> command) { private static Path qpdfOutputPath(List<String> command) {
return Path.of(command.get(command.size() - 1)); return Path.of(command.getLast());
} }
/** Stub gs to write a valid PDF to its output file and report success. */ /** Stub gs to write a valid PDF to its output file and report success. */
@@ -162,7 +162,7 @@ class RemoveImagesControllerTest {
/** Counts every PDImageXObject reachable through page + nested form resources. */ /** Counts every PDImageXObject reachable through page + nested form resources. */
private int countImagesInSavedOutput() throws IOException { private int countImagesInSavedOutput() throws IOException {
assertFalse(savedTempFiles.isEmpty(), "expected the controller to create a temp file"); assertFalse(savedTempFiles.isEmpty(), "expected the controller to create a temp file");
File out = savedTempFiles.get(savedTempFiles.size() - 1); File out = savedTempFiles.getLast();
try (PDDocument doc = Loader.loadPDF(out)) { try (PDDocument doc = Loader.loadPDF(out)) {
int count = 0; int count = 0;
for (PDPage page : doc.getPages()) { for (PDPage page : doc.getPages()) {
@@ -245,7 +245,7 @@ class RemoveImagesControllerTest {
assertEquals(0, countImagesInSavedOutput()); assertEquals(0, countImagesInSavedOutput());
// page count must be preserved // page count must be preserved
File out = savedTempFiles.get(savedTempFiles.size() - 1); File out = savedTempFiles.getLast();
try (PDDocument result = Loader.loadPDF(out)) { try (PDDocument result = Loader.loadPDF(out)) {
assertEquals(3, result.getNumberOfPages()); assertEquals(3, result.getNumberOfPages());
} }
@@ -98,12 +98,8 @@ class RepairControllerMoreTest {
} }
} }
/** /** Writes a valid PDF to the given output path, mimicking a successful tool run. */
* Writes a valid PDF to the path at the given command index, mimicking a successful tool run. private static void writeValidPdfTo(Path out) throws Exception {
*/
private static void writeValidPdfTo(List<String> command, int outputPathIndex)
throws Exception {
Path out = Path.of(command.get(outputPathIndex));
byte[] pdf = buildPdfBytes(1); byte[] pdf = buildPdfBytes(1);
Files.write(out, pdf); Files.write(out, pdf);
} }
@@ -133,7 +129,7 @@ class RepairControllerMoreTest {
.thenAnswer( .thenAnswer(
inv -> { inv -> {
List<String> cmd = inv.getArgument(0); List<String> cmd = inv.getArgument(0);
writeValidPdfTo(cmd, 2); writeValidPdfTo(Path.of(cmd.get(2)));
return okResult; return okResult;
}); });
@@ -176,7 +172,7 @@ class RepairControllerMoreTest {
.thenAnswer( .thenAnswer(
inv -> { inv -> {
List<String> cmd = inv.getArgument(0); List<String> cmd = inv.getArgument(0);
writeValidPdfTo(cmd, cmd.size() - 1); writeValidPdfTo(Path.of(cmd.getLast()));
return okResult; return okResult;
}); });
@@ -216,7 +212,7 @@ class RepairControllerMoreTest {
.thenAnswer( .thenAnswer(
inv -> { inv -> {
List<String> cmd = inv.getArgument(0); List<String> cmd = inv.getArgument(0);
writeValidPdfTo(cmd, cmd.size() - 1); writeValidPdfTo(Path.of(cmd.getLast()));
return okResult; return okResult;
}); });
@@ -256,7 +252,7 @@ class RepairControllerMoreTest {
.thenAnswer( .thenAnswer(
inv -> { inv -> {
List<String> cmd = inv.getArgument(0); List<String> cmd = inv.getArgument(0);
writeValidPdfTo(cmd, cmd.size() - 1); writeValidPdfTo(Path.of(cmd.getLast()));
return okResult; return okResult;
}); });
@@ -49,15 +49,7 @@ class UploadLimitServiceTest {
systemProps = mock(ApplicationProperties.System.class); systemProps = mock(ApplicationProperties.System.class);
when(applicationProperties.getSystem()).thenReturn(systemProps); when(applicationProperties.getSystem()).thenReturn(systemProps);
uploadLimitService = new UploadLimitService(); uploadLimitService = new UploadLimitService(applicationProperties);
// inject mock
try {
var field = UploadLimitService.class.getDeclaredField("applicationProperties");
field.setAccessible(true);
field.set(uploadLimitService, applicationProperties);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
} }
@ParameterizedTest(name = "getReadableUploadLimit case #{index}: rawValue={0}, expected={1}") @ParameterizedTest(name = "getReadableUploadLimit case #{index}: rawValue={0}, expected={1}")
@@ -143,19 +143,12 @@ public class AuditRestController {
@RequestParam(value = "period", defaultValue = "week") String period) { @RequestParam(value = "period", defaultValue = "week") String period) {
// Calculate days based on period // Calculate days based on period
int days; int days =
switch (period.toLowerCase()) { switch (period.toLowerCase()) {
case "day": case "day" -> 1;
days = 1; case "month" -> 30;
break; default -> 7;
case "month": };
days = 30;
break;
case "week":
default:
days = 7;
break;
}
// Get events from the specified period // Get events from the specified period
Instant startDate = Instant.now().minus(java.time.Duration.ofDays(days)); Instant startDate = Instant.now().minus(java.time.Duration.ofDays(days));
@@ -269,19 +262,12 @@ public class AuditRestController {
@RequestParam(value = "period", defaultValue = "week") String period) { @RequestParam(value = "period", defaultValue = "week") String period) {
// Calculate days based on period // Calculate days based on period
int days; int days =
switch (period.toLowerCase()) { switch (period.toLowerCase()) {
case "day": case "day" -> 1;
days = 1; case "month" -> 30;
break; default -> 7;
case "month": };
days = 30;
break;
case "week":
default:
days = 7;
break;
}
// Get events from the specified period and previous period // Get events from the specified period and previous period
Instant now = Instant.now(); Instant now = Instant.now();
@@ -754,7 +740,7 @@ public class AuditRestController {
List<Map<String, Object>> files = List<Map<String, Object>> files =
(List<Map<String, Object>>) eventData.get("files"); (List<Map<String, Object>>) eventData.get("files");
if (files != null && !files.isEmpty()) { if (files != null && !files.isEmpty()) {
Map<String, Object> firstFile = files.get(0); Map<String, Object> firstFile = files.getFirst();
data.put("documentname", String.valueOf(firstFile.getOrDefault("name", ""))); data.put("documentname", String.valueOf(firstFile.getOrDefault("name", "")));
data.put("author", String.valueOf(firstFile.getOrDefault("pdfAuthor", ""))); data.put("author", String.valueOf(firstFile.getOrDefault("pdfAuthor", "")));
data.put("filehash", String.valueOf(firstFile.getOrDefault("fileHash", ""))); data.put("filehash", String.valueOf(firstFile.getOrDefault("fileHash", "")));
@@ -131,7 +131,7 @@ public class PolicyExecutor {
// One call over all inputs. The outputs derive from a single input only when exactly // One call over all inputs. The outputs derive from a single input only when exactly
// one entered; otherwise (a genuine merge) there is no single source. // one entered; otherwise (a genuine merge) there is no single source.
ToolResult r = callEndpoint(step, inputFiles, supportingFiles); ToolResult r = callEndpoint(step, inputFiles, supportingFiles);
Integer origin = inputOrigins.size() == 1 ? inputOrigins.get(0) : null; Integer origin = inputOrigins.size() == 1 ? inputOrigins.getFirst() : null;
for (Resource file : r.files()) { for (Resource file : r.files()) {
files.add(file); files.add(file);
origins.add(origin); origins.add(origin);
@@ -2,7 +2,6 @@ package stirling.software.proprietary.security.configuration;
import java.time.Duration; import java.time.Duration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.cache.caffeine.CaffeineCacheManager;
@@ -19,7 +18,6 @@ public class CacheConfig {
private final ApplicationProperties applicationProperties; private final ApplicationProperties applicationProperties;
@Autowired
public CacheConfig(ApplicationProperties applicationProperties) { public CacheConfig(ApplicationProperties applicationProperties) {
this.applicationProperties = applicationProperties; this.applicationProperties = applicationProperties;
} }
@@ -61,7 +61,7 @@ public class CustomSaml2ResponseAuthenticationConverter
@Override @Override
public Saml2Authentication convert(ResponseToken responseToken) { public Saml2Authentication convert(ResponseToken responseToken) {
Assertion assertion = responseToken.getResponse().getAssertions().get(0); Assertion assertion = responseToken.getResponse().getAssertions().getFirst();
Map<String, List<Object>> attributes = extractAttributes(assertion); Map<String, List<Object>> attributes = extractAttributes(assertion);
// Debug log with actual values // Debug log with actual values
@@ -113,6 +113,6 @@ public class CustomSaml2ResponseAuthenticationConverter
private String getFirstAttributeValue(Map<String, List<Object>> attributes, String name) { private String getFirstAttributeValue(Map<String, List<Object>> attributes, String name) {
List<Object> values = attributes.get(name); List<Object> values = attributes.get(name);
return values != null && !values.isEmpty() ? values.get(0).toString() : null; return values != null && !values.isEmpty() ? values.getFirst().toString() : null;
} }
} }
@@ -229,7 +229,7 @@ public class DatabaseService implements DatabaseServiceInterface {
List<FileInfo> backupList = this.getBackupList(); List<FileInfo> backupList = this.getBackupList();
backupList.sort(Comparator.comparing(FileInfo::getModificationDate).reversed()); backupList.sort(Comparator.comparing(FileInfo::getModificationDate).reversed());
Path latestExport = Path.of(backupList.get(0).getFilePath()); Path latestExport = Path.of(backupList.getFirst().getFilePath());
executeDatabaseScript(latestExport); executeDatabaseScript(latestExport);
} }
@@ -373,7 +373,7 @@ public class DatabaseService implements DatabaseServiceInterface {
List<FileInfo> backupList = this.getBackupList(); List<FileInfo> backupList = this.getBackupList();
List<Pair<FileInfo, Boolean>> deletedFiles = new ArrayList<>(); List<Pair<FileInfo, Boolean>> deletedFiles = new ArrayList<>();
if (!backupList.isEmpty()) { if (!backupList.isEmpty()) {
FileInfo lastBackup = backupList.get(backupList.size() - 1); FileInfo lastBackup = backupList.getLast();
try { try {
Files.deleteIfExists(Path.of(lastBackup.getFilePath())); Files.deleteIfExists(Path.of(lastBackup.getFilePath()));
deletedFiles.add(Pair.of(lastBackup, true)); deletedFiles.add(Pair.of(lastBackup, true));
@@ -396,7 +396,7 @@ public class DatabaseService implements DatabaseServiceInterface {
Comparator.comparing( Comparator.comparing(
p -> p.getFileName().substring(7, p.getFileName().length() - 4))); p -> p.getFileName().substring(7, p.getFileName().length() - 4)));
FileInfo oldestFile = filteredBackupList.get(0); FileInfo oldestFile = filteredBackupList.getFirst();
Files.deleteIfExists(Path.of(oldestFile.getFilePath())); Files.deleteIfExists(Path.of(oldestFile.getFilePath()));
log.info("Deleted oldest backup: {}", oldestFile.getFileName()); log.info("Deleted oldest backup: {}", oldestFile.getFileName());
} catch (IOException e) { } catch (IOException e) {
@@ -261,8 +261,8 @@ public class KeyPersistenceService implements KeyPersistenceServiceInterface {
nativeCache.asMap().size()); nativeCache.asMap().size());
return nativeCache.asMap().values().stream() return nativeCache.asMap().values().stream()
.filter(value -> value instanceof JwtVerificationKey) .filter(JwtVerificationKey.class::isInstance)
.map(value -> (JwtVerificationKey) value) .map(JwtVerificationKey.class::cast)
.filter( .filter(
key -> { key -> {
boolean eligible = key.getCreatedAt().isBefore(cutoffDate); boolean eligible = key.getCreatedAt().isBefore(cutoffDate);
@@ -183,6 +183,6 @@ public class SessionPersistentRegistry implements SessionRegistry {
allSessions.sort((s1, s2) -> s2.getLastRequest().compareTo(s1.getLastRequest())); allSessions.sort((s1, s2) -> s2.getLastRequest().compareTo(s1.getLastRequest()));
// The first session in the list is the latest session for the given principal name // The first session in the list is the latest session for the given principal name
return Optional.of(allSessions.get(0)); return Optional.of(allSessions.getFirst());
} }
} }
@@ -230,7 +230,7 @@ public class PortalInfraAuditService {
Object files = data.get("files"); Object files = data.get("files");
if (files instanceof List<?> list if (files instanceof List<?> list
&& !list.isEmpty() && !list.isEmpty()
&& list.get(0) instanceof Map<?, ?> f) { && list.getFirst() instanceof Map<?, ?> f) {
Object name = ((Map<String, Object>) f).get("name"); Object name = ((Map<String, Object>) f).get("name");
return name != null ? String.valueOf(name) : null; return name != null ? String.valueOf(name) : null;
} }
@@ -119,20 +119,18 @@ public class UnifiedAccessControlService {
public ShareAccessRole getEffectiveRole(WorkflowParticipant participant) { public ShareAccessRole getEffectiveRole(WorkflowParticipant participant) {
ParticipantStatus status = participant.getStatus(); ParticipantStatus status = participant.getStatus();
switch (status) { return switch (status) {
case SIGNED: case SIGNED, DECLINED ->
case DECLINED: // After action completed, downgrade to read-only
// After action completed, downgrade to read-only ShareAccessRole.VIEWER;
return ShareAccessRole.VIEWER; case PENDING, NOTIFIED, VIEWED ->
case PENDING: // Active participants retain their assigned role
case NOTIFIED: participant.getAccessRole();
case VIEWED: default -> {
// Active participants retain their assigned role
return participant.getAccessRole();
default:
log.warn("Unknown participant status: {}", status); log.warn("Unknown participant status: {}", status);
return ShareAccessRole.VIEWER; yield ShareAccessRole.VIEWER;
} }
};
} }
/** Checks if a user can access a specific file */ /** Checks if a user can access a specific file */
@@ -152,7 +152,7 @@ public class AccountLinkController {
if (rows.isEmpty()) { if (rows.isEmpty()) {
return new LeaderTeam(null, null, HttpStatus.FORBIDDEN); return new LeaderTeam(null, null, HttpStatus.FORBIDDEN);
} }
TeamMembership m = rows.get(0); TeamMembership m = rows.getFirst();
if (m.getRole() != TeamRole.LEADER) { if (m.getRole() != TeamRole.LEADER) {
return new LeaderTeam(null, null, HttpStatus.FORBIDDEN); return new LeaderTeam(null, null, HttpStatus.FORBIDDEN);
} }
@@ -105,7 +105,7 @@ public class PaygInvoicesController {
if (rows.isEmpty()) { if (rows.isEmpty()) {
return ResponseEntity.ok(List.of()); return ResponseEntity.ok(List.of());
} }
Long teamId = rows.get(0).getTeam().getId(); Long teamId = rows.getFirst().getTeam().getId();
// No PAYG extension row OR no Stripe customer id → team has never subscribed → no // No PAYG extension row OR no Stripe customer id → team has never subscribed → no
// invoices. Empty list, not 404 — the UI distinguishes "no invoices yet" from a // invoices. Empty list, not 404 — the UI distinguishes "no invoices yet" from a
@@ -85,7 +85,7 @@ public class PaygPaymentMethodController {
if (rows.isEmpty()) { if (rows.isEmpty()) {
return ResponseEntity.ok(PaymentMethodResponse.absent()); return ResponseEntity.ok(PaymentMethodResponse.absent());
} }
Long teamId = rows.get(0).getTeam().getId(); Long teamId = rows.getFirst().getTeam().getId();
Optional<PaygTeamExtensions> ext = extRepo.findById(teamId); Optional<PaygTeamExtensions> ext = extRepo.findById(teamId);
if (ext.isEmpty() || ext.get().getStripeCustomerId() == null) { if (ext.isEmpty() || ext.get().getStripeCustomerId() == null) {
@@ -361,7 +361,7 @@ public class PaygWalletController {
private Optional<TeamMembership> primaryMembership(Long userId) { private Optional<TeamMembership> primaryMembership(Long userId) {
List<TeamMembership> rows = memberRepo.findPrimaryMembership(userId); List<TeamMembership> rows = memberRepo.findPrimaryMembership(userId);
return rows.isEmpty() ? Optional.empty() : Optional.of(rows.get(0)); return rows.isEmpty() ? Optional.empty() : Optional.of(rows.getFirst());
} }
private List<MemberRow> buildMemberRows( private List<MemberRow> buildMemberRows(
@@ -258,7 +258,7 @@ public class JobChargeService {
List<Path> paths = inputs.stream().map(JobInput::path).toList(); List<Path> paths = inputs.stream().map(JobInput::path).toList();
DocumentMetrics metrics = DocumentMetrics metrics =
multiparts.size() == 1 multiparts.size() == 1
? classifier.classify(multiparts.get(0), paths.get(0), policy) ? classifier.classify(multiparts.getFirst(), paths.getFirst(), policy)
: classifier.classify(multiparts, paths, policy); : classifier.classify(multiparts, paths, policy);
// Apply the policy-level minChargeUnits floor per design § 3.4. The classifier returns // Apply the policy-level minChargeUnits floor per design § 3.4. The classifier returns
// raw docUnits with a "non-empty input → ≥1" floor; the charge formula's // raw docUnits with a "non-empty input → ≥1" floor; the charge formula's
@@ -75,7 +75,7 @@ public class JpaJobLineageStore implements JobLineageStore {
List<LineageMatch> matches = List<LineageMatch> matches =
hashRepository.findOpenJobsForSignatures( hashRepository.findOpenJobsForSignatures(
userId, JobStatus.OPEN, since, storageKeys, Limit.of(1)); userId, JobStatus.OPEN, since, storageKeys, Limit.of(1));
return matches.isEmpty() ? Optional.empty() : Optional.of(matches.get(0)); return matches.isEmpty() ? Optional.empty() : Optional.of(matches.getFirst());
} }
@Override @Override
@@ -284,7 +284,7 @@ public class SupabaseAuthenticationFilter extends OncePerRequestFilter {
if (!(raw instanceof List<?> amrList) || amrList.isEmpty()) { if (!(raw instanceof List<?> amrList) || amrList.isEmpty()) {
return WEB; return WEB;
} }
Object first = amrList.get(0); Object first = amrList.getFirst();
if (!(first instanceof Map<?, ?> entry)) { if (!(first instanceof Map<?, ?> entry)) {
return WEB; return WEB;
} }