mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Removed remaining use of generator bean factories.
This commit is contained in:
@@ -13,15 +13,12 @@ import java.util.List;
|
|||||||
import de.digitalcollections.iiif.model.Motivation;
|
import de.digitalcollections.iiif.model.Motivation;
|
||||||
import de.digitalcollections.iiif.model.openannotation.Annotation;
|
import de.digitalcollections.iiif.model.openannotation.Annotation;
|
||||||
import de.digitalcollections.iiif.model.sharedcanvas.Resource;
|
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.
|
* Annotations associate content resources and commentary with a canvas.
|
||||||
* This is used for the otherContent AnnotationList and Search response.
|
* This is used for the otherContent AnnotationList and Search response.
|
||||||
*/
|
*/
|
||||||
@Component
|
|
||||||
@Scope("prototype")
|
|
||||||
public class AnnotationGenerator implements IIIFResource {
|
public class AnnotationGenerator implements IIIFResource {
|
||||||
|
|
||||||
public static final String TYPE = "sc:AnnotationList";
|
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 COMMENTING = new Motivation("oa:commenting");
|
||||||
public static final Motivation LINKING = new Motivation("oa:linking");
|
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) {
|
for (ManifestGenerator manifest : within) {
|
||||||
manifests.add(manifest.getResource());
|
this.manifests.add(manifest.getResource());
|
||||||
}
|
}
|
||||||
// property renamed to partOf in v3
|
return this;
|
||||||
annotation.setWithin(manifests);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<Annotation> getResource() {
|
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;
|
return annotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,7 @@ public class AnnotationListGenerator implements org.dspace.app.rest.iiif.model.g
|
|||||||
* Adds Annotation resource to the annotation list.
|
* Adds Annotation resource to the annotation list.
|
||||||
* @param annotation the Annotation Resource
|
* @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());
|
this.annotations.add((Annotation) annotation.getResource());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@ import org.springframework.context.annotation.Scope;
|
|||||||
import org.springframework.stereotype.Component;
|
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.
|
* 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.
|
* Used in the "related", "renderings" and "otherContent" fields of IIIF resources.
|
||||||
@@ -69,6 +69,9 @@ public class ExternalLinksGenerator implements IIIFResource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource<OtherContent> getResource() {
|
public Resource<OtherContent> getResource() {
|
||||||
|
if (identifier == null) {
|
||||||
|
throw new RuntimeException("Annotation requires an identifier");
|
||||||
|
}
|
||||||
OtherContent otherContent;
|
OtherContent otherContent;
|
||||||
if (format != null) {
|
if (format != null) {
|
||||||
otherContent = new OtherContent(identifier, format);
|
otherContent = new OtherContent(identifier, format);
|
||||||
|
@@ -60,7 +60,7 @@ public abstract class AbstractResourceService {
|
|||||||
protected void setConfiguration(ConfigurationService configurationService) {
|
protected void setConfiguration(ConfigurationService configurationService) {
|
||||||
IIIF_ENDPOINT = configurationService.getProperty("iiif.url");
|
IIIF_ENDPOINT = configurationService.getProperty("iiif.url");
|
||||||
IMAGE_SERVICE = configurationService.getProperty("iiif.image.server");
|
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");
|
BITSTREAM_PATH_PREFIX = configurationService.getProperty("iiif.bitstream.url");
|
||||||
DOCUMENT_VIEWING_HINT = configurationService.getProperty("iiif.document.viewing.hint");
|
DOCUMENT_VIEWING_HINT = configurationService.getProperty("iiif.document.viewing.hint");
|
||||||
CLIENT_URL = configurationService.getProperty("dspace.ui.url");
|
CLIENT_URL = configurationService.getProperty("dspace.ui.url");
|
||||||
|
@@ -25,7 +25,6 @@ import org.dspace.content.service.ItemService;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.services.ConfigurationService;
|
import org.dspace.services.ConfigurationService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.context.annotation.RequestScope;
|
import org.springframework.web.context.annotation.RequestScope;
|
||||||
|
|
||||||
@@ -33,7 +32,6 @@ import org.springframework.web.context.annotation.RequestScope;
|
|||||||
@RequestScope
|
@RequestScope
|
||||||
public class AnnotationListService extends AbstractResourceService {
|
public class AnnotationListService extends AbstractResourceService {
|
||||||
|
|
||||||
ApplicationContext applicationContext;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
IIIFUtils utils;
|
IIIFUtils utils;
|
||||||
@@ -54,9 +52,8 @@ public class AnnotationListService extends AbstractResourceService {
|
|||||||
AnnotationListGenerator annotationList;
|
AnnotationListGenerator annotationList;
|
||||||
|
|
||||||
|
|
||||||
public AnnotationListService(ApplicationContext applicationContext, ConfigurationService configurationService) {
|
public AnnotationListService(ConfigurationService configurationService) {
|
||||||
setConfiguration(configurationService);
|
setConfiguration(configurationService);
|
||||||
this.applicationContext = applicationContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,11 +96,11 @@ public class AnnotationListService extends AbstractResourceService {
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
AnnotationGenerator annotation = applicationContext
|
AnnotationGenerator annotationGenerator = new AnnotationGenerator()
|
||||||
.getBean(AnnotationGenerator.class, IIIF_ENDPOINT + bitstream.getID()
|
.setIdentifier(IIIF_ENDPOINT + bitstream.getID() + "/annot")
|
||||||
+ "/annot", AnnotationGenerator.LINKING);
|
.setMotivation(AnnotationGenerator.LINKING)
|
||||||
annotation.setResource(getLinksGenerator(mimetype, bitstream));
|
.setResource(getLinksGenerator(mimetype, bitstream));
|
||||||
annotationList.addResource(annotation);
|
annotationList.addResource(annotationGenerator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -193,7 +193,7 @@ public class ManifestService extends AbstractResourceService {
|
|||||||
private void addSeeAlso(Item item) {
|
private void addSeeAlso(Item item) {
|
||||||
List<Bundle> bundles = utils.getBundle(item, OTHER_CONTENT_BUNDLE);
|
List<Bundle> bundles = utils.getBundle(item, OTHER_CONTENT_BUNDLE);
|
||||||
if (bundles.size() > 0) {
|
if (bundles.size() > 0) {
|
||||||
manifestGenerator.addSeeAlso(seeAlsoService.getSeeAlso(item, bundles));
|
manifestGenerator.addSeeAlso(seeAlsoService.getSeeAlso(item.getID()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,32 +7,31 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.app.rest.iiif.service;
|
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.AnnotationGenerator;
|
||||||
import org.dspace.app.rest.iiif.model.generator.ExternalLinksGenerator;
|
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.dspace.services.ConfigurationService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.context.annotation.RequestScope;
|
import org.springframework.web.context.annotation.RequestScope;
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequestScope
|
@RequestScope
|
||||||
public class SeeAlsoService extends AbstractResourceService {
|
public class SeeAlsoService extends AbstractResourceService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ExternalLinksGenerator externalLinksGenerator;
|
||||||
|
|
||||||
private static final String SEE_ALSO_LABEL = "More descriptions of this resource";
|
private static final String SEE_ALSO_LABEL = "More descriptions of this resource";
|
||||||
|
|
||||||
public SeeAlsoService(ConfigurationService configurationService) {
|
public SeeAlsoService(ConfigurationService configurationService) {
|
||||||
setConfiguration(configurationService);
|
setConfiguration(configurationService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
public ExternalLinksGenerator getSeeAlso(UUID itemId) {
|
||||||
ExternalLinksGenerator externalLinksGenerator;
|
return externalLinksGenerator.setIdentifier(IIIF_ENDPOINT + itemId + "/manifest/seeAlso")
|
||||||
|
|
||||||
public ExternalLinksGenerator getSeeAlso(Item item, List<Bundle> bundles) {
|
|
||||||
return externalLinksGenerator.setIdentifier(IIIF_ENDPOINT + item.getID() + "/manifest/seeAlso")
|
|
||||||
.setType(AnnotationGenerator.TYPE)
|
.setType(AnnotationGenerator.TYPE)
|
||||||
.setLabel(SEE_ALSO_LABEL);
|
.setLabel(SEE_ALSO_LABEL);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user