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
.Arrays
;
15 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import javax
.servlet
.http
.HttpServletRequest
;
19 import javax
.servlet
.http
.HttpServletResponse
;
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
;
28 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
29 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
31 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
32 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
36 * The NamePortalController class is a Spring MVC Controller.
38 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
39 * The available {datasource-name}s are defined in a configuration file which
40 * is loaded by the {@link UpdatableRoutingDataSource}. If the
41 * UpdatableRoutingDataSource is not being used in the actual application
42 * context any arbitrary {datasource-name} may be used.
44 * Methods mapped at type level, inherited from super classes ({@link BaseController}):
46 * URI: <b>/{datasource-name}/portal/name/{name-uuid}</b>
48 * Get the {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
49 * The returned TaxonNameBase is initialized by
50 * the following strategy: -- NONE --
53 * @author a.kohlbecker
58 @RequestMapping(value
= {"/portal/name/{uuid}"})
59 public class NamePortalController
extends BaseController
<TaxonNameBase
, INameService
>
62 private static final List
<String
> TYPEDESIGNATION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
65 "typeStatus.representations",
67 "citation.authorTeam.$",
68 "typeSpecimen.media.representations.parts"
72 private static final List
<String
> NAMEDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
76 "elements.multilanguageText",
77 "elements.media.representations.parts",
78 "elements.media.title",
82 public NamePortalController(){
84 setInitializationStrategy(Arrays
.asList(new String
[]{"$"})); //TODO required???
88 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
92 public void setService(INameService service
) {
93 this.service
= service
;
97 private IDescriptionService descriptionService
;
100 * Get the list of {@link TypeDesignationBase}s of the
101 * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
103 * URI: <b>/{datasource-name}/portal/name/{name-uuid}/typeDesignations</b>
107 * @return a List of {@link TypeDesignationBase} entities which are initialized
108 * using the following initialization strategy:
109 * {@link #TYPEDESIGNATION_INIT_STRATEGY}
110 * @throws IOException
112 @SuppressWarnings("unchecked")
114 value
= {"typeDesignations"},
115 method
= RequestMethod
.GET
)
116 public ModelAndView
doGetTypeDesignations(@PathVariable("uuid") UUID uuid
,
117 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
118 ModelAndView mv
= new ModelAndView();
119 TaxonNameBase tnb
= getCdmBaseInstance(uuid
, response
, (List
<String
>)null);
120 Pager
<TypeDesignationBase
> p
= service
.getTypeDesignations(tnb
, null, null, null, TYPEDESIGNATION_INIT_STRATEGY
);
121 mv
.addObject(p
.getRecords());
126 * Get the list of {@link TaxonNameDescription}s of the Name associated with the
127 * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
129 * URI: <b>/{datasource-name}/portal/name/{name-uuid}/descriptions</b>
133 * @return a List of {@link TaxonNameDescription} entities which are initialized
134 * using the following initialization strategy:
135 * {@link #NAMEDESCRIPTION_INIT_STRATEGY}
136 * @throws IOException
139 value
= {"taxonNameDescriptions"},
140 method
= RequestMethod
.GET
)
141 public List
<TaxonNameDescription
> doGetNameDescriptions(@PathVariable("uuid") UUID uuid
,
142 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
143 logger
.info("doGetNameDescriptions()" + request
.getServletPath());
144 TaxonNameBase tnb
= service
.load(uuid
, null);
145 Pager
<TaxonNameDescription
> p
= descriptionService
.getTaxonNameDescriptions(tnb
, null, null, NAMEDESCRIPTION_INIT_STRATEGY
);
146 return p
.getRecords();