1
|
/**
|
2
|
* Copyright (C) 2020 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.remote.controller.iiif;
|
10
|
|
11
|
import java.io.IOException;
|
12
|
import java.util.Set;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import javax.servlet.http.HttpServletRequest;
|
16
|
import javax.servlet.http.HttpServletResponse;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
20
|
import org.springframework.web.bind.WebDataBinder;
|
21
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
22
|
import org.springframework.web.bind.annotation.InitBinder;
|
23
|
import org.springframework.web.bind.annotation.PathVariable;
|
24
|
import org.springframework.web.bind.annotation.RequestMapping;
|
25
|
import org.springframework.web.bind.annotation.RequestMethod;
|
26
|
import org.springframework.web.bind.annotation.RequestParam;
|
27
|
import org.springframework.web.bind.annotation.RestController;
|
28
|
|
29
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
30
|
|
31
|
import de.digitalcollections.iiif.model.jackson.IiifObjectMapper;
|
32
|
import de.digitalcollections.iiif.model.sharedcanvas.Manifest;
|
33
|
import eu.etaxonomy.cdm.api.service.IMediaService;
|
34
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
35
|
import eu.etaxonomy.cdm.api.service.media.MediaInfoFactory;
|
36
|
import eu.etaxonomy.cdm.api.util.TaxonRelationshipEdge;
|
37
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
38
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
39
|
import eu.etaxonomy.cdm.persistence.dao.initializer.EntityInitStrategy;
|
40
|
import eu.etaxonomy.cdm.remote.controller.AbstractController;
|
41
|
import eu.etaxonomy.cdm.remote.controller.MediaPortalController;
|
42
|
import eu.etaxonomy.cdm.remote.controller.TaxonPortalController;
|
43
|
import eu.etaxonomy.cdm.remote.controller.TaxonPortalController.EntityMediaContext;
|
44
|
import eu.etaxonomy.cdm.remote.controller.util.ControllerUtils;
|
45
|
import eu.etaxonomy.cdm.remote.controller.util.IMediaToolbox;
|
46
|
import eu.etaxonomy.cdm.remote.editor.CdmTypePropertyEditor;
|
47
|
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
|
48
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
49
|
import io.swagger.annotations.Api;
|
50
|
/**
|
51
|
* Serves media lists as iiif manifest files ( for the IIIF Presentation API see https://iiif.io/api/presentation/2.1/#resource-structure).
|
52
|
*
|
53
|
* @see https://dev.e-taxonomy.eu/redmine/issues/8867
|
54
|
*
|
55
|
* @author a.kohlbecker
|
56
|
* @since Feb 28, 2020
|
57
|
*/
|
58
|
@RestController
|
59
|
@CrossOrigin(origins = "*")
|
60
|
@Api("iiif")
|
61
|
@RequestMapping(value = {"/iiif"}, produces = "application/json; charset=utf-8")
|
62
|
public class ManifestController {
|
63
|
|
64
|
private static final String HTTP_IIIF_CYBERTAXONOMY_ORG = "http://iiif.cybertaxonomy.org/";
|
65
|
|
66
|
public static final Logger logger = Logger.getLogger(ManifestController.class);
|
67
|
|
68
|
@InitBinder
|
69
|
public void initBinder(WebDataBinder binder) {
|
70
|
binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
|
71
|
// binder.registerCustomEditor(NamedArea.class, new NamedAreaPropertyEditor());
|
72
|
// binder.registerCustomEditor(MatchMode.class, new MatchModePropertyEditor());
|
73
|
binder.registerCustomEditor(Class.class, new CdmTypePropertyEditor());
|
74
|
// binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
|
75
|
// binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<>(termService));
|
76
|
}
|
77
|
|
78
|
@Autowired
|
79
|
private TaxonPortalController taxonPortalController;
|
80
|
|
81
|
@Autowired
|
82
|
private ITermService termService;
|
83
|
|
84
|
@Autowired
|
85
|
private IMediaToolbox mediaTools;
|
86
|
|
87
|
@Autowired
|
88
|
private IMediaService mediaService;
|
89
|
|
90
|
@Autowired
|
91
|
private MediaInfoFactory mediaInfoFactory;
|
92
|
|
93
|
@RequestMapping(
|
94
|
value = {"taxon/{uuid}/manifest"},
|
95
|
method = RequestMethod.GET)
|
96
|
public String doTaxonMedia(
|
97
|
@PathVariable("uuid") UUID uuid,
|
98
|
@RequestParam(value = "type", required = false) Class<? extends MediaRepresentationPart> type,
|
99
|
@RequestParam(value = "mimeTypes", required = false) String[] mimeTypes,
|
100
|
@RequestParam(value = "relationships", required = false) UuidList relationshipUuids,
|
101
|
@RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,
|
102
|
@RequestParam(value = "includeTaxonDescriptions", required = false) Boolean includeTaxonDescriptions,
|
103
|
@RequestParam(value = "includeOccurrences", required = false, defaultValue = "false") Boolean includeOccurrences,
|
104
|
@RequestParam(value = "includeTaxonNameDescriptions", required = false, defaultValue = "false") Boolean includeTaxonNameDescriptions,
|
105
|
@RequestParam(value = "includeTaxonomicChildren", required = false, defaultValue = "false") Boolean includeTaxonomicChildren,
|
106
|
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
107
|
|
108
|
logger.info("doGetMedia() " + AbstractController.requestPathAndQuery(request));
|
109
|
|
110
|
EntityInitStrategy taxonInitStrategy = includeTaxonomicChildren? TaxonPortalController.TAXON_WITH_CHILDNODES_INIT_STRATEGY : TaxonPortalController.TAXON_INIT_STRATEGY;
|
111
|
EntityMediaContext<Taxon> entityMediaContext = taxonPortalController.loadMediaForTaxonAndRelated(uuid,
|
112
|
relationshipUuids, relationshipInversUuids,
|
113
|
includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions,
|
114
|
response, taxonInitStrategy.getPropertyPaths(),
|
115
|
MediaPortalController.MEDIA_INIT_STRATEGY.getPropertyPaths());
|
116
|
|
117
|
if(includeTaxonomicChildren){
|
118
|
Set<TaxonRelationshipEdge> includeRelationships = ControllerUtils.loadIncludeRelationships(relationshipUuids, relationshipInversUuids, termService);
|
119
|
entityMediaContext.setMedia(
|
120
|
taxonPortalController.addTaxonomicChildrenMedia(includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions, entityMediaContext.getEntity(), includeRelationships, entityMediaContext.getMedia())
|
121
|
);
|
122
|
}
|
123
|
ManifestComposer manifestFactory = new ManifestComposer(HTTP_IIIF_CYBERTAXONOMY_ORG, mediaTools, mediaService, mediaInfoFactory);
|
124
|
manifestFactory.setDoJoinAttributions(true);
|
125
|
manifestFactory.setUseThumbnailDimensionsForCanvas(true);
|
126
|
return serializeManifest(manifestFactory.manifestFor(entityMediaContext, "taxon", uuid.toString()));
|
127
|
}
|
128
|
|
129
|
private String serializeManifest(Manifest manifest) throws JsonProcessingException{
|
130
|
IiifObjectMapper iiifMapper = new IiifObjectMapper();
|
131
|
return iiifMapper.writeValueAsString(manifest);
|
132
|
}
|
133
|
|
134
|
|
135
|
}
|