Skip to content

Commit

Permalink
Updated IIIF Controller IT to text bitstream and bundle exclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
mspalti committed Nov 9, 2023
1 parent 92844f0 commit e92b4b7
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
51 changes: 51 additions & 0 deletions dspace-api/src/test/java/org/dspace/builder/BitstreamBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
import org.dspace.content.BitstreamFormat;
import org.dspace.content.Bundle;
import org.dspace.content.Item;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataValue;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.DSpaceObjectService;
import org.dspace.content.service.MetadataValueService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.eperson.Group;
Expand Down Expand Up @@ -55,6 +59,13 @@ public static BitstreamBuilder createBitstream(Context context, Item item, Input
return builder.createInRequestedBundle(context, item, is, bundleName);
}

public static BitstreamBuilder createBitstream(Context context, Item item, InputStream is,
String bundleName, boolean iiifEnabled)
throws SQLException, AuthorizeException, IOException {
BitstreamBuilder builder = new BitstreamBuilder(context);
return builder.createInRequestedBundleWithIiifDisabled(context, item, is, bundleName, iiifEnabled);
}

private BitstreamBuilder create(Context context, Item item, InputStream is)
throws SQLException, AuthorizeException, IOException {
this.context = context;
Expand Down Expand Up @@ -88,6 +99,41 @@ private BitstreamBuilder createInRequestedBundle(Context context, Item item, Inp
return this;
}

private BitstreamBuilder createInRequestedBundleWithIiifDisabled(Context context, Item item, InputStream is,
String bundleName, boolean iiifEnabled)
throws SQLException, AuthorizeException, IOException {
this.context = context;
this.item = item;

Bundle bundle = getBundleByNameAndIiiEnabled(item, bundleName, iiifEnabled);

bitstream = bitstreamService.create(context, bundle, is);

return this;
}

private Bundle getBundleByNameAndIiiEnabled(Item item, String bundleName, boolean iiifEnabled)
throws SQLException, AuthorizeException {
List<Bundle> bundles = itemService.getBundles(item, bundleName);
Bundle targetBundle = null;

if (bundles.size() < 1) {
// not found, create a new one
targetBundle = bundleService.create(context, item, bundleName);
MetadataValueService metadataValueService = ContentServiceFactory.getInstance().getMetadataValueService();
MetadataField iiifEnabledField = metadataFieldService.
findByString(context, "dspace.iiif.enabled", '.');
MetadataValue metadataValue = metadataValueService.create(context, targetBundle, iiifEnabledField);
metadataValue.setValue(String.valueOf(iiifEnabled));

} else {
// put bitstreams into first bundle
targetBundle = bundles.iterator().next();
}
return targetBundle;
}


private Bundle getBundleByName(Item item, String bundleName) throws SQLException, AuthorizeException {
List<Bundle> bundles = itemService.getBundles(item, bundleName);
Bundle targetBundle = null;
Expand Down Expand Up @@ -137,6 +183,11 @@ public BitstreamBuilder withProvenance(String provenance) throws SQLException {
}


public BitstreamBuilder withIIIFDisabled() throws SQLException {
bitstreamService.addMetadata(context, bitstream, "dspace", "iiif", "enabled", null, "false");
return this;
}

public BitstreamBuilder withIIIFLabel(String label) throws SQLException {
bitstreamService.addMetadata(context, bitstream, "iiif", "label", null, null, label);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,93 @@ public void findOneIIIFSearchableWithMixedConfigIT() throws Exception {
.andExpect(jsonPath("$.service").exists());
}

@Test
public void findOneWithExcludedBitstreamIT() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1")
.build();
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Public item 1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.enableIIIF()
.build();

String bitstreamContent = "ThisIsSomeText";
try (InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
BitstreamBuilder
.createBitstream(context, publicItem1, is)
.withName("Bitstream1.jpg")
.withMimeType("image/jpeg")
.withIIIFLabel("Custom Label")
.build();
}
try (InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
BitstreamBuilder
.createBitstream(context, publicItem1, is)
.withName("Bitstream2.jpg")
.withMimeType("image/jpeg")
.withIIIFDisabled()
.build();
}
context.restoreAuthSystemState();
// Expect canvas label, width and height to match bitstream description.
getClient().perform(get("/iiif/" + publicItem1.getID() + "/manifest"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.sequences[0].canvases", Matchers.hasSize(1)))
.andExpect(jsonPath("$.@context", is("http://iiif.io/api/presentation/2/context.json")))
.andExpect(jsonPath("$.sequences[0].canvases[0].@id",
Matchers.containsString("/iiif/" + publicItem1.getID() + "/canvas/c0")))
.andExpect(jsonPath("$.sequences[0].canvases[0].label", is("Custom Label")));
}

@Test
public void findOneWithExcludedBitstreamBundleIT() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1")
.build();
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Public item 1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.enableIIIF()
.build();

String bitstreamContent = "ThisIsSomeText";
try (InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
BitstreamBuilder
.createBitstream(context, publicItem1, is)
.withName("Bitstream1.jpg")
.withMimeType("image/jpeg")
.withIIIFLabel("Custom Label")
.build();
}
// Add bitstream
try (InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
BitstreamBuilder
.createBitstream(context, publicItem1, is, "ExcludedBundle", false)
.withName("Bitstream2.jpg")
.withMimeType("image/jpeg")
.build();
}
context.restoreAuthSystemState();
// Expect canvas label, width and height to match bitstream description.
getClient().perform(get("/iiif/" + publicItem1.getID() + "/manifest"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.sequences[0].canvases", Matchers.hasSize(1)))
.andExpect(jsonPath("$.@context", is("http://iiif.io/api/presentation/2/context.json")))
.andExpect(jsonPath("$.sequences[0].canvases[0].@id",
Matchers.containsString("/iiif/" + publicItem1.getID() + "/canvas/c0")))
.andExpect(jsonPath("$.sequences[0].canvases[0].label", is("Custom Label")));
}


@Test
public void findOneIIIFSearchableWithCustomBundleAndConfigIT() throws Exception {
context.turnOffAuthorisationSystem();
Expand Down

0 comments on commit e92b4b7

Please sign in to comment.