Project

General

Profile

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

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

    
12
import java.io.IOException;
13
import java.util.Arrays;
14
import java.util.List;
15
import java.util.UUID;
16

    
17
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletResponse;
19

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

    
28
import eu.etaxonomy.cdm.api.service.IReferenceService;
29
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
30
import eu.etaxonomy.cdm.model.reference.Reference;
31
import io.swagger.annotations.Api;
32

    
33
/**
34
 * TODO write controller documentation
35
 *
36
 * @author a.kohlbecker
37
 * @since 24.03.2009
38
 */
39

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

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

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

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

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

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

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

    
116
}
(50-50/75)