AT: committing Palm extension changes to the CDM Libraries
[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 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
35
36 /**
37 * TODO write controller documentation
38 *
39 * @author a.kohlbecker
40 * @date 24.03.2009
41 */
42
43 @Controller
44 @RequestMapping(value = {"/name/{uuid}"})
45 public class NameController extends BaseController<TaxonNameBase, INameService>
46 {
47
48 private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{
49 "typeStatus.representations",
50 "typifiedNames",
51 "typeSpecimen",
52 "typeName",
53 "citation",
54 "citation.authorTeam.$",
55 });
56
57 private static final List<String> NAME_CACHE_INIT_STRATEGY = Arrays.asList(new String []{
58
59 });
60
61 public NameController(){
62 super();
63 setInitializationStrategy(Arrays.asList(new String[]{"$"})); //TODO still needed????
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(INameService service) {
72 this.service = service;
73 }
74
75
76 /**
77 * Get the list of {@link TypeDesignationBase}s of the
78 * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
79 * <p>
80 * URI: <b>&#x002F;{datasource-name}&#x002F;name&#x002F;{name-uuid}&#x002F;typeDesignations</b>
81 *
82 * @param request
83 * @param response
84 * @return a List of {@link TypeDesignationBase} entities which are initialized
85 * using the {@link #TYPEDESIGNATION_INIT_STRATEGY}
86 * @throws IOException
87 *///TODO obsolete method?
88 @RequestMapping(value = { "typeDesignations" }, method = RequestMethod.GET)
89 public List<TypeDesignationBase> doGetNameTypeDesignations(
90 @PathVariable("uuid") UUID uuid, HttpServletRequest request,
91 HttpServletResponse response) throws IOException {
92
93 logger.info("doGetTypeDesignations()" + request.getServletPath());
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
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 }