Project

General

Profile

Download (3.84 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

    
11
package eu.etaxonomy.cdm.remote.controller;
12

    
13
import io.swagger.annotations.Api;
14

    
15
import java.io.IOException;
16
import java.util.Arrays;
17
import java.util.List;
18
import java.util.UUID;
19

    
20
import javax.servlet.http.HttpServletRequest;
21
import javax.servlet.http.HttpServletResponse;
22

    
23
import org.springframework.beans.factory.annotation.Autowired;
24
import org.springframework.stereotype.Controller;
25
import org.springframework.web.bind.annotation.PathVariable;
26
import org.springframework.web.bind.annotation.RequestMapping;
27
import org.springframework.web.bind.annotation.RequestMethod;
28
import org.springframework.web.bind.annotation.RequestParam;
29
import org.springframework.web.servlet.ModelAndView;
30

    
31
import eu.etaxonomy.cdm.api.service.IReferenceService;
32
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
33
import eu.etaxonomy.cdm.model.reference.Reference;
34

    
35
/**
36
 * TODO write controller documentation
37
 *
38
 * @author a.kohlbecker
39
 * @date 24.03.2009
40
 */
41

    
42
@Controller
43
@Api("reference")
44
@RequestMapping(value = {"/reference/{uuid}"})
45
public class ReferenceController extends BaseController<Reference, IReferenceService>
46
{
47

    
48
    private static final List<String> NOMENCLATURAL_CITATION_INIT_STRATEGY = Arrays.asList(new String []{
49
            "$",
50
            "authorship",
51
            "inReference.inReference",
52
            "inReference.authorship"
53
    });
54

    
55
    private static final List<String> CITATION_WITH_AUTHORSHIP_INIT_STRATEGY = Arrays.asList(new String []{
56
            "authorship.$"
57
    });
58

    
59
    public ReferenceController(){
60
        setInitializationStrategy(Arrays.asList(new String[]{
61
                "$",
62
                "authorship.$"
63
             }));
64
    }
65

    
66
    /* (non-Javadoc)
67
     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
68
     */
69
    @Autowired
70
    @Override
71
    public void setService(IReferenceService service) {
72
        this.service = service;
73
    }
74

    
75
    /**
76
     * TODO write controller documentation
77
     *
78
     * @param request
79
     * @param response
80
     * @return
81
     * @throws IOException
82
     */
83
    @RequestMapping(
84
        value = {"nomenclaturalCitation"},
85
        method = RequestMethod.GET)
86
    public ModelAndView doGetNomenclaturalCitation(
87
            @PathVariable("uuid") UUID uuid,
88
            HttpServletRequest request,
89
            HttpServletResponse response,
90
            @RequestParam(value = "microReference", required = false) String microReference)throws IOException {
91
        ModelAndView mv = new ModelAndView();
92
        Reference rb = service.load(uuid, NOMENCLATURAL_CITATION_INIT_STRATEGY);
93
        if(INomenclaturalReference.class.isAssignableFrom(rb.getClass())){
94
            String nomRefCit = ((INomenclaturalReference)rb).getNomenclaturalCitation(microReference);
95
            mv.addObject(nomRefCit);
96
            return mv;
97
        } else {
98
            response.sendError(400, "The supplied reference-uuid must specify a INomenclaturalReference.");
99
        }
100
        return mv;
101
    }
102

    
103
    @RequestMapping(
104
            value = {"authorship"},
105
            method = RequestMethod.GET)
106
        public ModelAndView doGetAuthorship(
107
                @PathVariable("uuid") UUID uuid,
108
                HttpServletRequest request,
109
                HttpServletResponse response) {
110
        ModelAndView mv = new ModelAndView();
111
        Reference rb = service.load(uuid, CITATION_WITH_AUTHORSHIP_INIT_STRATEGY);
112
        if(rb.getAuthorship() != null){
113
            mv.addObject(rb.getAuthorship());
114
        }
115
        return mv;
116
    }
117

    
118
}
(50-50/63)