Skip to content

Commit

Permalink
ufal/be-cannot-download-and-preview-files-after-migration (#454)
Browse files Browse the repository at this point in the history
* Find bitstream format using mimetype not ID.

* Updated tests according to fix.
  • Loading branch information
milanmajchrak authored Nov 15, 2023
1 parent dc628c9 commit 2f8a81d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,10 @@ public BitstreamRest importBitstreamForExistingFile(HttpServletRequest request)
log.info("SequenceId is null. Bitstream UUID: " + bitstream.getID());
}
//add bitstream format
String bitstreamFormatIdString = request.getParameter("bitstreamFormat");
Integer bitstreamFormatId = getIntegerFromString(bitstreamFormatIdString);
String bitstreamFormatMimeType = request.getParameter("bitstreamFormat");
BitstreamFormat bitstreamFormat = null;
if (!Objects.isNull(bitstreamFormatId)) {
bitstreamFormat = bitstreamFormatService.find(context, bitstreamFormatId);
if (StringUtils.isNotBlank(bitstreamFormatMimeType)) {
bitstreamFormat = bitstreamFormatService.findByMIMEType(context, bitstreamFormatMimeType);
}
bitstream.setFormat(context, bitstreamFormat);
String deletedString = request.getParameter("deleted");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void setup() throws Exception {
.withName("TESTINGBUNDLE")
.build();
token = getAuthToken(admin.getEmail(), password);
bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context).build();
bitstreamFormat = BitstreamFormatBuilder.createBitstreamFormat(context).withMimeType("application/pdf").build();
String input = "Hello, World!";
MockMultipartFile file = new MockMultipartFile("file", "hello.txt",
MediaType.TEXT_PLAIN_VALUE,
Expand Down Expand Up @@ -147,7 +147,7 @@ public void importBitstreamForExistingFileWithBundleTest() throws Exception {
.contentType(contentType)
.param("internal_id", internalId)
.param("storeNumber", Integer.toString(storeNumber))
.param("bitstreamFormat", Integer.toString(bitstreamFormat.getID()))
.param("bitstreamFormat", bitstreamFormat.getMIMEType())
.param("deleted", Boolean.toString(deleted))
.param("sequenceId", Integer.toString(sequence))
.param("primaryBundle_id", "")
Expand All @@ -156,8 +156,8 @@ public void importBitstreamForExistingFileWithBundleTest() throws Exception {
.andReturn().getResponse().getContentAsString(),
"$.id"));

checkCreatedBitstream(uuid, internalId, storeNumber, bitstreamFormat.getID(), sequence, deleted, sizeBytes,
checkSum);
checkCreatedBitstream(uuid, internalId, storeNumber, bitstreamFormat.getMIMEType(), sequence, deleted,
sizeBytes, checkSum);

//clean all
context.turnOffAuthorisationSystem();
Expand All @@ -182,7 +182,7 @@ public void importBitstreamForExistingFileWithoutBundleTest() throws Exception {
.contentType(contentType)
.param("internal_id", internalId)
.param("storeNumber", Integer.toString(storeNumber))
.param("bitstreamFormat", Integer.toString(bitstreamFormat.getID()))
.param("bitstreamFormat", bitstreamFormat.getMIMEType())
.param("deleted", Boolean.toString(deleted))
.param("sequenceId", Integer.toString(sequence))
.param("primaryBundle_id", "")
Expand All @@ -191,8 +191,8 @@ public void importBitstreamForExistingFileWithoutBundleTest() throws Exception {
.andReturn().getResponse().getContentAsString(),
"$.id"));

checkCreatedBitstream(uuid, internalId, storeNumber, bitstreamFormat.getID(), sequence, deleted, sizeBytes,
checkSum);
checkCreatedBitstream(uuid, internalId, storeNumber, bitstreamFormat.getMIMEType(), sequence, deleted,
sizeBytes, checkSum);

//clean all
context.turnOffAuthorisationSystem();
Expand All @@ -217,7 +217,7 @@ public void importBitstreamForExistingFileAsPrimaryBitstreamOfBundleTest() throw
.contentType(contentType)
.param("internal_id", internalId)
.param("storeNumber", Integer.toString(storeNumber))
.param("bitstreamFormat", Integer.toString(bitstreamFormat.getID()))
.param("bitstreamFormat", bitstreamFormat.getMIMEType())
.param("deleted", Boolean.toString(deleted))
.param("sequenceId", Integer.toString(sequence))
.param("primaryBundle_id", bundle.getID().toString())
Expand All @@ -226,8 +226,8 @@ public void importBitstreamForExistingFileAsPrimaryBitstreamOfBundleTest() throw
.andReturn().getResponse().getContentAsString(),
"$.id"));

checkCreatedBitstream(uuid, internalId, storeNumber, bitstreamFormat.getID(), sequence, deleted, sizeBytes,
checkSum);
checkCreatedBitstream(uuid, internalId, storeNumber, bitstreamFormat.getMIMEType(), sequence, deleted,
sizeBytes, checkSum);
bundle = bundleService.find(context, bundle.getID());
assertEquals(bundle.getPrimaryBitstream().getID(), bitstream.getID());

Expand Down Expand Up @@ -257,7 +257,7 @@ public void importBitstreamForExistingFileValidationErrorTest() throws Exception
.contentType(contentType)
.param("internal_id", internalId)
.param("storeNumber", Integer.toString(storeNumber))
.param("bitstreamFormat", Integer.toString(bitstreamFormat.getID()))
.param("bitstreamFormat", bitstreamFormat.getMIMEType())
.param("deleted", Boolean.toString(deleted))
.param("sequenceId", Integer.toString(sequence))
.param("primaryBundle_id", "")
Expand All @@ -271,12 +271,12 @@ public void importBitstreamForExistingFileValidationErrorTest() throws Exception
}

private void checkCreatedBitstream(UUID uuid, String internalId, int storeNumber,
Integer bitstreamFormat, int sequence, boolean deleted, long sizeBytes,
String bitstreamFormat, int sequence, boolean deleted, long sizeBytes,
String checkSum) throws SQLException {
bitstream = bitstreamService.find(context, uuid);
assertEquals(bitstream.getChecksum(), checkSum);
assertEquals(bitstream.getSizeBytes(), sizeBytes);
assertEquals(bitstream.getFormat(context).getID(), bitstreamFormat);
assertEquals(bitstream.getFormat(context).getMIMEType(), bitstreamFormat);
assertEquals(bitstream.getInternalId(), internalId);
assertEquals(bitstream.getStoreNumber(), storeNumber);
assertEquals(bitstream.getSequenceID(), sequence);
Expand Down

0 comments on commit 2f8a81d

Please sign in to comment.