Skip to content

Commit

Permalink
[SERV-888] Updates for IIIF Object Type column (#233)
Browse files Browse the repository at this point in the history
* [SERV-888] updates for IIIF Object Type column

* codacy fixes
  • Loading branch information
DRickard committed Nov 16, 2023
1 parent 5c06d48 commit 0c60ab8
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 30 deletions.
5 changes: 5 additions & 0 deletions src/main/java/edu/ucla/library/iiif/fester/CSV.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public final class CSV {
*/
public static final String OBJECT_TYPE = "Object Type";

/**
* The IIIF object type for the row
*/
public static final String IIIF_OBJECT_TYPE = "IIIF Object Type";

/**
* The row's file name. Not all rows are intended to have files.
*/
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/edu/ucla/library/iiif/fester/CsvHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class CsvHeaders {
*/
private int myObjectTypeIndex = -1;

/**
* The index position for the IIIF object type column.
*/
private int myIiifObjectTypeIndex = -1;

/**
* The index position for the file name column.
*/
Expand Down Expand Up @@ -120,6 +125,9 @@ public CsvHeaders(final String[] aRow) {
case CSV.OBJECT_TYPE:
setObjectTypeIndex(index);
break;
case CSV.IIIF_OBJECT_TYPE:
setIiifObjectTypeIndex(index);
break;
case CSV.FILE_NAME:
setFileNameIndex(index);
break;
Expand Down Expand Up @@ -327,6 +335,37 @@ public boolean hasObjectTypeIndex() {
return myObjectTypeIndex != -1;
}

/**
* Gets the Object Type index position.
*
* @return The index position of the Object Type
*/
@JsonGetter
public int getIiifObjectTypeIndex() {
return myIiifObjectTypeIndex;
}

/**
* Sets the Object Type index position.
*
* @param anIiifObjectTypeIndex The index position of the IIIF Object Type
* @return This CSV headers
*/
@JsonSetter
public CsvHeaders setIiifObjectTypeIndex(final int anIiifObjectTypeIndex) {
myIiifObjectTypeIndex = anIiifObjectTypeIndex;
return this;
}

/**
* Checks whether there is an Object Type index position
*
* @return True if there is an IIIF Object Type index position; else, false
*/
public boolean hasIiifObjectTypeIndex() {
return myIiifObjectTypeIndex != -1;
}

/**
* Gets the File Name index position.
*
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/edu/ucla/library/iiif/fester/CsvParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,28 @@ private String[] checkApiCompatibility(final String[] aRow, final Path aPath, fi
*/
public static ObjectType getObjectType(final String[] aRow, final CsvHeaders aCsvHeaders)
throws CsvParsingException {
if (aCsvHeaders.hasObjectTypeIndex()) {
if (aCsvHeaders.hasIiifObjectTypeIndex()) {
final int iiifObjectTypeIndex = aCsvHeaders.getIiifObjectTypeIndex();

if (aRow.length > iiifObjectTypeIndex) {
final String objectType = aRow[iiifObjectTypeIndex];

if (ObjectType.COLLECTION.equals(objectType)) {
return ObjectType.COLLECTION;
} else if (ObjectType.WORK.equals(objectType)) {
return ObjectType.WORK;
} else if (ObjectType.PAGE.equals(objectType)) {
return ObjectType.PAGE;
} else if (ObjectType.MISSING.equals(StringUtils.trimTo(objectType, Constants.EMPTY))) {
return ObjectType.MISSING;
} else {
// Disallow unknown types
throw new CsvParsingException(MessageCodes.MFS_094, objectType);
}
} else {
throw new CsvParsingException(MessageCodes.MFS_098, iiifObjectTypeIndex, Arrays.toString(aRow));
}
} else if (aCsvHeaders.hasObjectTypeIndex()) {
final int objectTypeIndex = aCsvHeaders.getObjectTypeIndex();

if (aRow.length > objectTypeIndex) {
Expand Down
1 change: 0 additions & 1 deletion src/main/tools/checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
<suppressions>
<suppress files="src[\\/]main[\\/]generated[\\/]" checks="."/>
<suppress files="target[\\/]" checks="."/>
<suppress files=".mvn[\\/]" checks="."/>
</suppressions>
2 changes: 2 additions & 0 deletions src/test/java/edu/ucla/library/iiif/fester/CsvParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public final void testGetCsvHeaders() throws CsvParsingException, CsvException,
assertEquals(7, csvHeaders.getItemSequenceIndex());
assertEquals(-1, csvHeaders.getLocalRightsStatementIndex());
assertEquals(5, csvHeaders.getObjectTypeIndex());
assertEquals(39, csvHeaders.getIiifObjectTypeIndex());
assertEquals(2, csvHeaders.getParentArkIndex());
assertEquals(20, csvHeaders.getRepositoryNameIndex());
assertEquals(17, csvHeaders.getRightsContactIndex());
Expand All @@ -111,6 +112,7 @@ public final void testGetCsvHeadersWhitespace() throws CsvParsingException, IOEx
assertEquals(1, csvHeaders.getItemArkIndex());
assertEquals(2, csvHeaders.getParentArkIndex());
assertEquals(3, csvHeaders.getObjectTypeIndex());
assertEquals(24, csvHeaders.getIiifObjectTypeIndex());
assertEquals(4, csvHeaders.getFileNameIndex());
assertEquals(5, csvHeaders.getItemSequenceIndex());
assertEquals(12, csvHeaders.getTitleIndex());
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/edu/ucla/library/iiif/fester/fit/PostCsvFIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class PostCsvFIT {

private static final File ALL_IN_ONE_CSV = new File(DIR, "csv/hathaway.csv");

private static final File IIIF_TYPES_CSV = new File(DIR, "csv/hathaway_iiif_type.csv");

private static final File WORKS_CSV_COLLECTION = new File(DIR, "csv/hathaway/batch1/works.csv");

private static final File WORKS_CSV_NO_COLLECTION = new File(DIR, "csv/hathaway/batch2/works.csv");
Expand Down Expand Up @@ -872,6 +874,52 @@ public final void testImageCanvasThumbnailsV3(final TestContext aContext) {
});
}

/**
* Tests submitting a CSV with IIIF Object Type header with IIIF Presentation API 3 specified.
*
* @param aContext A test context
*/
@Test
public final void testIiifObjectTypeV3(final TestContext aContext) {
final Async asyncTask = aContext.async();

postCSV(IIIF_TYPES_CSV, Constants.IIIF_API_V3, post -> {
if (post.succeeded()) {
final HttpResponse<Buffer> response = post.result();
final int statusCode = response.statusCode();
final String statusMessage = response.statusMessage();

if (statusCode == HTTP.CREATED) {
// Just check the second manifest, since another test already uses the first manifest
final Optional<JsonObject> optJsonObject = checkS3(HATHAWAY_SECOND_WORK_ARK, false);

if (optJsonObject.isPresent()) {
try {
final JsonObject expected = readJsonFile(HATHAWAY_SECOND_MANIFEST);
final JsonObject found = optJsonObject.get();

aContext.assertTrue(TestUtils.manifestsAreEffectivelyEqual(expected, found));
} catch (final IOException details) {
LOGGER.error(details, details.getMessage());
aContext.fail(details);
}
} else {
aContext.fail(LOGGER.getMessage(MessageCodes.MFS_154, ALL_IN_ONE_CSV));
}
TestUtils.complete(asyncTask);
} else {
aContext.fail(LOGGER.getMessage(MessageCodes.MFS_039, statusCode, statusMessage));
}
} else {
final Throwable exception = post.cause();

LOGGER.error(exception, exception.getMessage());
aContext.fail(exception);
}
});
}


/**
* Tests submitting a CSV using an outdated version of Festerize.
*
Expand Down

0 comments on commit 0c60ab8

Please sign in to comment.