Skip to content

Commit

Permalink
Issue 1011 format name difference between api and UI (#1064)
Browse files Browse the repository at this point in the history
* Updated to get name from binary signature file based on puid when identification method is container

* Updated to get name from binary signature file based on puid when identification method is container
  • Loading branch information
sparkhi authored Jan 29, 2024
1 parent 6f0a6b1 commit 3071273
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,11 +159,20 @@ public List<ApiResult> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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<ApiResult> results = api.submit(
Paths.get("../droid-container/src/test/resources/word97.doc"));
assertThat(results.get(0).getName(), is("Microsoft Word Document"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 3071273

Please sign in to comment.