From 90d999806c2638b4ade731683d9a1874e910637d Mon Sep 17 00:00:00 2001 From: sparkhi Date: Fri, 26 Jan 2024 18:34:10 +0000 Subject: [PATCH 1/2] Updated to get name from binary signature file based on puid when identification method is container --- .../droid/internal/api/DroidAPI.java | 12 +++++++++++- .../droid/internal/api/DroidAPITest.java | 9 ++++++++- .../droid/core/interfaces/DroidCore.java | 9 +++++++-- .../droid/core/BinarySignatureIdentifier.java | 12 +++++++++++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/droid-api/src/main/java/uk/gov/nationalarchives/droid/internal/api/DroidAPI.java b/droid-api/src/main/java/uk/gov/nationalarchives/droid/internal/api/DroidAPI.java index 8e755645f..a832794b4 100644 --- a/droid-api/src/main/java/uk/gov/nationalarchives/droid/internal/api/DroidAPI.java +++ b/droid-api/src/main/java/uk/gov/nationalarchives/droid/internal/api/DroidAPI.java @@ -45,6 +45,7 @@ import uk.gov.nationalarchives.droid.core.BinarySignatureIdentifier; import uk.gov.nationalarchives.droid.core.SignatureParseException; import uk.gov.nationalarchives.droid.core.interfaces.DroidCore; +import uk.gov.nationalarchives.droid.core.interfaces.IdentificationMethod; import uk.gov.nationalarchives.droid.core.interfaces.IdentificationResultCollection; import uk.gov.nationalarchives.droid.core.interfaces.IdentificationResult; import uk.gov.nationalarchives.droid.core.interfaces.RequestIdentifier; @@ -158,11 +159,20 @@ public List submit(final Path file) throws IOException { boolean fileExtensionMismatch = resultCollection.getExtensionMismatch(); return resultCollection.getResults() - .stream().map(res -> new ApiResult(extension, res.getMethod(), res.getPuid(), res.getName(), fileExtensionMismatch)) + .stream().map(res -> createApiResult(res, extension, fileExtensionMismatch)) .collect(Collectors.toList()); } } + private ApiResult createApiResult(IdentificationResult result, String extension, boolean extensionMismatch) { + String name = result.getName(); + if (result.getMethod().equals(IdentificationMethod.CONTAINER) + && (droidCore.formatNameByPuid(result.getPuid()) != null)) { + name = droidCore.formatNameByPuid(result.getPuid()); + } + return new ApiResult(extension, result.getMethod(), result.getPuid(), name, extensionMismatch); + } + private IdentificationResultCollection identifyByExtension(final FileSystemIdentificationRequest identificationRequest) { IdentificationResultCollection extensionResult = droidCore.matchExtensions(identificationRequest, false); droidCore.removeLowerPriorityHits(extensionResult); diff --git a/droid-api/src/test/java/uk/gov/nationalarchives/droid/internal/api/DroidAPITest.java b/droid-api/src/test/java/uk/gov/nationalarchives/droid/internal/api/DroidAPITest.java index da28ba74a..0e4eb7b8e 100644 --- a/droid-api/src/test/java/uk/gov/nationalarchives/droid/internal/api/DroidAPITest.java +++ b/droid-api/src/test/java/uk/gov/nationalarchives/droid/internal/api/DroidAPITest.java @@ -88,7 +88,7 @@ public void should_identify_given_file_using_container_signature() throws IOExce ApiResult identificationResult = results.get(0); assertThat(identificationResult.getPuid(), is("fmt/291")); - assertThat(identificationResult.getName(), is("Open Document Text 1.2")); + assertThat(identificationResult.getName(), is("OpenDocument Text")); assertThat(identificationResult.getMethod(), is(IdentificationMethod.CONTAINER)); } @@ -155,4 +155,11 @@ public void should_produce_results_for_every_time_a_file_is_submitted_for_identi } assertThat(acc, is(MAX_ITER)); } + + @Test + public void should_identify_fmt_40_correctly_with_container_identification_method() throws IOException { + List results = api.submit( + Paths.get("../droid-container/src/test/resources/word97.doc")); + assertThat(results.get(0).getName(), is("Microsoft Word Document")); + } } diff --git a/droid-core-interfaces/src/main/java/uk/gov/nationalarchives/droid/core/interfaces/DroidCore.java b/droid-core-interfaces/src/main/java/uk/gov/nationalarchives/droid/core/interfaces/DroidCore.java index 12019bdcb..2af152824 100644 --- a/droid-core-interfaces/src/main/java/uk/gov/nationalarchives/droid/core/interfaces/DroidCore.java +++ b/droid-core-interfaces/src/main/java/uk/gov/nationalarchives/droid/core/interfaces/DroidCore.java @@ -124,6 +124,11 @@ public interface DroidCore { * @param fileExtension The file extension to check against. */ void checkForExtensionsMismatches(IdentificationResultCollection results, String fileExtension); - - + + /** + * Returns name of the format based on puid from the signatures. + * @param puid string representation of puid + * @return format name + */ + String formatNameByPuid(String puid); } diff --git a/droid-core/src/main/java/uk/gov/nationalarchives/droid/core/BinarySignatureIdentifier.java b/droid-core/src/main/java/uk/gov/nationalarchives/droid/core/BinarySignatureIdentifier.java index ddc075f50..544d33a71 100644 --- a/droid-core/src/main/java/uk/gov/nationalarchives/droid/core/BinarySignatureIdentifier.java +++ b/droid-core/src/main/java/uk/gov/nationalarchives/droid/core/BinarySignatureIdentifier.java @@ -254,5 +254,15 @@ public void checkForExtensionsMismatches( } } } - + + /** + * Return the name of format based on the puid. + * @param puid + * @return format name + */ + @Override + public String formatNameByPuid(String puid) { + FileFormat format = sigFile.getFileFormat(puid); + return format != null? format.getName() : null; + } } From 091d1491737be349ad9bb97a61f629afcda5a8a7 Mon Sep 17 00:00:00 2001 From: sparkhi Date: Mon, 29 Jan 2024 10:41:49 +0000 Subject: [PATCH 2/2] Updated to get name from binary signature file based on puid when identification method is container --- .../nationalarchives/droid/core/BinarySignatureIdentifier.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/droid-core/src/main/java/uk/gov/nationalarchives/droid/core/BinarySignatureIdentifier.java b/droid-core/src/main/java/uk/gov/nationalarchives/droid/core/BinarySignatureIdentifier.java index 544d33a71..c821ee6db 100644 --- a/droid-core/src/main/java/uk/gov/nationalarchives/droid/core/BinarySignatureIdentifier.java +++ b/droid-core/src/main/java/uk/gov/nationalarchives/droid/core/BinarySignatureIdentifier.java @@ -257,7 +257,7 @@ public void checkForExtensionsMismatches( /** * Return the name of format based on the puid. - * @param puid + * @param puid puid whose corresponding format name is needed * @return format name */ @Override