Fixed bundle ranges.

This commit is contained in:
Michael Spalti
2021-11-03 17:22:06 -07:00
parent 6b5ae6f528
commit 7ba9894d8e
2 changed files with 19 additions and 13 deletions

View File

@@ -139,6 +139,10 @@ public class ManifestService extends AbstractResourceService {
* @param manifestId the generated manifestId * @param manifestId the generated manifestId
*/ */
private void addCanvasAndRange(Context context, Item item, String manifestId) { private void addCanvasAndRange(Context context, Item item, String manifestId) {
// Set the root range for this manifest.
rangeService.setInitialRange(manifestId);
// Process the bitstreams in each bundle. // Process the bitstreams in each bundle.
List<Bundle> bundles = utils.getIIIFBundles(item); List<Bundle> bundles = utils.getIIIFBundles(item);
for (Bundle bnd : bundles) { for (Bundle bnd : bundles) {
@@ -146,30 +150,28 @@ public class ManifestService extends AbstractResourceService {
if (bundles.size() > 1) { if (bundles.size() > 1) {
bundleToCPrefix = utils.getBundleIIIFToC(bnd); bundleToCPrefix = utils.getBundleIIIFToC(bnd);
} }
// Set the root range for this manifest.
rangeService.setInitialRange(manifestId);
for (Bitstream bitstream : utils.getIIIFBitstreams(context, bnd)) { for (Bitstream bitstream : utils.getIIIFBitstreams(context, bnd)) {
// Add the canvas to the manifest's sequence. // Add the canvas to the manifest's sequence.
CanvasGenerator canvasGenerator = sequenceService.addCanvas(context, item, bnd, bitstream); CanvasGenerator fullCanvas = sequenceService.addCanvas(context, item, bnd, bitstream);
// Now process ranges. // Now process the ranges.
List<String> tocs = utils.getIIIFToCs(bitstream, bundleToCPrefix); List<String> tocs = utils.getIIIFToCs(bitstream, bundleToCPrefix);
if (tocs.size() > 0) { if (tocs.size() > 0) {
// If toc fields exist for the bitstream, start a new range. // If toc fields exist for the bitstream, add a new range.
rangeService.setTocRange(tocs, canvasGenerator); rangeService.setTocRange(tocs, fullCanvas);
} else { } else {
// If ranges have been created, add canvas ids to the current range. // Add canvas ids to the currently active range.
if (rangeService.getTocRanges().size() > 0) { if (rangeService.getTocRanges().size() > 0) {
RangeGenerator currentRange = rangeService.getLastRange(); RangeGenerator currentRange = rangeService.getLastRange();
currentRange.addCanvas(canvasService.getRangeCanvasReference( String canvasIdentifier = fullCanvas.getIdentifier();
canvasGenerator.getIdentifier()) CanvasGenerator simpleCanvas = canvasService.getRangeCanvasReference(canvasIdentifier);
); currentRange.addCanvas(simpleCanvas);
} }
} }
} }
} }
// Finally, if ranges were found add them to manifest's structures element. // If ranges were created add them to manifest's structures element.
Map<String, RangeGenerator> tocRanges = rangeService.getTocRanges(); Map<String, RangeGenerator> tocRanges = rangeService.getTocRanges();
if (tocRanges != null && tocRanges.size() > 0) { if (tocRanges != null && tocRanges.size() > 0) {
RangeGenerator rootRange = rangeService.getRootRange(); RangeGenerator rootRange = rangeService.getRootRange();

View File

@@ -70,8 +70,12 @@ public class RangeService extends AbstractResourceService {
} }
/**
* Creates generator for the root table of contents range.
* @param manifestId manifest id
* @return root range generator
*/
private RangeGenerator getRootGenerator(String manifestId) { private RangeGenerator getRootGenerator(String manifestId) {
// The root range that will be used for this manifest.
RangeGenerator root = new RangeGenerator(this); RangeGenerator root = new RangeGenerator(this);
// This hint is required. // This hint is required.
root.addViewingHint("top"); root.addViewingHint("top");
@@ -131,7 +135,7 @@ public class RangeService extends AbstractResourceService {
// Finally, update the range that will be used in the next iteration. // Finally, update the range that will be used in the next iteration.
lastRange = currRange; lastRange = currRange;
} }
} }
/** /**
* Ranges expect the sub-range object to have only an identifier. * Ranges expect the sub-range object to have only an identifier.