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

Create manifest link according to cascading ObjectTypes #240

Merged
merged 2 commits into from
Jun 14, 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<properties>
<!-- Docker image dependencies -->
<ubuntu.tag>22.04</ubuntu.tag>
<jdk.version>17.0.10+7-1~22.04.1</jdk.version>
<jdk.version>17.0.11+9-1~22.04.1</jdk.version>
<python3.version>3.10.6-1~22.04</python3.version>
<curl.version>7.81.0-1ubuntu1.16</curl.version>

Expand Down
47 changes: 34 additions & 13 deletions src/main/java/edu/ucla/library/iiif/fester/utils/LinkUtils.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@

package edu.ucla.library.iiif.fester.utils;

import static edu.ucla.library.iiif.fester.Constants.EMPTY;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

import info.freelibrary.util.Logger;
import info.freelibrary.util.LoggerFactory;

import edu.ucla.library.iiif.fester.CSV;
import edu.ucla.library.iiif.fester.CsvHeaders;
import edu.ucla.library.iiif.fester.CsvParser;
import edu.ucla.library.iiif.fester.CsvParsingException;
import edu.ucla.library.iiif.fester.MessageCodes;
import edu.ucla.library.iiif.fester.ObjectType;

/**
* A utility class for link generation.
*/
public final class LinkUtils {

/** A logger for the {@code LinkUtils} object. */
private static final Logger LOGGER = LoggerFactory.getLogger(LinkUtils.class, MessageCodes.BUNDLE);

/**
* Creates a new {@code LinkUtils} instance.
*/
private LinkUtils() {
// This is intentionally left empty
}

/**
Expand All @@ -29,7 +45,6 @@ public static List<String[]> addManifests(final String aHostURL, final List<Stri
Objects.requireNonNull(aHostURL);
Objects.requireNonNull(aCsvList);

final int objectTypeHeaderIndex = getColumnIndex(CSV.OBJECT_TYPE, aCsvList);
final int manifestHeaderIndex = getColumnIndex(CSV.MANIFEST_URL, aCsvList);
final int itemArkHeaderIndex = getColumnIndex(CSV.ITEM_ARK, aCsvList);
final int columnLength = aCsvList.get(0).length;
Expand All @@ -55,18 +70,24 @@ public static List<String[]> addManifests(final String aHostURL, final List<Stri
if (index == 0) {
row[manifestHeaderIndex] = CSV.MANIFEST_URL;
} else {
final String objectType = row[objectTypeHeaderIndex];
final String itemARK = row[itemArkHeaderIndex];

// URLs vary depending on whether the row is a Collection or Work
if (ObjectType.COLLECTION.equals(objectType)) {
row[manifestHeaderIndex] = IDUtils.getResourceURI(aHostURL, IDUtils.getCollectionS3Key(itemARK))
.toString();
} else if (ObjectType.WORK.equals(objectType)) {
row[manifestHeaderIndex] = IDUtils.getResourceURI(aHostURL, IDUtils.getWorkS3Key(itemARK))
.toString();
} else {
row[manifestHeaderIndex] = ""; // Use an empty placeholder for things without links
try {
final ObjectType objectType = CsvParser.getObjectType(row, new CsvHeaders(aCsvList.get(0)));
final String itemARK = row[itemArkHeaderIndex];

// URLs vary depending on whether the row is a Collection or Work
if (ObjectType.COLLECTION.equals(objectType)) {
row[manifestHeaderIndex] =
IDUtils.getResourceURI(aHostURL, IDUtils.getCollectionS3Key(itemARK)).toString();
} else if (ObjectType.WORK.equals(objectType)) {
row[manifestHeaderIndex] =
IDUtils.getResourceURI(aHostURL, IDUtils.getWorkS3Key(itemARK)).toString();
} else {
row[manifestHeaderIndex] = EMPTY; // Use an empty placeholder for things without links
}
} catch (final CsvParsingException details) {
// Should not be possible; we checked this on CSV submission
LOGGER.error(details.getMessage());
row[manifestHeaderIndex] = EMPTY;
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/test/java/edu/ucla/library/iiif/fester/CsvParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public final void testParse() throws CsvParsingException, CsvException, IOExcept
myCsvParser.parse(getTestPath(GOOD_CSV));
}

/**
* Tests parsing the correct object type, with two possible options.
*
* @throws CsvParsingException If there is an error while parsing the CSV data
* @throws CsvException If there is a generic CSV error
* @throws IOException If there is trouble reading the CSV data
*/
@Test
public final void testObjTypeTest() throws CsvParsingException, CsvException, IOException {
final CsvMetadata metadata = myCsvParser.parse(getTestPath("iiif-object-type-test.csv")).getCsvMetadata();
assertEquals(0, metadata.getWorksMap().size()); // Should contain a collection record, not work
}

/**
* Tests handling spaces in non-header rows in a CSV file.
*
Expand Down Expand Up @@ -196,8 +209,7 @@ public final void testPageCsvNoItemSequence() throws CsvParsingException, CsvExc
* @throws IOException If there is trouble reading the CSV data
*/
@Test(expected = CsvParsingException.class)
public final void testCollectionWorkPageCsvNoItemSequence() throws CsvParsingException, CsvException,
IOException {
public final void testCollectionWorkPageCsvNoItemSequence() throws CsvParsingException, CsvException, IOException {
myCsvParser.parse(getTestPath("hathaway_combined_no_item_seq.csv"));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"Bib ID","Object Type","IIIF Object Type","Parent ARK","Item ARK","File Name","Title","Thumbnail","Item Sequence","AltTitle.other","AltTitle.uniform","Author","Place of origin","Date.creation","Date.normalized","Colophon","Description.note","Note","Summary","Representative image","Masthead","Language","References","Provenance","Table of Contents","Format.extent","Type.typeOfResource","Type.genre","Subject topic","Name.repository","AltIdentifier.local","Rights.copyrightStatus","Rights.servicesContact","Text direction","viewingHint","Opac url","Note.admin","vol.","IIIF Manifest URL"
"3275969","Work","Collection","ark:/21198/z1ht87xv","ark:/21198/z1d566ht","","Bon-Kan taieishū | 梵漢対映集","","","梵漢對映集 [variant title]","","","","Shōho 2 [1645] | 正保2","1645","","","","","","","jpn|~|chi","","","","","text","","","Richard C. Rudolph East Asian Library, UCLA","","public domain","http://www.library.ucla.edu/eastasian, (310) 825-4836","","","","","","https://iiif.library.ucla.edu/ark%3A%2F21198%2Fz1d566ht/manifest"
Loading