Removed remaining use of generator bean factories.

This commit is contained in:
Michael Spalti
2021-09-15 16:30:42 -07:00
parent 2539800955
commit 0affa79216
7 changed files with 94 additions and 39 deletions

View File

@@ -13,15 +13,12 @@ import java.util.List;
import de.digitalcollections.iiif.model.Motivation;
import de.digitalcollections.iiif.model.openannotation.Annotation;
import de.digitalcollections.iiif.model.sharedcanvas.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* Annotations associate content resources and commentary with a canvas.
* This is used for the otherContent AnnotationList and Search response.
*/
@Component
@Scope("prototype")
public class AnnotationGenerator implements IIIFResource {
public static final String TYPE = "sc:AnnotationList";
@@ -29,35 +26,94 @@ public class AnnotationGenerator implements IIIFResource {
public static final Motivation COMMENTING = new Motivation("oa:commenting");
public static final Motivation LINKING = new Motivation("oa:linking");
private Annotation annotation;
private Motivation motivation;
private String identifier;
private CanvasGenerator canvasGenerator;
private ContentAsTextGenerator contentAsTextGenerator;
private ExternalLinksGenerator externalLinksGenerator;
List<Resource> manifests = new ArrayList<>();
public AnnotationGenerator(String identifier, Motivation motivation) {
annotation = new Annotation(identifier, motivation);
/**
* Set the annotation identifier. Required.
* @param identifier
* @return
*/
public AnnotationGenerator setIdentifier(String identifier) {
this.identifier = identifier;
return this;
}
public void setOnCanvas(CanvasGenerator canvas) {
annotation.setOn(canvas.getResource());
/**
* Sets the annotation motivtion. Required.
* @param motivation
* @return
*/
public AnnotationGenerator setMotivation(Motivation motivation) {
this.motivation = motivation;
return this;
}
public void setResource(org.dspace.app.rest.iiif.model.generator.ContentAsTextGenerator contentAsText) {
annotation.setResource(contentAsText.getResource());
/**
* Set the canvas for this annotation.
* @param canvas
* @return
*/
public AnnotationGenerator setOnCanvas(CanvasGenerator canvas) {
this.canvasGenerator = canvas;
return this;
}
public void setResource(org.dspace.app.rest.iiif.model.generator.ExternalLinksGenerator otherContent) {
annotation.setResource(otherContent.getResource());
/**
* Set a text resource for this annotation.
* @param contentAsText
* @return
*/
public AnnotationGenerator setResource(ContentAsTextGenerator contentAsText) {
this.contentAsTextGenerator = contentAsText;
return this;
}
public void setWithin(List<ManifestGenerator> within) {
List<Resource> manifests = new ArrayList<>();
/**
* Set the external link for this annotation.
* @param otherContent
* @return
*/
public AnnotationGenerator setResource(ExternalLinksGenerator otherContent) {
this.externalLinksGenerator = otherContent;
return this;
}
/**
* Set the within property for this annotation. This property
* is a list of manifests. The property is renamed to partOf in v3
* @param within
* @return
*/
public AnnotationGenerator setWithin(List<ManifestGenerator> within) {
for (ManifestGenerator manifest : within) {
manifests.add(manifest.getResource());
this.manifests.add(manifest.getResource());
}
// property renamed to partOf in v3
annotation.setWithin(manifests);
return this;
}
@Override
public Resource<Annotation> getResource() {
if (identifier == null || motivation == null) {
throw new RuntimeException("Annotations require both an identifier and a motivation");
}
Annotation annotation = new Annotation(identifier, motivation);
annotation.setWithin(manifests);
// These optional annotation fields vary with the context.
if (canvasGenerator != null) {
annotation.setOn(canvasGenerator.getResource());
}
if (externalLinksGenerator != null) {
annotation.setResource(externalLinksGenerator.getResource());
}
if (contentAsTextGenerator != null) {
annotation.setResource(contentAsTextGenerator.getResource());
}
return annotation;
}
}

View File

@@ -37,7 +37,7 @@ public class AnnotationListGenerator implements org.dspace.app.rest.iiif.model.g
* Adds Annotation resource to the annotation list.
* @param annotation the Annotation Resource
*/
public void addResource(org.dspace.app.rest.iiif.model.generator.AnnotationGenerator annotation) {
public void addResource(AnnotationGenerator annotation) {
this.annotations.add((Annotation) annotation.getResource());
}

View File

@@ -14,7 +14,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* Facade for the IIIF Presentation API version 2.1.1 "OtherContent" domain model class.
* Facade for the API version 2.1.1 "OtherContent" domain model.
*
* This is the type for Content resources such as images or texts that are associated with a canvas.
* Used in the "related", "renderings" and "otherContent" fields of IIIF resources.
@@ -69,6 +69,9 @@ public class ExternalLinksGenerator implements IIIFResource {
@Override
public Resource<OtherContent> getResource() {
if (identifier == null) {
throw new RuntimeException("Annotation requires an identifier");
}
OtherContent otherContent;
if (format != null) {
otherContent = new OtherContent(identifier, format);

View File

@@ -60,7 +60,7 @@ public abstract class AbstractResourceService {
protected void setConfiguration(ConfigurationService configurationService) {
IIIF_ENDPOINT = configurationService.getProperty("iiif.url");
IMAGE_SERVICE = configurationService.getProperty("iiif.image.server");
SEARCH_URL = configurationService.getProperty("iiif.solr.search.url");
SEARCH_URL = configurationService.getProperty("iiif.search.url");
BITSTREAM_PATH_PREFIX = configurationService.getProperty("iiif.bitstream.url");
DOCUMENT_VIEWING_HINT = configurationService.getProperty("iiif.document.viewing.hint");
CLIENT_URL = configurationService.getProperty("dspace.ui.url");

View File

@@ -25,7 +25,6 @@ import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
@@ -33,7 +32,6 @@ import org.springframework.web.context.annotation.RequestScope;
@RequestScope
public class AnnotationListService extends AbstractResourceService {
ApplicationContext applicationContext;
@Autowired
IIIFUtils utils;
@@ -54,9 +52,8 @@ public class AnnotationListService extends AbstractResourceService {
AnnotationListGenerator annotationList;
public AnnotationListService(ApplicationContext applicationContext, ConfigurationService configurationService) {
public AnnotationListService(ConfigurationService configurationService) {
setConfiguration(configurationService);
this.applicationContext = applicationContext;
}
/**
@@ -99,11 +96,11 @@ public class AnnotationListService extends AbstractResourceService {
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
AnnotationGenerator annotation = applicationContext
.getBean(AnnotationGenerator.class, IIIF_ENDPOINT + bitstream.getID()
+ "/annot", AnnotationGenerator.LINKING);
annotation.setResource(getLinksGenerator(mimetype, bitstream));
annotationList.addResource(annotation);
AnnotationGenerator annotationGenerator = new AnnotationGenerator()
.setIdentifier(IIIF_ENDPOINT + bitstream.getID() + "/annot")
.setMotivation(AnnotationGenerator.LINKING)
.setResource(getLinksGenerator(mimetype, bitstream));
annotationList.addResource(annotationGenerator);
}
}
}

View File

@@ -193,7 +193,7 @@ public class ManifestService extends AbstractResourceService {
private void addSeeAlso(Item item) {
List<Bundle> bundles = utils.getBundle(item, OTHER_CONTENT_BUNDLE);
if (bundles.size() > 0) {
manifestGenerator.addSeeAlso(seeAlsoService.getSeeAlso(item, bundles));
manifestGenerator.addSeeAlso(seeAlsoService.getSeeAlso(item.getID()));
}
}

View File

@@ -7,32 +7,31 @@
*/
package org.dspace.app.rest.iiif.service;
import java.util.List;
import java.util.UUID;
import org.dspace.app.rest.iiif.model.generator.AnnotationGenerator;
import org.dspace.app.rest.iiif.model.generator.ExternalLinksGenerator;
import org.dspace.content.Bundle;
import org.dspace.content.Item;
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
@Component
@RequestScope
public class SeeAlsoService extends AbstractResourceService {
@Autowired
ExternalLinksGenerator externalLinksGenerator;
private static final String SEE_ALSO_LABEL = "More descriptions of this resource";
public SeeAlsoService(ConfigurationService configurationService) {
setConfiguration(configurationService);
}
@Autowired
ExternalLinksGenerator externalLinksGenerator;
public ExternalLinksGenerator getSeeAlso(Item item, List<Bundle> bundles) {
return externalLinksGenerator.setIdentifier(IIIF_ENDPOINT + item.getID() + "/manifest/seeAlso")
public ExternalLinksGenerator getSeeAlso(UUID itemId) {
return externalLinksGenerator.setIdentifier(IIIF_ENDPOINT + itemId + "/manifest/seeAlso")
.setType(AnnotationGenerator.TYPE)
.setLabel(SEE_ALSO_LABEL);