Project

General

Profile

Download (4.45 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.ArrayList;
14
import java.util.Arrays;
15
import java.util.List;
16
import java.util.UUID;
17

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

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

    
28
import eu.etaxonomy.cdm.api.service.INameService;
29
import eu.etaxonomy.cdm.api.service.pager.Pager;
30
import eu.etaxonomy.cdm.model.name.NonViralName;
31
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
32
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
33
import io.swagger.annotations.Api;
34

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

    
42
@Controller
43
@Api("name")
44
@RequestMapping(value = {"/name/{uuid}"})
45
public class NameController extends AbstractIdentifiableController<TaxonNameBase, INameService>{
46

    
47
    private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{
48
            "typeStatus.representations",
49
            "typifiedNames",
50
            "typeSpecimen",
51
            "typeName",
52
            "citation",
53
            "citation.authorship.$",
54
    });
55

    
56
    private static final List<String> NAME_CACHE_INIT_STRATEGY = Arrays.asList(new String []{
57

    
58
    });
59

    
60
    public NameController(){
61
        super();
62
        setInitializationStrategy(Arrays.asList(new String[]{"$"})); //TODO still needed????
63
    }
64

    
65
    @Autowired
66
    @Override
67
    public void setService(INameService service) {
68
        this.service = service;
69
    }
70

    
71

    
72
    /**
73
     * Get the list of {@link TypeDesignationBase}s of the
74
     * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
75
     * <p>
76
     * URI: <b>&#x002F;{datasource-name}&#x002F;name&#x002F;{name-uuid}&#x002F;typeDesignations</b>
77
     *
78
     * @param request
79
     * @param response
80
     * @return a List of {@link TypeDesignationBase} entities which are initialized
81
     *         using the {@link #TYPEDESIGNATION_INIT_STRATEGY}
82
     * @throws IOException
83
     *
84
     * TODO obsolete method?
85
     */
86
    @RequestMapping(value = { "typeDesignations" }, method = RequestMethod.GET)
87
    public List<TypeDesignationBase> doGetNameTypeDesignations(
88
            @PathVariable("uuid") UUID uuid, HttpServletRequest request,
89
            HttpServletResponse response) throws IOException {
90

    
91
        if (request != null) {
92
            logger.info("doGetTypeDesignations()" + request.getRequestURI());
93
        }
94
        TaxonNameBase<?,?> tnb = getCdmBaseInstance(uuid, response,
95
                (List<String>) null);
96
        Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb, null,
97
                null, null, TYPEDESIGNATION_INIT_STRATEGY);
98
        return p.getRecords();
99
    }
100

    
101
    @RequestMapping(
102
            value = {"nameCache"},
103
            method = RequestMethod.GET)
104
    public List<String> doGetNameCache(@PathVariable("uuid") UUID uuid,
105
            HttpServletRequest request, HttpServletResponse response)throws IOException {
106

    
107
        logger.info("doGetNameCache()" + request.getRequestURI());
108
        TaxonNameBase<?,?> tnb = getCdmBaseInstance(uuid, response, NAME_CACHE_INIT_STRATEGY);
109
        NonViralName<?> nvn = (NonViralName<?>) tnb;
110
        String nameCacheString = nvn.getNameCache();
111
        List<String> result = new ArrayList<>();
112
        result.add(nameCacheString);
113
        return result;
114

    
115
    }
116

    
117
    @RequestMapping(value = "taggedName", method = RequestMethod.GET)
118
    public ModelAndView doGetTaggedName(
119
            @PathVariable("uuid") UUID uuid,
120
            HttpServletRequest request,
121
            HttpServletResponse response) throws IOException {
122
        logger.info("doGetDescriptionElementsByType() - " + request.getRequestURI());
123

    
124
        ModelAndView mv = new ModelAndView();
125
        mv.addObject(service.getTaggedName(uuid));
126
        return mv;
127
    }
128

    
129

    
130
}
(38-38/66)