Skip to content

Commit 67d9838

Browse files
authored
Merge pull request #153 from TAMULib/cantaloupe_sprint_2_staging
Cantaloupe sprint 2 staging
2 parents 426d393 + e1456a2 commit 67d9838

File tree

168 files changed

+6037
-1036
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+6037
-1036
lines changed

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@
172172
<scope>test</scope>
173173
</dependency>
174174

175+
<dependency>
176+
<groupId>org.mock-server</groupId>
177+
<artifactId>mockserver-junit-jupiter-no-dependencies</artifactId>
178+
<version>5.14.0</version>
179+
</dependency>
180+
181+
<dependency>
182+
<groupId>org.mock-server</groupId>
183+
<artifactId>mockserver-client-java-no-dependencies</artifactId>
184+
<version>5.14.0</version>
185+
</dependency>
186+
175187
<dependency>
176188
<groupId>it.ozimov</groupId>
177189
<artifactId>embedded-redis</artifactId>

src/main/java/edu/tamu/iiif/exception/NotFoundException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ public NotFoundException(String message) {
1010
super(message);
1111
}
1212

13+
public NotFoundException(String message, Exception e) {
14+
super(message, e);
15+
}
16+
1317
}

src/main/java/edu/tamu/iiif/service/AbstractManifestService.java

Lines changed: 35 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,14 @@
22

33
import static edu.tamu.iiif.constants.Constants.IIIF_IMAGE_API_CONTEXT;
44
import static edu.tamu.iiif.constants.Constants.IIIF_IMAGE_API_LEVEL_ZERO_PROFILE;
5-
import static edu.tamu.iiif.utility.RdfModelUtility.createRdfModel;
65
import static edu.tamu.iiif.utility.RdfModelUtility.getObjects;
76
import static edu.tamu.iiif.utility.StringUtility.encode;
8-
import static edu.tamu.iiif.utility.StringUtility.encodeSpaces;
97
import static edu.tamu.iiif.utility.StringUtility.joinPath;
108

11-
import java.io.IOException;
12-
import java.net.URI;
13-
import java.net.URISyntaxException;
14-
import java.net.URLDecoder;
15-
import java.nio.charset.StandardCharsets;
16-
import java.util.ArrayList;
17-
import java.util.Collection;
18-
import java.util.HashMap;
19-
import java.util.List;
20-
import java.util.Map;
21-
import java.util.Optional;
22-
import java.util.stream.Collectors;
23-
24-
import javax.annotation.PostConstruct;
25-
26-
import org.apache.jena.rdf.model.Model;
27-
import org.apache.jena.rdf.model.Property;
28-
import org.apache.jena.rdf.model.RDFNode;
29-
import org.apache.jena.rdf.model.Resource;
30-
import org.apache.jena.rdf.model.Statement;
31-
import org.apache.jena.rdf.model.StmtIterator;
32-
import org.slf4j.Logger;
33-
import org.slf4j.LoggerFactory;
34-
import org.springframework.beans.factory.annotation.Autowired;
35-
import org.springframework.beans.factory.annotation.Value;
36-
import org.springframework.http.HttpHeaders;
37-
import org.springframework.web.client.RestClientException;
38-
import org.springframework.web.client.RestTemplate;
39-
409
import com.fasterxml.jackson.databind.JsonNode;
4110
import com.fasterxml.jackson.databind.MapperFeature;
4211
import com.fasterxml.jackson.databind.ObjectMapper;
4312
import com.fasterxml.jackson.databind.SerializationFeature;
44-
4513
import de.digitalcollections.iiif.presentation.model.api.v2.Canvas;
4614
import de.digitalcollections.iiif.presentation.model.api.v2.Image;
4715
import de.digitalcollections.iiif.presentation.model.api.v2.ImageResource;
@@ -66,6 +34,31 @@
6634
import edu.tamu.iiif.model.RedisManifest;
6735
import edu.tamu.iiif.model.rdf.RdfResource;
6836
import edu.tamu.iiif.model.repo.RedisManifestRepo;
37+
import java.io.IOException;
38+
import java.net.URI;
39+
import java.net.URISyntaxException;
40+
import java.util.ArrayList;
41+
import java.util.Collection;
42+
import java.util.HashMap;
43+
import java.util.List;
44+
import java.util.Map;
45+
import java.util.Optional;
46+
import java.util.stream.Collectors;
47+
import javax.annotation.PostConstruct;
48+
import org.apache.jena.rdf.model.Model;
49+
import org.apache.jena.rdf.model.Property;
50+
import org.apache.jena.rdf.model.RDFNode;
51+
import org.apache.jena.rdf.model.Resource;
52+
import org.apache.jena.rdf.model.Statement;
53+
import org.apache.jena.rdf.model.StmtIterator;
54+
import org.apache.jena.riot.RDFDataMgr;
55+
import org.slf4j.Logger;
56+
import org.slf4j.LoggerFactory;
57+
import org.springframework.beans.factory.annotation.Autowired;
58+
import org.springframework.beans.factory.annotation.Value;
59+
import org.springframework.http.HttpHeaders;
60+
import org.springframework.web.client.RestClientException;
61+
import org.springframework.web.client.RestTemplate;
6962

