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..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 @@ -254,5 +254,15 @@ public void checkForExtensionsMismatches( } } } - + + /** + * Return the name of format based on the puid. + * @param puid puid whose corresponding format name is needed + * @return format name + */ + @Override + public String formatNameByPuid(String puid) { + FileFormat format = sigFile.getFileFormat(puid); + return format != null? format.getName() : null; + } }