mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Updated IIIF Controller IT to text bitstream and bundle exclusions
(cherry picked from commit e92b4b7bfd
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
6edf793023
commit
6b99584e96
@@ -17,7 +17,11 @@ import org.dspace.content.Bitstream;
|
||||
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;
|
||||
@@ -54,6 +58,13 @@ public class BitstreamBuilder extends AbstractDSpaceObjectBuilder<Bitstream> {
|
||||
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;
|
||||
@@ -87,6 +98,41 @@ public class BitstreamBuilder extends AbstractDSpaceObjectBuilder<Bitstream> {
|
||||
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;
|
||||
@@ -136,6 +182,11 @@ public class BitstreamBuilder extends AbstractDSpaceObjectBuilder<Bitstream> {
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
@@ -221,6 +221,93 @@ public class IIIFControllerIT extends AbstractControllerIntegrationTest {
|
||||
.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();
|
||||
|
Reference in New Issue
Block a user