Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1011 format name difference between api and UI #1064

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading