1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.remote.service;
|
11
|
|
12
|
import io.swagger.annotations.Api;
|
13
|
|
14
|
import org.apache.commons.logging.Log;
|
15
|
import org.apache.commons.logging.LogFactory;
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
import org.springframework.stereotype.Controller;
|
18
|
import org.springframework.web.bind.WebDataBinder;
|
19
|
import org.springframework.web.bind.annotation.InitBinder;
|
20
|
import org.springframework.web.bind.annotation.RequestMapping;
|
21
|
import org.springframework.web.bind.annotation.RequestMethod;
|
22
|
import org.springframework.web.bind.annotation.RequestParam;
|
23
|
import org.springframework.web.servlet.ModelAndView;
|
24
|
|
25
|
import com.ibm.lsid.ExpiringResponse;
|
26
|
import com.ibm.lsid.LSIDException;
|
27
|
import com.ibm.lsid.server.LSIDServerException;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.service.lsid.LSIDAuthorityService;
|
30
|
import eu.etaxonomy.cdm.model.common.LSID;
|
31
|
import eu.etaxonomy.cdm.model.common.LSIDAuthority;
|
32
|
import eu.etaxonomy.cdm.remote.editor.LSIDAuthorityPropertyEditor;
|
33
|
import eu.etaxonomy.cdm.remote.editor.LSIDPropertyEditor;
|
34
|
|
35
|
/**
|
36
|
* Controller which accepts incoming requests to the LSIDAuthorityService
|
37
|
* This controller has three methods. Using ControllerClassNameHandlerMapping means that
|
38
|
* any requests to /authority/ get handled by this controller.
|
39
|
*
|
40
|
* To allow the Spring DispatcherServlet to handle /authority/, /authority/notify/ and
|
41
|
* /authority/revoke/ directly, you need to add the following mappings to your web.xml
|
42
|
*
|
43
|
* <servlet-mapping>
|
44
|
* <servlet-name>${servlet.name}</servlet-name>
|
45
|
* <url-pattern>/authority/</url-pattern>
|
46
|
* </servlet-mapping>
|
47
|
* <servlet-mapping>
|
48
|
* <servlet-name>${servlet.name}</servlet-name>
|
49
|
* <url-pattern>/authority/revoke/</url-pattern>
|
50
|
* </servlet-mapping>
|
51
|
* <servlet-mapping>
|
52
|
* <servlet-name>${servlet.name}</servlet-name>
|
53
|
* <url-pattern>/authority/notify/</url-pattern>
|
54
|
* </servlet-mapping>
|
55
|
*
|
56
|
* You also need to use some kind of MethodNameResolver - AuthorityMethodNameResolver
|
57
|
* maps the request to the correct method using the request URL.
|
58
|
*
|
59
|
* @author ben
|
60
|
* @author Ben Szekely (<a href="mailto:bhszekel@us.ibm.com">bhszekel@us.ibm.com</a>)
|
61
|
* @see org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping
|
62
|
* @see org.cateproject.controller.interceptor.lsid.AuthorityMethodNameResolver
|
63
|
* @see com.ibm.lsid.server.servlet.AuthorityServlet
|
64
|
*/
|
65
|
@Controller
|
66
|
@Api(value="lsid_authority",
|
67
|
description="Controller which accepts incoming requests to the LSIDAuthorityService.")
|
68
|
public class AuthorityController {
|
69
|
private static Log log = LogFactory.getLog(AuthorityController.class);
|
70
|
private LSIDAuthorityService lsidAuthorityService;
|
71
|
|
72
|
@Autowired
|
73
|
public void setLsidAuthorityService(LSIDAuthorityService lsidAuthorityService) {
|
74
|
this.lsidAuthorityService = lsidAuthorityService;
|
75
|
}
|
76
|
|
77
|
@InitBinder
|
78
|
public void initBinder(WebDataBinder binder) {
|
79
|
binder.registerCustomEditor(LSID.class, new LSIDPropertyEditor());
|
80
|
binder.registerCustomEditor(LSIDAuthority.class, new LSIDAuthorityPropertyEditor());
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* Get the available services of this LSIDAuthority as a wsdl document
|
85
|
*
|
86
|
* @return ModelAndView containing the WSDL as a javax.xml.transform.Source, view name 'Authority.wsdl'
|
87
|
* @throws LSIDServerException
|
88
|
* @see javax.xml.transform.Source
|
89
|
*/
|
90
|
@RequestMapping(value="/authority/",params="!lsid", method = RequestMethod.GET) // mapped as absolute path, see CdmAntPathMatcher
|
91
|
public ModelAndView getAvailableServices() throws LSIDServerException {
|
92
|
ExpiringResponse expiringResponse = lsidAuthorityService.getAuthorityWSDL();
|
93
|
return new ModelAndView("Authority.wsdl","source",expiringResponse.getValue());
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* Get the available services for a given lsid
|
98
|
*
|
99
|
* @return ModelAndView containing the WSDL as a javax.xml.transform.Source, view name 'Services.wsdl'
|
100
|
* @param LSID the lsid to query the service with
|
101
|
* @throws LSIDServerException
|
102
|
* @see javax.xml.transform.Source
|
103
|
*/
|
104
|
@RequestMapping(value="/authority/",params="lsid", method = RequestMethod.GET)
|
105
|
public ModelAndView getAvailableServices(@RequestParam("lsid")LSID lsid) throws LSIDServerException {
|
106
|
ExpiringResponse expiringResponse = lsidAuthorityService.getAvailableServices(lsid);
|
107
|
return new ModelAndView("Services.wsdl","source",expiringResponse.getValue());
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Notify the authority that another authority resolves the object with the given identifier
|
112
|
*
|
113
|
* @param lsid the LSID to notify the authority about
|
114
|
* @param authorityName the foreign authority
|
115
|
* @return ModelAndView (null)
|
116
|
* @throws LSIDServerException
|
117
|
*/
|
118
|
@RequestMapping(value="/authority/notify/",params={"lsid","authorityName"}, method = RequestMethod.GET)
|
119
|
public ModelAndView notifyForeignAuthority(@RequestParam("lsid")LSID lsid,
|
120
|
@RequestParam("authorityName")LSIDAuthority lsidAuthority) throws LSIDServerException {
|
121
|
lsidAuthorityService.notifyForeignAuthority(lsid,lsidAuthority);
|
122
|
return null;
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* Maps to the notify path without the required params
|
127
|
*
|
128
|
* @throws LSIDServerException
|
129
|
*/
|
130
|
@RequestMapping(value="/authority/notify/", method = RequestMethod.GET)
|
131
|
public ModelAndView notifyForeignAuthority() throws LSIDException {
|
132
|
throw new LSIDException(LSIDException.INVALID_METHOD_CALL, "You must supply an lsid and an lsidAuthority");
|
133
|
}
|
134
|
|
135
|
/**
|
136
|
* Notify the authority that another authority no longer resolves the object with the given identifier
|
137
|
*
|
138
|
* @param lsid the LSID to notify the authority about
|
139
|
* @param authorityName the foreign authority
|
140
|
* @return ModelAndView (null)
|
141
|
* @throws LSIDServerException
|
142
|
*/
|
143
|
@RequestMapping(value="/authority/revoke/",params={"lsid","authorityName"}, method = RequestMethod.GET)
|
144
|
public ModelAndView revokeNotificationForeignAuthority(@RequestParam("lsid")LSID lsid,
|
145
|
@RequestParam("authorityName")LSIDAuthority lsidAuthority) throws LSIDServerException {
|
146
|
lsidAuthorityService.revokeNotificationForeignAuthority(lsid,lsidAuthority);
|
147
|
return null;
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* Maps to the revoke path without the required params
|
152
|
*
|
153
|
* @throws LSIDServerException
|
154
|
*/
|
155
|
@RequestMapping(value="/authority/revoke/", method = RequestMethod.GET)
|
156
|
public ModelAndView revokeNotificationForeignAuthority() throws LSIDException {
|
157
|
throw new LSIDException(LSIDException.INVALID_METHOD_CALL, "You must supply an lsid and an lsidAuthority");
|
158
|
}
|
159
|
}
|