3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.remote
.controller
;
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
;
19 import javax
.servlet
.http
.HttpServletRequest
;
20 import javax
.servlet
.http
.HttpServletResponse
;
22 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
23 import org
.springframework
.stereotype
.Controller
;
24 import org
.springframework
.web
.bind
.WebDataBinder
;
25 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
26 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
27 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
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
.Rank
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
34 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
36 import eu
.etaxonomy
.cdm
.remote
.dto
.tdwg
.voc
.TaxonName
;
37 import eu
.etaxonomy
.cdm
.remote
.editor
.RankPropertyEditor
;
38 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDPropertyEditor
;
41 * TODO write controller documentation
43 * @author a.kohlbecker
48 @RequestMapping(value
= {"/name/*", "/name/{uuid}"})
49 public class NameController
extends AnnotatableController
<TaxonNameBase
, INameService
>
52 private static final List
<String
> TYPEDESIGNATION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
54 "citation.authorTeam",
55 "typifiedNames.taggedName"
58 private static final List
<String
> NAME_CACHE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
62 public NameController(){
64 setUuidParameterPattern("^/name/([^/?#&\\.]+).*");
65 setInitializationStrategy(Arrays
.asList(new String
[]{"$"}));
69 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
73 public void setService(INameService service
) {
74 this.service
= service
;
78 public void initBinder(WebDataBinder binder
) {
79 binder
.registerCustomEditor(UUID
.class, new UUIDPropertyEditor());
83 * Get the list of {@link TypeDesignationBase}s of the
84 * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
86 * URI: <b>/{datasource-name}/name/{name-uuid}/typeDesignations</b>
90 * @return a List of {@link TypeDesignationBase} entities which are initialized
91 * using the {@link #TYPEDESIGNATION_INIT_STRATEGY}
95 value
= {"*/typeDesignations"},
96 method
= RequestMethod
.GET
)
97 public List
<TypeDesignationBase
> doGetNameDesignations(HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
98 TaxonNameBase tnb
= getCdmBase(request
, response
, null, TaxonNameBase
.class);
99 Pager
<TypeDesignationBase
> p
= service
.getTypeDesignations(tnb
, null, null, null, TYPEDESIGNATION_INIT_STRATEGY
);
100 return p
.getRecords();
104 value
= {"*/nameCache"},
105 method
= RequestMethod
.GET
)
106 public List
<String
> doGetNameCache(HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
107 TaxonNameBase tnb
= getCdmBase(request
, response
, NAME_CACHE_INIT_STRATEGY
, TaxonNameBase
.class);
108 NonViralName nvn
= (NonViralName
) tnb
;
109 String nameCacheString
= nvn
.getNameCache();
110 List result
= new ArrayList
<String
>();
111 result
.add(nameCacheString
);