Project

General

Profile

Download (4.14 KB) Statistics
| Branch: | Tag: | Revision:
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 java.util.StringTokenizer;
15
import java.util.Vector;
16

    
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.stereotype.Controller;
19
import org.springframework.web.bind.WebDataBinder;
20
import org.springframework.web.bind.annotation.InitBinder;
21
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestMethod;
23
import org.springframework.web.bind.annotation.RequestParam;
24
import org.springframework.web.servlet.ModelAndView;
25

    
26
import com.ibm.lsid.LSIDException;
27
import com.ibm.lsid.MetadataResponse;
28
import com.ibm.lsid.server.LSIDServerException;
29

    
30
import eu.etaxonomy.cdm.api.service.lsid.LSIDMetadataService;
31
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
32
import eu.etaxonomy.cdm.model.common.LSID;
33
import eu.etaxonomy.cdm.remote.editor.LSIDPropertyEditor;
34

    
35
/**
36
 * Controller which accepts requests for the metadata representation of an object
37
 * with a given lsid.
38
 *
39
 * @author ben
40
 * @author Ben Szekely (<a href="mailto:bhszekel@us.ibm.com">bhszekel@us.ibm.com</a>)
41
 * @see com.ibm.lsid.server.servlet.MetadataServlet
42
 */
43
@Controller
44
@Api(value="lsid_authority_metadata",
45
description="Controller which accepts incoming requests to the LSIDMetadataService.")
46
public class MetadataController {
47

    
48
    private LSIDMetadataService lsidMetadataService;
49

    
50
    @Autowired
51
    public void setLsidMetadataService(LSIDMetadataService lsidMetadataService) {
52
        this.lsidMetadataService = lsidMetadataService;
53
    }
54

    
55
    @InitBinder
56
    public void initBinder(WebDataBinder binder) {
57
        binder.registerCustomEditor(LSID.class, new LSIDPropertyEditor());
58
    }
59

    
60
    /**
61
     * Handle requests for the metadata representation of an object with a given lsid. Will return metadata in any format supported
62
     * from a list of formats if specified.
63
     *
64
     * @param lsid the lsid to get metadata for
65
     * @param formats a comma separated list of acceptable formats to the client
66
     * @return ModelAndView containing the metadata response as an object with key 'metadataResponse', view name 'Metadata.rdf'
67
     * @throws LSIDServerException
68
     */
69
    @RequestMapping(value = "/authority/metadata.do", params = "lsid", method = RequestMethod.GET)
70
    public ModelAndView getMetadata(@RequestParam("lsid") LSID lsid,
71
                                    @RequestParam(value = "acceptedFormats", required = false) String formats) throws LSIDServerException  {
72
        String[] acceptedFormats = null;
73
        if (formats != null) {
74
            StringTokenizer st = new StringTokenizer(formats,",",false);
75
            Vector<String> v = new Vector<String>();
76
            while (st.hasMoreTokens()) {
77
                v.add(st.nextToken());
78
            }
79
            acceptedFormats = new String[v.size()];
80
            v.toArray(acceptedFormats);
81
        }
82

    
83
        if (acceptedFormats != null) {
84
            boolean found = false;
85
            for (int i=0;i<acceptedFormats.length;i++) {
86
                    if (acceptedFormats[i].equals(MetadataResponse.RDF_FORMAT )) {
87
                        found = true;
88
                    }
89
                    break;
90
            }
91
            if (!found) {
92
                    throw new LSIDServerException(LSIDServerException.NO_METADATA_AVAILABLE_FOR_FORMATS,"No metadata found for given format");
93
            }
94
        }
95

    
96
        IIdentifiableEntity identifiableEntity = lsidMetadataService.getMetadata(lsid);
97
        ModelAndView modelAndView = new ModelAndView("Metadata.rdf");
98
        modelAndView.addObject(identifiableEntity);
99
        return modelAndView;
100
    }
101

    
102
    @RequestMapping(value = "/authority/metadata.do", params = "!lsid", method = RequestMethod.GET)
103
    public ModelAndView getMetadata() throws LSIDException {
104
        throw new LSIDException(LSIDException.INVALID_METHOD_CALL, "Must specify HTTP Parameter 'lsid'");
105
    }
106

    
107
}
(4-4/5)