cleanup
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / NameController.java
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.TaxonName;
31 import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
32 import io.swagger.annotations.Api;
33
34 /**
35 * TODO write controller documentation
36 *
37 * @author a.kohlbecker
38 * @date 24.03.2009
39 */
40
41 @Controller
42 @Api("name")
43 @RequestMapping(value = {"/name/{uuid}"})
44 public class NameController extends AbstractIdentifiableController<TaxonName, INameService>{
45
46 private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{
47 "typeStatus.representations",
48 "typifiedNames",
49 "typeSpecimen",
50 "typeName",
51 "citation",
52 "citation.authorship.$",
53 });
54
55 private static final List<String> NAME_CACHE_INIT_STRATEGY = Arrays.asList(new String []{
56
57 });
58
59 public NameController(){
60 super();
61 setInitializationStrategy(Arrays.asList(new String[]{"$"})); //TODO still needed????
62 }
63
64 @Autowired
65 @Override
66 public void setService(INameService service) {
67 this.service = service;
68 }
69
70
71 /**
72 * Get the list of {@link TypeDesignationBase}s of the
73 * {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
74 * <p>
75 * URI: <b>&#x002F;{datasource-name}&#x002F;name&#x002F;{name-uuid}&#x002F;typeDesignations</b>
76 *
77 * @param request
78 * @param response
79 * @return a List of {@link TypeDesignationBase} entities which are initialized
80 * using the {@link #TYPEDESIGNATION_INIT_STRATEGY}
81 * @throws IOException
82 *
83 * TODO obsolete method?
84 */
85 @RequestMapping(value = { "typeDesignations" }, method = RequestMethod.GET)
86 public List<TypeDesignationBase> doGetNameTypeDesignations(
87 @PathVariable("uuid") UUID uuid, HttpServletRequest request,
88 HttpServletResponse response) throws IOException {
89
90 if (request != null) {
91 logger.info("doGetTypeDesignations()" + request.getRequestURI());
92 }
93 TaxonName tnb = getCdmBaseInstance(uuid, response,
94 (List<String>) null);
95 Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb, null,
96 null, null, TYPEDESIGNATION_INIT_STRATEGY);
97 return p.getRecords();
98 }
99
100 @RequestMapping(
101 value = {"nameCache"},
102 method = RequestMethod.GET)
103 public List<String> doGetNameCache(@PathVariable("uuid") UUID uuid,
104 HttpServletRequest request, HttpServletResponse response)throws IOException {
105
106 logger.info("doGetNameCache()" + request.getRequestURI());
107 TaxonName tnb = getCdmBaseInstance(uuid, response, NAME_CACHE_INIT_STRATEGY);
108 String nameCacheString = tnb.getNameCache();
109 List<String> result = new ArrayList<>();
110 result.add(nameCacheString);
111 return result;
112
113 }
114
115 @RequestMapping(value = "taggedName", method = RequestMethod.GET)
116 public ModelAndView doGetTaggedName(
117 @PathVariable("uuid") UUID uuid,
118 HttpServletRequest request,
119 HttpServletResponse response) throws IOException {
120 logger.info("doGetDescriptionElementsByType() - " + request.getRequestURI());
121
122 ModelAndView mv = new ModelAndView();
123 mv.addObject(service.getTaggedName(uuid));
124 return mv;
125 }
126
127
128 }