From 8dc95bd6d3bc53e72529f51b07936d8c7878aa9c Mon Sep 17 00:00:00 2001 From: Saurabh Parkhi <4743002+sparkhi@users.noreply.github.com> Date: Tue, 4 Nov 2025 10:06:54 +0000 Subject: [PATCH 1/3] Rollback jaxb-runtime until we figure out what is wrong with 4.0.6 and ignored 4.0.6 onwards from dependabot (#1510) --- .github/dependabot.yml | 3 +++ droid-parent/pom.xml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7c3694417..a4f1e9cf2 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,6 +6,9 @@ updates: interval: daily open-pull-requests-limit: 10 ignore: + - dependency-name: org.glassfish.jaxb:jaxb-runtime + versions: + - ">=4.0.6" - dependency-name: org.owasp:dependency-check-maven versions: - 6.1.0 diff --git a/droid-parent/pom.xml b/droid-parent/pom.xml index ba6d3f9b8..5f05625cf 100644 --- a/droid-parent/pom.xml +++ b/droid-parent/pom.xml @@ -98,7 +98,7 @@ 10.17.1.0 4.1.3 2.1.0 - 4.0.6 + 4.0.5 4.0.4 2.19.2 9.7.2 From f1a1369b36e730701353debd64a50c9ce52523f1 Mon Sep 17 00:00:00 2001 From: Saurabh Parkhi <4743002+sparkhi@users.noreply.github.com> Date: Wed, 5 Nov 2025 10:18:20 +0000 Subject: [PATCH 2/3] Dr2 2500 allow single line comments (#1507) * Support full line comments in export template * added info about comment line in help * Code simplification and grammar correction --- .../template/ExportTemplateBuilder.java | 30 +++++++------- .../template/ExportTemplateBuilderTest.java | 39 +++++++++++++++++++ .../src/main/resources/pages/export.html | 39 +++++++++++++------ 3 files changed, 82 insertions(+), 26 deletions(-) diff --git a/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ExportTemplateBuilder.java b/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ExportTemplateBuilder.java index d9856243e..f6444a398 100644 --- a/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ExportTemplateBuilder.java +++ b/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ExportTemplateBuilder.java @@ -42,7 +42,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; /** * Class to build export template from a file. @@ -57,6 +56,7 @@ public class ExportTemplateBuilder { private static final String OPENING_BRACKET = "("; private static final String CLOSING_BRACKET = ")"; private static final String DATA_COLUMN_PREFIX = "$"; + private static final String COMMENT_PREFIX = "//"; /** * The entry point into building an ExportTemplate object by reading a template file. @@ -70,7 +70,10 @@ public ExportTemplate buildExportTemplate(String pathToTemplate) { List templateLines; try { - templateLines = Files.readAllLines(Paths.get(pathToTemplate)); + templateLines = Files.readAllLines(Paths.get(pathToTemplate)).stream().filter(line -> { + String trimmedLine = line.trim(); + return !trimmedLine.isEmpty() && !trimmedLine.startsWith(COMMENT_PREFIX); + }).toList(); Map columnMap = buildColumnMap(templateLines); return new ExportTemplateImpl(columnMap); } catch (IOException e) { @@ -79,23 +82,23 @@ public ExportTemplate buildExportTemplate(String pathToTemplate) { } private Map buildColumnMap(List templateLines) { - if ((templateLines == null) || (templateLines.size() == 0)) { + if ((templateLines == null) || (templateLines.isEmpty())) { throw new ExportTemplateParseException("Export template is empty"); } - String versionLine = templateLines.get(0); + String versionLine = templateLines.getFirst(); String version = parseVersionLine(versionLine); //we have only one version at the moment, but future provision for versioning switch (version) { - case "1.0": + case "1.0" -> { return parseExportTemplateV1(templateLines.subList(1, templateLines.size())); - default: - throw new ExportTemplateParseException("Unsupported version for the export template"); + } + default -> throw new ExportTemplateParseException("Unsupported version for the export template"); } } private Map parseExportTemplateV1(List templateLines) { - List columnLines = templateLines.stream().filter(line -> line.trim().length() > 0).collect(Collectors.toList()); + List columnLines = templateLines.stream().filter(line -> !line.trim().isEmpty()).toList(); Map columnMap = new HashMap<>(); for (int i = 0; i < columnLines.size(); i++) { String line = columnLines.get(i); @@ -123,11 +126,11 @@ private Map parseExportTemplateV1(List private boolean isExpressionForDataModification(String expressionParam) { List operations = Arrays.stream( ExportTemplateColumnDef.DataModification.values()).map(v -> v.toString() + OPENING_BRACKET). - collect(Collectors.toList()); + toList(); String expression = expressionParam.trim(); - List possibleOperations = operations.stream().filter(op -> expression.startsWith(op)).collect(Collectors.toList()); - return possibleOperations.size() > 0; + List possibleOperations = operations.stream().filter(expression::startsWith).toList(); + return !possibleOperations.isEmpty(); } private ExportTemplateColumnDef createDataModifierDef(String header, String param2) { @@ -138,8 +141,7 @@ private ExportTemplateColumnDef createDataModifierDef(String header, String para String operationName = tokens[0].trim(); List operations = Arrays.stream( - ExportTemplateColumnDef.DataModification.values()).map(v -> v.toString()). - collect(Collectors.toList()); + ExportTemplateColumnDef.DataModification.values()).map(Enum::toString).toList(); if (!operations.contains(operationName)) { throw new ExportTemplateParseException("Undefined operation '" + operationName + "' encountered in export template"); @@ -192,7 +194,7 @@ private ProfileResourceNodeColumnDef createProfileNodeDef(String header, String throw new ExportTemplateParseException(String.format(messageFormat, param2)); } String originalColumnName = param2.substring(1); - if (!(Arrays.stream(WriterConstants.HEADERS).collect(Collectors.toList()).contains(originalColumnName))) { + if (!Arrays.asList(WriterConstants.HEADERS).contains(originalColumnName)) { throw new ExportTemplateParseException(String.format(messageFormat, originalColumnName)); } return new ProfileResourceNodeColumnDef(originalColumnName, header); diff --git a/droid-export/src/test/java/uk/gov/nationalarchives/droid/export/template/ExportTemplateBuilderTest.java b/droid-export/src/test/java/uk/gov/nationalarchives/droid/export/template/ExportTemplateBuilderTest.java index 6030cf247..b54b164e6 100644 --- a/droid-export/src/test/java/uk/gov/nationalarchives/droid/export/template/ExportTemplateBuilderTest.java +++ b/droid-export/src/test/java/uk/gov/nationalarchives/droid/export/template/ExportTemplateBuilderTest.java @@ -329,4 +329,43 @@ public void should_throw_an_exception_when_a_column_name_is_not_prefixed_with_do ExportTemplateParseException ex = assertThrows(ExportTemplateParseException.class, () -> builder.buildExportTemplate(tempFile.getAbsolutePath())); assertEquals("Invalid syntax in data modifier expression 'LCASE(PUID)', expecting '$' after '('", ex.getMessage()); } + + @Test + public void should_remove_comment_lines_from_the_template_when_multiple_comment_lines_at_the_beginning() throws IOException { + ExportTemplateBuilder builder = new ExportTemplateBuilder(); + File tempFile = temporaryFolder.newFile("comments-at-the-beginning"); + List data = Arrays.asList( + "// This is a comment about the file", + "// Which can explain the use of template", + " // and some where the line begins with blank space before the comment prefix", + "version 1.0", + "Identifier: $ID", + ""); + Files.write(tempFile.toPath(), data, StandardOpenOption.WRITE); + ExportTemplate template = builder.buildExportTemplate(tempFile.getAbsolutePath()); + assertNotNull(template); + assertEquals(1, template.getColumnOrderMap().size()); + assertEquals("Identifier",template.getColumnOrderMap().get(0).getHeaderLabel()); + } + + @Test + public void should_remove_comment_lines_and_blank_from_the_template_when_comment_lines_are_in_between_the_lines() throws IOException { + ExportTemplateBuilder builder = new ExportTemplateBuilder(); + File tempFile = temporaryFolder.newFile("comments-at-the-beginning"); + List data = Arrays.asList( + "// This is a comment about the file", + "// Which can explain the use of template and add information such as ", + "", + "// Created on: 18-MAR-2020 by Dr. O. I. Dean (aka Droidean)", + "version 1.0", + "// Changing the 'ID' column to be called 'Identifier'", + "Identifier: $ID", + "", + " // Add a string column in the template", + "Language: \"English\" ", + ""); + Files.write(tempFile.toPath(), data, StandardOpenOption.WRITE); + ExportTemplate template = builder.buildExportTemplate(tempFile.getAbsolutePath()); + assertNotNull(template); + } } \ No newline at end of file diff --git a/droid-help/src/main/resources/pages/export.html b/droid-help/src/main/resources/pages/export.html index 4fd5a996f..95185d216 100644 --- a/droid-help/src/main/resources/pages/export.html +++ b/droid-help/src/main/resources/pages/export.html @@ -454,12 +454,10 @@

Export Templates An export template is a simple text file, with a .template extension, which defines customisations of columns to be exported. Using a template, you can customise headers for the data columns, add new - columns - to the export, convert the data in a column to be uppercase / lowercase and change the order in which - columns - appear in the export. You can make an export template available to Droid by copying it into the - .droid6\export_templates folder. You can customise the columns listed in the CSV Columns section. + columns to the export, convert the data in a column to be uppercase / lowercase and change the order + in which columns appear in the export. You can make an export template available to Droid by copying + it into the .droid6\export_templates folder. You can customise the columns listed in + the CSV Columns section.

Features

The current syntax for the export template is referred to as version 1.0. This version of the export @@ -472,11 +470,16 @@

Features

Syntax

Syntactically, the export template is simple to define. The details for defining various customisations - are explained below.

+ are explained below.

  • - version line: The very first line of the Export Template defines the version number. For now - it simply needs to be version 1.0 + Comment line: The export template allows for comments to be added in the file. Any line that + begins with // is treated as a comment and it is ignored for column customisations. + Please note, Droid only supports single line comments as of the current version +
  • +
  • + Version line: The very first non-comment line of the Export Template defines the version + number. For now it simply needs to be version 1.0
  • Modifying a header: If you intend to use a different column header instead of one of the @@ -514,12 +517,20 @@

    Syntax

Putting it all together

Consider the following template

-
version 1.0
+                

+// The following customisations are an example of how an export template can be used
+// It defines a template version and customisations
+//
+// Created on: 21-SEP-2024
+
+version 1.0
 Identifier: $ID
 Name: $NAME
 LowerName: LCASE($NAME)
 Language: "Simplified English"
 Submitter: "Government Dept."
+
+// Following column is added to the export but not populated
 Background:
 FormatName: $FORMAT_NAME
 FormatVersion: $FORMAT_VERSION
@@ -527,6 +538,9 @@ 

Putting i

It indicates the following:

    +
  • +

    Initial few lines describe the template using comments

    +
  • The version of the template is 1.0

  • @@ -631,8 +645,9 @@

    Other options

    to the encoding used on your local machine instead, select 'Platform specific' instead.

    - When you are happy you want to export your profiles, press the profiles... button. This will bring up a standard file-save - dialog, in which you can specify where you want your CSV file to be saved. + When you are happy you want to export your profiles, press the Export profiles... + button. This will bring up a standard file-save dialog, in which you can specify where you want + your CSV file to be saved.

    From eac6df3ad67630de8a17b81cbb92baec6b8a5274 Mon Sep 17 00:00:00 2001 From: MancunianSam Date: Wed, 5 Nov 2025 15:09:46 +0000 Subject: [PATCH 3/3] Use the pull request trigger --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1e7e2164b..09583b432 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,8 @@ name: Release DROID on: - push: - branches: - - main + pull_request: + types: + - closed permissions: contents: write pull-requests: write