Skip to content

Commit

Permalink
Merge pull request #1 from TAMULib/dspace-metadata
Browse files Browse the repository at this point in the history
processing title and description from rdf
  • Loading branch information
wwelling committed May 30, 2018
2 parents aa433ca + 12b1b76 commit 9fc5bd3
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 141 deletions.
1 change: 1 addition & 0 deletions src/main/java/edu/tamu/iiif/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Constants {

public final static String DUBLIN_CORE_TERMS_TITLE = DUBLIN_CORE_TERMS_PREFIX + "title";
public final static String DUBLIN_CORE_TERMS_DESCRIPTION = DUBLIN_CORE_TERMS_PREFIX + "description";
public final static String DUBLIN_CORE_TERMS_ABSTRACT = DUBLIN_CORE_TERMS_PREFIX + "abstract";
public final static String DUBLIN_CORE_TERMS_HAS_PART = DUBLIN_CORE_TERMS_PREFIX + "hasPart";
public final static String DUBLIN_CORE_TERMS_IS_PART_OF = DUBLIN_CORE_TERMS_PREFIX + "isPartOf";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ private List<Metadata> getMetadata(RdfResource rdfResource, String prefix) {
match = resourceUrl.equals(statementUrl);
}
if (match && predicate.getNameSpace().equals(prefix)) {

Optional<Metadata> metadatum = Optional.empty();
try {
metadatum = Optional.of(generateMetadatum(statement));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static edu.tamu.iiif.constants.Constants.DSPACE_IS_PART_OF_COMMUNITY_PREDICATE;
import static edu.tamu.iiif.constants.Constants.DSPACE_IS_PART_OF_REPOSITORY_PREDICATE;
import static edu.tamu.iiif.constants.Constants.DSPACE_IS_SUB_COMMUNITY_OF_PREDICATE;
import static edu.tamu.iiif.constants.Constants.DUBLIN_CORE_TERMS_ABSTRACT;
import static edu.tamu.iiif.constants.Constants.DUBLIN_CORE_TERMS_DESCRIPTION;
import static edu.tamu.iiif.constants.Constants.DUBLIN_CORE_TERMS_TITLE;
import static edu.tamu.iiif.constants.Constants.PRESENTATION_IDENTIFIER;
Expand Down Expand Up @@ -83,7 +84,11 @@ protected Canvas generateCanvas(RdfResource rdfResource) throws IOException, URI

canvas.setImages(rdfCanvas.getImages());

canvas.setMetadata(new ArrayList<Metadata>());
List<Metadata> metadata = getDublinCoreMetadata(rdfResource);

metadata.addAll(getDublinCoreTermsMetadata(rdfResource));

canvas.setMetadata(metadata);

return canvas;
}
Expand All @@ -98,7 +103,10 @@ protected PropertyValueSimpleImpl getTitle(RdfResource rdfResource) {
}

protected PropertyValueSimpleImpl getDescription(RdfResource rdfResource) {
Optional<String> description = getObject(rdfResource, DUBLIN_CORE_TERMS_DESCRIPTION);
Optional<String> description = getObject(rdfResource, DUBLIN_CORE_TERMS_ABSTRACT);
if (!description.isPresent()) {
description = getObject(rdfResource, DUBLIN_CORE_TERMS_DESCRIPTION);
}
if (!description.isPresent()) {
description = Optional.of("N/A");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ private Collection generateCollection(String handle) throws URISyntaxException,

PropertyValueSimpleImpl label = getTitle(rdfResource);

List<Metadata> metadata = new ArrayList<Metadata>();
List<Metadata> metadata = getDublinCoreMetadata(rdfResource);

metadata.addAll(getDublinCoreTermsMetadata(rdfResource));

Collection collection = new CollectionImpl(id, label, metadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import de.digitalcollections.iiif.presentation.model.api.v2.Canvas;
import de.digitalcollections.iiif.presentation.model.api.v2.Image;
import de.digitalcollections.iiif.presentation.model.api.v2.Manifest;
import de.digitalcollections.iiif.presentation.model.api.v2.Metadata;
import de.digitalcollections.iiif.presentation.model.api.v2.Sequence;
import de.digitalcollections.iiif.presentation.model.api.v2.Thumbnail;
import de.digitalcollections.iiif.presentation.model.impl.v2.ManifestImpl;
Expand All @@ -38,13 +39,19 @@ public String generateManifest(String handle) throws IOException, URISyntaxExcep

Manifest manifest = new ManifestImpl(id, label);

manifest.setDescription(getDescription(rdfResource));

List<Sequence> sequences = getSequences(rdfResource);

manifest.setSequences(sequences);

manifest.setLogo(getLogo(rdfResource));

manifest.setMetadata(getDublinCoreTermsMetadata(rdfResource));
List<Metadata> metadata = getDublinCoreMetadata(rdfResource);

metadata.addAll(getDublinCoreTermsMetadata(rdfResource));

manifest.setMetadata(metadata);

Optional<Thumbnail> thumbnail = getThumbnail(sequences);
if (thumbnail.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public String generateManifest(String handle) throws IOException, URISyntaxExcep

Sequence sequence = generateSequence(rdfResource);

sequence.setDescription(getDescription(rdfResource));

return mapper.writeValueAsString(sequence);
}

Expand Down
15 changes: 10 additions & 5 deletions src/main/java/edu/tamu/iiif/utility/RdfModelUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static Model createRdfModel(String rdf) {
model.read(stream, null, "TTL");
return model;
}

public static Optional<String> getIdByPredicate(Model model, String predicate) {
Optional<String> id = Optional.empty();
NodeIterator firstNodeItr = model.listObjectsOfProperty(model.getProperty(predicate));
Expand All @@ -30,15 +30,20 @@ public static Optional<String> getIdByPredicate(Model model, String predicate) {
}
return id;
}

public static Optional<String> getObject(RdfResource rdfResource, String uri) {
Optional<String> metadatum = Optional.empty();
Statement statement = rdfResource.getStatementOfPropertyWithId(uri);
if (statement != null) {
RDFNode object = statement.getObject();
Optional<Statement> statement = Optional.ofNullable(rdfResource.getStatementOfPropertyWithId(uri));
if (statement.isPresent()) {
RDFNode object = statement.get().getObject();
if (!object.toString().isEmpty()) {
metadatum = Optional.of(object.toString());
}
} else {
NodeIterator nodeIteerator = rdfResource.getAllNodesOfPropertyWithId(uri);
if (nodeIteerator.hasNext()) {
metadatum = Optional.of(nodeIteerator.next().toString());
}
}
return metadatum;
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ iiif.image.server.url: http://localhost:8182/iiif/2

iiif.logo.url: https://brandguide.tamu.edu/assets/downloads/logos/TAM-Logo.png

# request connection timeout, 5 minutes in milliseconds
iiif.service.connection.timeout: 300000
# request connection timeout in milliseconds
iiif.service.connection.timeout: 30000

# request connection timeout, 5 minutes in milliseconds
iiif.service.connection.request.timeout: 300000
# request connection timeout in milliseconds
iiif.service.connection.request.timeout: 15000

# cache request socket timeout, 5 minutes in milliseconds
iiif.service.socket.timeout: 300000
# cache request socket timeout in milliseconds
iiif.service.socket.timeout: 60000

# number of retries per request
iiif.service.request.retries: 3
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class FedoraPresentationManifestServiceTest extends AbstractFedoraManifes
@Value("classpath:mock/fedora/rdf/pcdm_item_container.rdf")
private Resource rdf;

@Value("classpath:mock/fedora/rdf/pcdm_item_container_without_order.rdf")
private Resource rdfWithoutOrder;

@Value("classpath:mock/fedora/rdf/pcdm_item_proxy_0.rdf")
private Resource proxy0Rdf;

Expand Down Expand Up @@ -66,4 +69,17 @@ public void testGetManifest() throws IOException, URISyntaxException {
Assert.assertEquals(objectMapper.readValue(presentation.getFile(), JsonNode.class), objectMapper.readValue(manifest, JsonNode.class));
}

@Test
public void testGetManifestWithoutOrder() throws IOException, URISyntaxException {
when(httpService.get(eq(PCDM_RDF_URL), any(String.class))).thenReturn(FileUtils.readFileToString(rdfWithoutOrder.getFile(), "UTF-8"));

when(httpService.get(eq(IMAGE_SERVICE_URL + "/ZmVkb3JhOmNhcnNfcGNkbV9vYmplY3RzL2NoZXZ5L3BhZ2VzL3BhZ2VfMC9maWxlcy9QVEFSXzgwMHg0MDAucG5n/info.json"))).thenReturn(FileUtils.readFileToString(image0.getFile(), "UTF-8"));

when(httpService.get(eq(IMAGE_SERVICE_URL + "/ZmVkb3JhOmNhcnNfcGNkbV9vYmplY3RzL2NoZXZ5L3BhZ2VzL3BhZ2VfMS9maWxlcy9jYXIyLmpwZw==/info.json"))).thenReturn(FileUtils.readFileToString(image1.getFile(), "UTF-8"));

String manifest = fedoraPresentationManifestService.getManifest("cars_pcdm_objects/chevy", false);

Assert.assertEquals(objectMapper.readValue(presentation.getFile(), JsonNode.class), objectMapper.readValue(manifest, JsonNode.class));
}

}
100 changes: 52 additions & 48 deletions src/test/resources/mock/dspace/json/presentation.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,58 @@
{
"@context" : "http://iiif.io/api/presentation/2/context.json",
"@id" : "http://localhost:9003/dspace/presentation?context=123456789/158308",
"@type" : "sc:Manifest",
"label" : "dspace:rdf/handle/123456789/158308",
"logo" : "https://brandguide.tamu.edu/assets/downloads/logos/TAM-Logo.png",
"metadata" : [ {
"label" : "title",
"value" : "Corvette"
"@context": "http://iiif.io/api/presentation/2/context.json",
"@id": "http://localhost:9003/dspace/presentation?context=123456789/158308",
"@type": "sc:Manifest",
"description": "N/A",
"label": "Corvette",
"logo": "https://brandguide.tamu.edu/assets/downloads/logos/TAM-Logo.png",
"metadata": [{
"label": "date",
"value": "2018-04-24T13:29:59Z^^http://www.w3.org/2001/XMLSchema#dateTime"
}, {
"label" : "available",
"value" : "2018-04-24T13:29:59Z^^http://www.w3.org/2001/XMLSchema#dateTime"
} ],
"sequences" : [ {
"@id" : "http://localhost:9003/dspace/sequence?context=123456789/158308",
"@type" : "sc:Sequence",
"canvases" : [ {
"@id" : "http://localhost:9003/dspace/canvas?context=123456789/158308/1/sports-car-146873_960_720.png",
"@type" : "sc:Canvas",
"height" : 480,
"images" : [ {
"@id" : "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=/info.json",
"@type" : "oa:Annotation",
"motivation" : "sc:painting",
"on" : "http://localhost:9003/dspace/canvas?context=123456789/158308/1/sports-car-146873_960_720.png",
"resource" : {
"@id" : "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=/full/full/0/default.jpg",
"@type" : "dctypes:Image",
"height" : 480,
"service" : {
"label" : "DSpace IIIF Image Resource Service",
"profile" : "http://iiif.io/api/image/2/level0.json",
"@context" : "http://iiif.io/api/image/2/context.json",
"@id" : "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc="
"label": "title",
"value": "Corvette"
}, {
"label": "available",
"value": "2018-04-24T13:29:59Z^^http://www.w3.org/2001/XMLSchema#dateTime"
}],
"sequences": [{
"@id": "http://localhost:9003/dspace/sequence?context=123456789/158308",
"@type": "sc:Sequence",
"canvases": [{
"@id": "http://localhost:9003/dspace/canvas?context=123456789/158308/1/sports-car-146873_960_720.png",
"@type": "sc:Canvas",
"height": 480,
"images": [{
"@id": "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=/info.json",
"@type": "oa:Annotation",
"motivation": "sc:painting",
"on": "http://localhost:9003/dspace/canvas?context=123456789/158308/1/sports-car-146873_960_720.png",
"resource": {
"@id": "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=/full/full/0/default.jpg",
"@type": "dctypes:Image",
"height": 480,
"service": {
"label": "DSpace IIIF Image Resource Service",
"profile": "http://iiif.io/api/image/2/level0.json",
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc="
},
"width" : 960
"width": 960
}
} ],
"label" : "123456789/158308/1/sports-car-146873_960_720.png",
"metadata" : [ ],
"width" : 960
} ],
"label" : "123456789/158308"
} ],
"thumbnail" : {
"@id" : "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=/full/!200,200/0/default.jpg",
"services" : [ {
"@context" : "http://iiif.io/api/image/2/context.json",
"@id" : "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=",
"label" : "DSpace IIIF Image Resource Service",
"profile" : "http://iiif.io/api/image/2/level0.json"
} ]
}],
"label": "123456789/158308/1/sports-car-146873_960_720.png",
"metadata": [],
"width": 960
}],
"label": "123456789/158308"
}],
"thumbnail": {
"@id": "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=/full/!200,200/0/default.jpg",
"services": [{
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=",
"label": "DSpace IIIF Image Resource Service",
"profile": "http://iiif.io/api/image/2/level0.json"
}]
}
}
55 changes: 28 additions & 27 deletions src/test/resources/mock/dspace/json/sequence.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
"@id" : "http://localhost:9003/dspace/sequence?context=123456789/158308",
"@type" : "sc:Sequence",
"canvases" : [ {
"@id" : "http://localhost:9003/dspace/canvas?context=123456789/158308/1/sports-car-146873_960_720.png",
"@type" : "sc:Canvas",
"height" : 480,
"images" : [ {
"@id" : "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=/info.json",
"@type" : "oa:Annotation",
"motivation" : "sc:painting",
"on" : "http://localhost:9003/dspace/canvas?context=123456789/158308/1/sports-car-146873_960_720.png",
"resource" : {
"@id" : "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=/full/full/0/default.jpg",
"@type" : "dctypes:Image",
"height" : 480,
"service" : {
"label" : "DSpace IIIF Image Resource Service",
"profile" : "http://iiif.io/api/image/2/level0.json",
"@context" : "http://iiif.io/api/image/2/context.json",
"@id" : "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc="
"@id": "http://localhost:9003/dspace/sequence?context=123456789/158308",
"@type": "sc:Sequence",
"canvases": [{
"@id": "http://localhost:9003/dspace/canvas?context=123456789/158308/1/sports-car-146873_960_720.png",
"@type": "sc:Canvas",
"height": 480,
"images": [{
"@id": "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=/info.json",
"@type": "oa:Annotation",
"motivation": "sc:painting",
"on": "http://localhost:9003/dspace/canvas?context=123456789/158308/1/sports-car-146873_960_720.png",
"resource": {
"@id": "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc=/full/full/0/default.jpg",
"@type": "dctypes:Image",
"height": 480,
"service": {
"label": "DSpace IIIF Image Resource Service",
"profile": "http://iiif.io/api/image/2/level0.json",
"@context": "http://iiif.io/api/image/2/context.json",
"@id": "http://localhost:8182/iiif/2/ZHNwYWNlOnhtbHVpL2JpdHN0cmVhbS8xMjM0NTY3ODkvMTU4MzA4LzEvc3BvcnRzLWNhci0xNDY4NzNfOTYwXzcyMC5wbmc="
},
"width" : 960
"width": 960
}
} ],
"label" : "123456789/158308/1/sports-car-146873_960_720.png",
"metadata" : [ ],
"width" : 960
} ],
"label" : "123456789/158308"
}],
"label": "123456789/158308/1/sports-car-146873_960_720.png",
"metadata": [],
"width": 960
}],
"description": "N/A",
"label": "123456789/158308"
}
Loading

0 comments on commit 9fc5bd3

Please sign in to comment.