a little bit documentation
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / NameController.java
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 java.io.IOException;
14 import java.util.ArrayList;
15 import java.util.Arrays;
16 import java.util.List;
17 import java.util.UUID;
18
19 import javax.servlet.http.HttpServletRequest;
20 import javax.servlet.http.HttpServletResponse;
21
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.stereotype.Controller;
24 import org.springframework.web.bind.annotation.PathVariable;
25 import org.springframework.web.bind.annotation.RequestMapping;
26 import org.springframework.web.bind.annotation.RequestMethod;
27 import org.springframework.web.servlet.ModelAndView;
28
29 import eu.etaxonomy.cdm.api.service.INameService;
30 import eu.etaxonomy.cdm.api.service.pager.Pager;
31 import eu.etaxonomy.cdm.model.name.NonViralName;
32 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
33 import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
34
35 /**
36 * TODO write controller documentation
37 *
38 * @author a.kohlbecker
39 * @date 24.03.2009
40 */
41
42 @Controller
43 @RequestMapping(value = {"/name/{uuid}"})
44 public class NameController extends BaseController<TaxonNameBase, INameService>
45 {
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.authorTeam.$",
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 /* (non-Javadoc)
66 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
67 */
68 @Autowired
69 @Override
70 public void setService(INameService service) {
71 this.service = service;
72 }
73
74
75 /**
76 * Get the list of {@link TypeDesignationBase}s of the
77 * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
78 * <p>
79 * URI: <b>&#x002F;{datasource-name}&#x002F;name&#x002F;{name-uuid}&#x002F;typeDesignations</b>
80 *
81 * @param request
82 * @param response
83 * @return a List of {@link TypeDesignationBase} entities which are initialized
84 * using the {@link #TYPEDESIGNATION_INIT_STRATEGY}
85 * @throws IOException
86 *
87 * TODO obsolete method?
88 */
89 @RequestMapping(value = { "typeDesignations" }, method = RequestMethod.GET)
90 public List<TypeDesignationBase> doGetNameTypeDesignations(
91 @PathVariable("uuid") UUID uuid, HttpServletRequest request,
92 HttpServletResponse response) throws IOException {
93
94 logger.info("doGetTypeDesignations()" + request.getServletPath());
95 TaxonNameBase tnb = getCdmBaseInstance(uuid, response,
96 (List<String>) null);
97 Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb, null,
98 null, null, TYPEDESIGNATION_INIT_STRATEGY);
99 return p.getRecords();
100 }
101
102 @RequestMapping(
103 value = {"nameCache"},
104 method = RequestMethod.GET)
105 public List<String> doGetNameCache(@PathVariable("uuid") UUID uuid,
106 HttpServletRequest request, HttpServletResponse response)throws IOException {
107
108 logger.info("doGetNameCache()" + request.getServletPath());
109 TaxonNameBase tnb = getCdmBaseInstance(uuid, response, NAME_CACHE_INIT_STRATEGY);
110 NonViralName nvn = (NonViralName) tnb;
111 String nameCacheString = nvn.getNameCache();
112 List result = new ArrayList<String>();
113 result.add(nameCacheString);
114 return result;
115
116 }
117
118 @RequestMapping(value = "taggedName", method = RequestMethod.GET)
119 public ModelAndView doGetTaggedName(
120 @PathVariable("uuid") UUID uuid,
121 HttpServletRequest request,
122 HttpServletResponse response) throws IOException {
123 logger.info("doGetDescriptionElementsByType() - " + request.getServletPath());
124
125 ModelAndView mv = new ModelAndView();
126 mv.addObject(service.getTaggedName(uuid));
127 return mv;
128 }
129
130
131 }