7063
public abstract class AbstractManifestService implements ManifestService {
7164

@@ -134,7 +127,6 @@ public String getManifest(ManifestRequest request) throws IOException, URISyntax
134127
redisManifestRepo.save(new RedisManifest(encode(path), getManifestType(), getRepository(), request.getAllowed(), request.getDisallowed(), manifest));
135128
update = false;
136129
}
137-
138130
if (update) {
139131
RedisManifest redisManifest = optionalRedisManifest.get();
140132
manifest = generateManifest(request);
@@ -144,17 +136,16 @@ public String getManifest(ManifestRequest request) throws IOException, URISyntax
144136
} else {
145137
logger.info("Manifest requested: " + path);
146138
}
147-
148139
return manifest;
149140
}
150141

151-
protected RdfResource getRdfResourceByContextPath(String contextPath) throws NotFoundException {
142+
protected RdfResource getRdfResourceByContextPath(String contextPath) throws IOException {
152143
String rdfUrl = getRdfUrl(contextPath);
153144
Model model = getRdfModel(rdfUrl);
154145
return getRdfResource(model, rdfUrl);
155146
}
156147

157-
protected RdfResource getRdfResourceByUrl(String rdfUrl) throws NotFoundException {
148+
protected RdfResource getRdfResourceByUrl(String rdfUrl) throws IOException {
158149
Model model = getRdfModel(rdfUrl);
159150
return getRdfResource(model, rdfUrl);
160151
}
@@ -165,30 +156,12 @@ private RdfResource getRdfResource(Model model, String rdfUrl) {
165156
return new RdfResource(model, model.getResource(rdfUrl));
166157
}
167158

168-
protected Model getRdfModel(String url) throws NotFoundException {
169-
return createRdfModel(getRdf(url));
170-
}
171-
172-
private String getRdf(String url) throws NotFoundException {
173-
try {
174-
url = URLDecoder.decode(url, StandardCharsets.UTF_8);
175-
if (logger.isDebugEnabled()) {
176-
logger.info("Requesting RDF for {}", url);
177-
}
178-
Optional<String> rdf = Optional.ofNullable(restTemplate.getForObject(url, String.class));
179-
if (rdf.isPresent()) {
180-
logger.debug("RDF for {}: \n{}\n", url, rdf.get());
181-
return rdf.get();
182-
}
183-
} catch (RestClientException e) {
184-
logger.error("Failed to get RDF for {}: {}", url, e.getMessage());
185-
logger.debug("Error while requesting RDF for {}: {}", url, e.getMessage(), e);
186-
}
187-
throw new NotFoundException("RDF not found! " + url);
159+
protected Model getRdfModel(String url) throws IOException {
160+
return RDFDataMgr.loadModel(url);
188161
}
189162

190163
protected URI buildId(String path) throws URISyntaxException {
191-
return new URI(encodeSpaces(getIiifServiceUrl() + FORWARD_SLASH + getManifestType().getName() + FORWARD_SLASH + path));
164+
return new URI(getIiifServiceUrl() + FORWARD_SLASH + getManifestType().getName() + FORWARD_SLASH + path);
192165
}
193166

194167
protected String getLogo(RdfResource rdfResource) {
@@ -285,11 +258,12 @@ protected boolean includeResource(ManifestRequest request, String mimeType) {
285258

286259
protected String fetchImageInfo(String url) throws NotFoundException {
287260
logger.debug("Fetching image info {}", url);
288-
Optional<String> imageInfo = Optional.ofNullable(restTemplate.getForObject(url, String.class));
289-
if (imageInfo.isPresent()) {
290-
return imageInfo.get();
261+
262+
try {
263+
return restTemplate.getForObject(url, String.class);
264+
} catch (RestClientException e) {
265+
throw new NotFoundException("Image not found for " + url, e);
291266
}
292-
throw new NotFoundException("Image information not found!");
293267
}
294268

295269
protected URI getImageUri(String url) throws URISyntaxException {

src/main/java/edu/tamu/iiif/service/CustomRedirectStrategy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.net.URISyntaxException;
66
import java.net.URLDecoder;
77
import java.util.Optional;
8-
98
import org.apache.commons.validator.routines.UrlValidator;
109
import org.apache.http.Header;
1110
import org.apache.http.HttpRequest;

src/main/java/edu/tamu/iiif/service/ManifestService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
public interface ManifestService {
1010

1111
public String getManifest(ManifestRequest request) throws IOException, URISyntaxException;
12-
12+
1313
public String getRepository();
14-
14+
1515
public ManifestType getManifestType();
1616

1717
}

src/main/java/edu/tamu/iiif/service/RedisResourceResolver.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package edu.tamu.iiif.service;
22

3+
import edu.tamu.iiif.exception.NotFoundException;
4+
import edu.tamu.iiif.model.RedisResource;
5+
import edu.tamu.iiif.model.repo.RedisResourceRepo;
36
import java.net.URISyntaxException;
47
import java.util.Optional;
5-
68
import org.apache.commons.validator.routines.UrlValidator;
79
import org.springframework.beans.factory.annotation.Autowired;
810
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
911
import org.springframework.stereotype.Service;
1012

11-
import edu.tamu.iiif.exception.NotFoundException;
12-
import edu.tamu.iiif.model.RedisResource;
13-
import edu.tamu.iiif.model.repo.RedisResourceRepo;
14-
1513
@Service
1614
@ConditionalOnProperty(value = "iiif.resolver.type", havingValue = "redis", matchIfMissing = true)
1715
public class RedisResourceResolver implements ResourceResolver {

src/main/java/edu/tamu/iiif/service/dspace/rdf/AbstractDSpaceRdfManifestService.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,8 @@
1111
import static edu.tamu.iiif.constants.Constants.PRESENTATION_IDENTIFIER;
1212
import static edu.tamu.iiif.constants.Constants.SEQUENCE_IDENTIFIER;
1313
import static edu.tamu.iiif.utility.RdfModelUtility.hasObject;
14-
import static edu.tamu.iiif.utility.StringUtility.encodeSpaces;
1514
import static edu.tamu.iiif.utility.StringUtility.joinPath;
1615

17-
import java.io.IOException;
18-
import java.io.UnsupportedEncodingException;
19-
import java.net.URI;
20-
import java.net.URISyntaxException;
21-
import java.net.URLDecoder;
22-
import java.util.ArrayList;
23-
import java.util.List;
24-
import java.util.Optional;
25-
26-
import org.apache.jena.rdf.model.Model;
27-
import org.apache.jena.rdf.model.NodeIterator;
28-
import org.springframework.beans.factory.annotation.Autowired;
29-
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
30-
3116
import de.digitalcollections.iiif.presentation.model.api.v2.Canvas;
3217
import de.digitalcollections.iiif.presentation.model.api.v2.ImageResource;
3318
import de.digitalcollections.iiif.presentation.model.api.v2.Sequence;
@@ -43,6 +28,18 @@
4328
import edu.tamu.iiif.model.rdf.RdfResource;
4429
import edu.tamu.iiif.service.AbstractManifestService;
4530
import edu.tamu.iiif.utility.RdfModelUtility;
31+
import java.io.IOException;
32+
import java.io.UnsupportedEncodingException;
33+
import java.net.URI;
34+
import java.net.URISyntaxException;
35+
import java.net.URLDecoder;
36+
import java.util.ArrayList;
37+
import java.util.List;
38+
import java.util.Optional;
39+
import org.apache.jena.rdf.model.Model;
40+
import org.apache.jena.rdf.model.NodeIterator;
41+
import org.springframework.beans.factory.annotation.Autowired;
42+
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
4643

4744
@ConditionalOnExpression(DSPACE_RDF_CONDITION)
4845
public abstract class AbstractDSpaceRdfManifestService extends AbstractManifestService {
@@ -90,19 +87,19 @@ protected boolean isItem(Model model) {
9087
}
9188

9289
protected URI getDSpaceIiifCollectionUri(String handle) throws URISyntaxException {
93-
return getDSpaceIiifUri(encodeSpaces(handle), COLLECTION_IDENTIFIER);
90+
return getDSpaceIiifUri(handle, COLLECTION_IDENTIFIER);
9491
}
9592

9693
protected URI getDSpaceIiifPresentationUri(String handle) throws URISyntaxException {
97-
return getDSpaceIiifUri(encodeSpaces(handle), PRESENTATION_IDENTIFIER);
94+
return getDSpaceIiifUri(handle, PRESENTATION_IDENTIFIER);
9895
}
9996

10097
protected URI getDSpaceIiifSequenceUri(String handle) throws URISyntaxException {
101-
return getDSpaceIiifUri(encodeSpaces(handle), SEQUENCE_IDENTIFIER);
98+
return getDSpaceIiifUri(handle, SEQUENCE_IDENTIFIER);
10299
}
103100

104101
protected URI getDSpaceIiifCanvasUri(String handle) throws URISyntaxException {
105-
return getDSpaceIiifUri(encodeSpaces(handle), CANVAS_IDENTIFIER);
102+
return getDSpaceIiifUri(handle, CANVAS_IDENTIFIER);
106103
}
107104

108105
protected String getHandle(String uri) {
@@ -181,7 +178,7 @@ private URI getDSpaceIiifUri(String handle, String type) throws URISyntaxExcepti
181178
private List<Canvas> getCanvases(ManifestRequest request, RdfResource rdfResource) throws IOException, URISyntaxException {
182179
List<Canvas> canvases = new ArrayList<Canvas>();
183180
// NOTE: canvas per bitstream and bitstreams uri must contain the context handle path of the desired resource
184-
String contextHandlePath = encodeSpaces(getHandlePath(rdfResource.getId()));
181+
String contextHandlePath = getHandlePath(rdfResource.getId());
185182
NodeIterator bitstreamIterator = rdfResource.getAllNodesOfPropertyWithId(DSPACE_HAS_BITSTREAM_PREDICATE);
186183
while (bitstreamIterator.hasNext()) {
187184
String uri = bitstreamIterator.next().toString();

src/main/java/edu/tamu/iiif/service/dspace/rdf/DSpaceRdfCollectionManifestService.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
import static edu.tamu.iiif.constants.Constants.DSPACE_HAS_SUB_COMMUNITY_PREDICATE;
77
import static edu.tamu.iiif.model.ManifestType.COLLECTION;
88

9-
import java.io.IOException;
10-
import java.net.URI;
11-
import java.net.URISyntaxException;
12-
import java.util.ArrayList;
13-
import java.util.List;
14-
import java.util.Optional;
15-
16-
import org.apache.jena.rdf.model.NodeIterator;
17-
import org.springframework.stereotype.Service;
18-
199
import de.digitalcollections.iiif.presentation.model.api.v2.Collection;
2010
import de.digitalcollections.iiif.presentation.model.api.v2.Metadata;
2111
import de.digitalcollections.iiif.presentation.model.api.v2.references.CollectionReference;
@@ -25,10 +15,17 @@
2515
import de.digitalcollections.iiif.presentation.model.impl.v2.references.CollectionReferenceImpl;
2616
import de.digitalcollections.iiif.presentation.model.impl.v2.references.ManifestReferenceImpl;
2717
import edu.tamu.iiif.controller.ManifestRequest;
28-
import edu.tamu.iiif.exception.NotFoundException;
2918
import edu.tamu.iiif.model.ManifestType;
3019
import edu.tamu.iiif.model.rdf.RdfResource;
3120
import edu.tamu.iiif.utility.RdfModelUtility;
21+
import java.io.IOException;
22+
import java.net.URI;
23+
import java.net.URISyntaxException;
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
import java.util.Optional;
27+
import org.apache.jena.rdf.model.NodeIterator;
28+
import org.springframework.stereotype.Service;
3229

3330
@Service
3431
public class DSpaceRdfCollectionManifestService extends AbstractDSpaceRdfManifestService {
@@ -38,7 +35,7 @@ protected String generateManifest(ManifestRequest request) throws URISyntaxExcep
3835
return mapper.writeValueAsString(generateCollection(request));
3936
}
4037

41-
private Collection generateCollection(ManifestRequest request) throws URISyntaxException, NotFoundException {
38+
private Collection generateCollection(ManifestRequest request) throws URISyntaxException, IOException {
4239
String context = request.getContext();
4340

4441
String parameterizedContext = RdfModelUtility.getParameterizedId(request);
@@ -75,7 +72,7 @@ private Collection generateCollection(ManifestRequest request) throws URISyntaxE
7572
return collection;
7673
}
7774

78-
private List<ManifestReference> getResourceManifests(ManifestRequest request, RdfResource rdfResource) throws URISyntaxException, NotFoundException {
75+
private List<ManifestReference> getResourceManifests(ManifestRequest request, RdfResource rdfResource) throws URISyntaxException, IOException {
7976
List<ManifestReference> manifests = new ArrayList<ManifestReference>();
8077
if (isItem(rdfResource.getModel())) {
8178
NodeIterator hasBitstreamIterator = rdfResource.getAllNodesOfPropertyWithId(DSPACE_HAS_BITSTREAM_PREDICATE);
@@ -100,7 +97,7 @@ private List<ManifestReference> getResourceManifests(ManifestRequest request, Rd
10097
return manifests;
10198
}
10299

103-
private List<CollectionReference> getSubcollections(RdfResource rdfResource) throws URISyntaxException, NotFoundException {
100+
private List<CollectionReference> getSubcollections(RdfResource rdfResource) throws URISyntaxException, IOException {
104101
List<CollectionReference> collectionsToElide = new ArrayList<CollectionReference>();
105102
List<CollectionReference> subcollections = getSubcommunities(rdfResource, collectionsToElide);
106103
List<CollectionReference> collections = getCollections(rdfResource);
@@ -119,7 +116,7 @@ private List<CollectionReference> getSubcollections(RdfResource rdfResource) thr
119116
return subcollections;
120117
}
121118

122-
private List<CollectionReference> getSubcommunities(RdfResource rdfResource, List<CollectionReference> collectionsToElide) throws URISyntaxException, NotFoundException {
119+
private List<CollectionReference> getSubcommunities(RdfResource rdfResource, List<CollectionReference> collectionsToElide) throws URISyntaxException, IOException {
123120
List<CollectionReference> subcommunities = new ArrayList<CollectionReference>();
124121
NodeIterator subcommunityIterator = rdfResource.getAllNodesOfPropertyWithId(DSPACE_HAS_SUB_COMMUNITY_PREDICATE);
125122
while (subcommunityIterator.hasNext()) {
@@ -131,7 +128,7 @@ private List<CollectionReference> getSubcommunities(RdfResource rdfResource, Lis
131128
return subcommunities;
132129
}
133130

134-
private List<CollectionReference> getCollections(RdfResource rdfResource) throws URISyntaxException, NotFoundException {
131+
private List<CollectionReference> getCollections(RdfResource rdfResource) throws URISyntaxException, IOException {
135132
List<CollectionReference> collections = new ArrayList<CollectionReference>();
136133
NodeIterator collectionIterator = rdfResource.getAllNodesOfPropertyWithId(DSPACE_HAS_COLLECTION_PREDICATE);
137134
while (collectionIterator.hasNext()) {

0 commit comments

Comments
 (0)