Skip to content

Commit

Permalink
[SERV-910] Add a catch for duplicate IDs in collection doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ksclarke committed Sep 12, 2023
1 parent 3079157 commit f8380f8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 62 deletions.
38 changes: 6 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,19 @@
<organization>UCLA Library</organization>
<organizationUrl>http://github.com/uclalibrary</organizationUrl>
<timezone>America/New_York</timezone>
<roles>
<role>Lead Developer</role>
</roles>
</developer>
<developer>
<id>hardyoyo</id>
<name>Hardy Pottinger</name>
<email>hardy.pottinger@gmail.com</email>
<timezone>America/Chicago</timezone>
</developer>
<developer>
<id>cachemeoutside</id>
<name>Anthony Vuong</name>
<email>avuong@cachemeoutside.io</email>
<organization>UCLA Library</organization>
<organizationUrl>http://github.com/uclalibrary</organizationUrl>
<timezone>America/Los_Angeles</timezone>
</developer>
<developer>
<id>markmatney</id>
<name>Mark A. Matney, Jr.</name>
<email>mmatney@library.ucla.edu</email>
<organization>UCLA Library</organization>
<organizationUrl>http://github.com/uclalibrary</organizationUrl>
<timezone>America/Los_Angeles</timezone>
</developer>
<developer>
<id>DRickard</id>
<name>David Rickard</name>
<email>drickard1967@library.ucla.edu</email>
<organization>UCLA Library</organization>
<organizationUrl>http://github.com/uclalibrary</organizationUrl>
<timezone>America/Los_Angeles</timezone>
</developer>
<!-- Also https://github.com/UCLALibrary/fester/graphs/contributors -->
</developers>

<properties>
<!-- Docker image dependencies -->
<ubuntu.tag>22.04</ubuntu.tag>
<jdk.version>17.0.4+8-1~22.04</jdk.version>
<jdk.version>17.0.8.1+1~us1-0ubuntu1~22.04</jdk.version>
<python3.version>3.10.6-1~22.04</python3.version>
<curl.version>7.81.0-1ubuntu1.6</curl.version>
<curl.version>7.81.0-1ubuntu1.13</curl.version>

<!-- Application dependencies -->
<vertx.version>3.9.14</vertx.version>
Expand Down
2 changes: 1 addition & 1 deletion src/main/docker/scripts/show_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ print_line() {
}

declare -a DEPENDENCIES=(
"openjdk-11-jre-headless"
"openjdk-17-jre-headless"
"python3"
"curl"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,31 +286,38 @@ private void updateCollection(final Message<JsonObject> aMessage) throws JsonPro

// First, add the old manifests to the map
final Stream<Collection.Manifest> stream = collection.getManifests().stream();
manifestMap.putAll(stream.collect(Collectors.toMap(Collection.Manifest::getID, manifest -> manifest)));

// Next, add the new manifests to the map, replacing any that already exist
worksMap.get(IDUtils.getResourceID(collection.getID())).stream().forEach(workArray -> {
final URI manifestURI = URI.create(workArray[0]);
manifestMap.put(manifestURI, new Collection.Manifest(manifestURI, new Label(workArray[1])));
});
try {
// Below can throw a RuntimeException if duplicate IDs are found
manifestMap.putAll(stream.collect(Collectors.toMap(Collection.Manifest::getID, manifest -> manifest)));

// Update the manifest list with the manifests in the map, ordered by their label
sortedManifestSet.addAll(manifestMap.values());
// Next, add the new manifests to the map, replacing any that already exist
worksMap.get(IDUtils.getResourceID(collection.getID())).stream().forEach(workArray -> {
final URI manifestURI = URI.create(workArray[0]);
manifestMap.put(manifestURI, new Collection.Manifest(manifestURI, new Label(workArray[1])));
});

collection.getManifests().clear();
collection.getManifests().addAll(sortedManifestSet);
// Update the manifest list with the manifests in the map, ordered by their label
sortedManifestSet.addAll(manifestMap.values());

message.put(Constants.DATA, collection.toJSON());
message.put(Constants.COLLECTION_NAME, collectionName);
options.addHeader(Constants.ACTION, Op.PUT_COLLECTION);
collection.getManifests().clear();
collection.getManifests().addAll(sortedManifestSet);

sendMessage(S3BucketVerticle.class.getName(), message, options, update -> {
if (update.succeeded()) {
aMessage.reply(collection.toJSON());
} else {
error(aMessage, update.cause(), MessageCodes.MFS_152, update.cause().getMessage());
}
});
message.put(Constants.DATA, collection.toJSON());
message.put(Constants.COLLECTION_NAME, collectionName);
options.addHeader(Constants.ACTION, Op.PUT_COLLECTION);

sendMessage(S3BucketVerticle.class.getName(), message, options, update -> {
if (update.succeeded()) {
aMessage.reply(collection.toJSON());
} else {
error(aMessage, update.cause(), MessageCodes.MFS_152, update.cause().getMessage());
}
});
} catch (final RuntimeException details) {
LOGGER.error(details, details.getMessage());
aMessage.fail(HTTP.INTERNAL_SERVER_ERROR, details.getMessage());
}
}

/**
Expand Down Expand Up @@ -355,11 +362,11 @@ private void updateWork(final Message<JsonObject> aMessage) throws JsonProcessin
});

CsvParser.getMetadata(workRow, csvHeaders.getLocalRightsStatementIndex())
.ifPresentOrElse(localRightsStatement -> {
manifest.setAttribution(new Attribution(localRightsStatement));
}, () -> {
manifest.clearAttribution();
});
.ifPresentOrElse(localRightsStatement -> {
manifest.setAttribution(new Attribution(localRightsStatement));
}, () -> {
manifest.clearAttribution();
});

CsvParser.getMetadata(workRow, csvHeaders.getRightsContactIndex()).ifPresentOrElse(rightsContact -> {
manifest.setMetadata(updateMetadata(manifest.getMetadata(), MetadataLabels.RIGHTS_CONTACT, rightsContact));
Expand Down Expand Up @@ -456,10 +463,10 @@ private Canvas[] createCanvases(final CsvHeaders aCsvHeaders, final List<String[
final String pageURI = StringUtils.format(SIMPLE_URI, aImageHost, encodedPageID);
final String contentURI = StringUtils.format(ANNOTATION_URI, Constants.URL_PLACEHOLDER, aWorkID, idPart);

String resourceURI = StringUtils.format(Constants.SAMPLE_URI_TEMPLATE, pageURI,
Constants.DEFAULT_SAMPLE_SIZE);
ImageResource imageResource = new ImageResource(resourceURI,
new ImageInfoService(APIComplianceLevel.TWO, pageURI));
String resourceURI =
StringUtils.format(Constants.SAMPLE_URI_TEMPLATE, pageURI, Constants.DEFAULT_SAMPLE_SIZE);
ImageResource imageResource =
new ImageResource(resourceURI, new ImageInfoService(APIComplianceLevel.TWO, pageURI));
ImageContent imageContent;
Canvas canvas;

Expand Down

0 comments on commit f8380f8

Please sign in to comment.