1
|
/**
|
2
|
* Copyright (C) 2007 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.service;
|
10
|
|
11
|
import java.util.StringTokenizer;
|
12
|
import java.util.Vector;
|
13
|
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.stereotype.Controller;
|
16
|
import org.springframework.web.bind.WebDataBinder;
|
17
|
import org.springframework.web.bind.annotation.InitBinder;
|
18
|
import org.springframework.web.bind.annotation.RequestMapping;
|
19
|
import org.springframework.web.bind.annotation.RequestMethod;
|
20
|
import org.springframework.web.bind.annotation.RequestParam;
|
21
|
import org.springframework.web.servlet.ModelAndView;
|
22
|
|
23
|
import com.ibm.lsid.LSIDException;
|
24
|
import com.ibm.lsid.MetadataResponse;
|
25
|
import com.ibm.lsid.server.LSIDServerException;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.service.lsid.LSIDMetadataService;
|
28
|
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
|
29
|
import eu.etaxonomy.cdm.model.common.LSID;
|
30
|
import eu.etaxonomy.cdm.remote.editor.LSIDPropertyEditor;
|
31
|
import io.swagger.annotations.Api;
|
32
|
|
33
|
/**
|
34
|
* Controller which accepts requests for the metadata representation of an object
|
35
|
* with a given lsid.
|
36
|
*
|
37
|
* @author ben
|
38
|
* @author Ben Szekely (<a href="mailto:bhszekel@us.ibm.com">bhszekel@us.ibm.com</a>)
|
39
|
* @see com.ibm.lsid.server.servlet.MetadataServlet
|
40
|
*/
|
41
|
@Controller(value = "lsidMetadataController")
|
42
|
@Api(value="lsid_authority_metadata",
|
43
|
description="Controller which accepts incoming requests to the LSIDMetadataService.")
|
44
|
public class MetadataController {
|
45
|
|
46
|
private LSIDMetadataService lsidMetadataService;
|
47
|
|
48
|
@Autowired
|
49
|
public void setLsidMetadataService(LSIDMetadataService lsidMetadataService) {
|
50
|
this.lsidMetadataService = lsidMetadataService;
|
51
|
}
|
52
|
|
53
|
@InitBinder
|
54
|
public void initBinder(WebDataBinder binder) {
|
55
|
binder.registerCustomEditor(LSID.class, new LSIDPropertyEditor());
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Handle requests for the metadata representation of an object with a given lsid. Will return metadata in any format supported
|
60
|
* from a list of formats if specified.
|
61
|
*
|
62
|
* @param lsid the lsid to get metadata for
|
63
|
* @param formats a comma separated list of acceptable formats to the client
|
64
|
* @return ModelAndView containing the metadata response as an object with key 'metadataResponse', view name 'Metadata.rdf'
|
65
|
* @throws LSIDServerException
|
66
|
*/
|
67
|
@RequestMapping(value = "/authority/metadata.do", params = "lsid", method = RequestMethod.GET)
|
68
|
public ModelAndView getMetadata(@RequestParam("lsid") LSID lsid,
|
69
|
@RequestParam(value = "acceptedFormats", required = false) String formats) throws LSIDServerException {
|
70
|
String[] acceptedFormats = null;
|
71
|
if (formats != null) {
|
72
|
StringTokenizer st = new StringTokenizer(formats,",",false);
|
73
|
Vector<String> v = new Vector<String>();
|
74
|
while (st.hasMoreTokens()) {
|
75
|
v.add(st.nextToken());
|
76
|
}
|
77
|
acceptedFormats = new String[v.size()];
|
78
|
v.toArray(acceptedFormats);
|
79
|
}
|
80
|
|
81
|
if (acceptedFormats != null) {
|
82
|
boolean found = false;
|
83
|
for (int i=0;i<acceptedFormats.length;i++) {
|
84
|
if (acceptedFormats[i].equals(MetadataResponse.RDF_FORMAT )) {
|
85
|
found = true;
|
86
|
}
|
87
|
break;
|
88
|
}
|
89
|
if (!found) {
|
90
|
throw new LSIDServerException(LSIDServerException.NO_METADATA_AVAILABLE_FOR_FORMATS,"No metadata found for given format");
|
91
|
}
|
92
|
}
|
93
|
|
94
|
IIdentifiableEntity identifiableEntity = lsidMetadataService.getMetadata(lsid);
|
95
|
ModelAndView modelAndView = new ModelAndView("Metadata.rdf");
|
96
|
modelAndView.addObject(identifiableEntity);
|
97
|
return modelAndView;
|
98
|
}
|
99
|
|
100
|
@RequestMapping(value = "/authority/metadata.do", params = "!lsid", method = RequestMethod.GET)
|
101
|
public ModelAndView getMetadata() throws LSIDException {
|
102
|
throw new LSIDException(LSIDException.INVALID_METHOD_CALL, "Must specify HTTP Parameter 'lsid'");
|
103
|
}
|
104
|
|
105
|
}
|