Project

General

Profile

Download (6.78 KB) Statistics
| Branch: | Tag: | Revision:
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 io.swagger.annotations.Api;
12

    
13
import org.apache.commons.logging.Log;
14
import org.apache.commons.logging.LogFactory;
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.stereotype.Controller;
17
import org.springframework.web.bind.WebDataBinder;
18
import org.springframework.web.bind.annotation.InitBinder;
19
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestMethod;
21
import org.springframework.web.bind.annotation.RequestParam;
22
import org.springframework.web.servlet.ModelAndView;
23

    
24
import com.ibm.lsid.ExpiringResponse;
25
import com.ibm.lsid.LSIDException;
26
import com.ibm.lsid.server.LSIDServerException;
27

    
28
import eu.etaxonomy.cdm.api.service.lsid.LSIDAuthorityService;
29
import eu.etaxonomy.cdm.model.common.LSID;
30
import eu.etaxonomy.cdm.model.common.LSIDAuthority;
31
import eu.etaxonomy.cdm.remote.editor.LSIDAuthorityPropertyEditor;
32
import eu.etaxonomy.cdm.remote.editor.LSIDPropertyEditor;
33

    
34
/**
35
 * Controller which accepts incoming requests to the LSIDAuthorityService
36
 * This controller has three methods. Using ControllerClassNameHandlerMapping means that
37
 * any requests to /authority/ get handled by this controller.
38
 *
39
 * To allow the Spring DispatcherServlet to handle /authority/, /authority/notify/ and
40
 * /authority/revoke/ directly, you need to add the following mappings to your web.xml
41
 *
42
 * <servlet-mapping>
43
 *   <servlet-name>${servlet.name}</servlet-name>
44
 *   <url-pattern>/authority/</url-pattern>
45
 * </servlet-mapping>
46
 * <servlet-mapping>
47
 *   <servlet-name>${servlet.name}</servlet-name>
48
 *   <url-pattern>/authority/revoke/</url-pattern>
49
 * </servlet-mapping>
50
 * <servlet-mapping>
51
 *   <servlet-name>${servlet.name}</servlet-name>
52
 *   <url-pattern>/authority/notify/</url-pattern>
53
 * </servlet-mapping>
54
 *
55
 * You also need to use some kind of MethodNameResolver - AuthorityMethodNameResolver
56
 * maps the request to the correct method using the request URL.
57
 *
58
 * @author ben
59
 * @author Ben Szekely (<a href="mailto:bhszekel@us.ibm.com">bhszekel@us.ibm.com</a>)
60
 * @see org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping
61
 * @see org.cateproject.controller.interceptor.lsid.AuthorityMethodNameResolver
62
 * @see com.ibm.lsid.server.servlet.AuthorityServlet
63
 */
64
@Controller
65
@Api(value="lsid_authority",
66
    description="Controller which accepts incoming requests to the LSIDAuthorityService.")
67
public class AuthorityController {
68
    private static Log log = LogFactory.getLog(AuthorityController.class);
69
    private LSIDAuthorityService lsidAuthorityService;
70

    
71
    @Autowired
72
    public void setLsidAuthorityService(LSIDAuthorityService lsidAuthorityService) {
73
        this.lsidAuthorityService = lsidAuthorityService;
74
    }
75

    
76
    @InitBinder
77
    public void initBinder(WebDataBinder binder) {
78
        binder.registerCustomEditor(LSID.class, new LSIDPropertyEditor());
79
        binder.registerCustomEditor(LSIDAuthority.class, new LSIDAuthorityPropertyEditor());
80
    }
81

    
82
    /**
83
     * Get the available services of this LSIDAuthority as a wsdl document
84
     *
85
     * @return ModelAndView containing the WSDL as a javax.xml.transform.Source, view name 'Authority.wsdl'
86
     * @throws LSIDServerException
87
     * @see javax.xml.transform.Source
88
     */
89
    @RequestMapping(value="/authority/",params="!lsid", method = RequestMethod.GET) // mapped as absolute path, see CdmAntPathMatcher
90
    public ModelAndView getAvailableServices() throws LSIDServerException {
91
        ExpiringResponse expiringResponse = lsidAuthorityService.getAuthorityWSDL();
92
        return new ModelAndView("Authority.wsdl","source",expiringResponse.getValue());
93
    }
94

    
95
    /**
96
     * Get the available services for a given lsid
97
     *
98
     * @return ModelAndView containing the WSDL as a javax.xml.transform.Source, view name 'Services.wsdl'
99
     * @param LSID the lsid to query the service with
100
     * @throws LSIDServerException
101
     * @see javax.xml.transform.Source
102
     */
103
    @RequestMapping(value="/authority/",params="lsid", method = RequestMethod.GET)
104
    public ModelAndView getAvailableServices(@RequestParam("lsid")LSID lsid) throws LSIDServerException {
105
        ExpiringResponse expiringResponse = lsidAuthorityService.getAvailableServices(lsid);
106
        return new ModelAndView("Services.wsdl","source",expiringResponse.getValue());
107
    }
108

    
109
    /**
110
     * Notify the authority that another authority resolves the object with the given identifier
111
     *
112
     * @param lsid the LSID to notify the authority about
113
     * @param authorityName the foreign authority
114
     * @return ModelAndView (null)
115
     * @throws LSIDServerException
116
     */
117
    @RequestMapping(value="/authority/notify/",params={"lsid","authorityName"}, method = RequestMethod.GET)
118
    public ModelAndView notifyForeignAuthority(@RequestParam("lsid")LSID lsid,
119
                                               @RequestParam("authorityName")LSIDAuthority lsidAuthority) throws LSIDServerException {
120
        lsidAuthorityService.notifyForeignAuthority(lsid,lsidAuthority);
121
        return null;
122
    }
123

    
124
    /**
125
     * Maps to the notify path without the required params
126
     *
127
     * @throws LSIDServerException
128
     */
129
    @RequestMapping(value="/authority/notify/", method = RequestMethod.GET)
130
    public ModelAndView notifyForeignAuthority() throws LSIDException {
131
        throw new LSIDException(LSIDException.INVALID_METHOD_CALL, "You must supply an lsid and an lsidAuthority");
132
    }
133

    
134
    /**
135
     * Notify the authority that another authority no longer resolves the object with the given identifier
136
     *
137
     * @param lsid the LSID to notify the authority about
138
     * @param authorityName the foreign authority
139
     * @return ModelAndView (null)
140
     * @throws LSIDServerException
141
     */
142
    @RequestMapping(value="/authority/revoke/",params={"lsid","authorityName"}, method = RequestMethod.GET)
143
    public ModelAndView revokeNotificationForeignAuthority(@RequestParam("lsid")LSID lsid,
144
                                                           @RequestParam("authorityName")LSIDAuthority lsidAuthority) throws LSIDServerException {
145
        lsidAuthorityService.revokeNotificationForeignAuthority(lsid,lsidAuthority);
146
        return null;
147
    }
148

    
149
    /**
150
     * Maps to the revoke path without the required params
151
     *
152
     * @throws LSIDServerException
153
     */
154
    @RequestMapping(value="/authority/revoke/", method = RequestMethod.GET)
155
    public ModelAndView revokeNotificationForeignAuthority() throws LSIDException {
156
        throw new LSIDException(LSIDException.INVALID_METHOD_CALL, "You must supply an lsid and an lsidAuthority");
157
    }
158
}
(1-1/6)