2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.remote
.controller
;
12 import java
.io
.IOException
;
13 import java
.util
.Arrays
;
14 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import javax
.servlet
.http
.HttpServletRequest
;
18 import javax
.servlet
.http
.HttpServletResponse
;
20 import org
.apache
.log4j
.Logger
;
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
;
27 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
28 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
29 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
30 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
32 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
34 import eu
.etaxonomy
.cdm
.persistence
.dao
.initializer
.EntityInitStrategy
;
35 import io
.swagger
.annotations
.Api
;
38 * The NamePortalController class is a Spring MVC Controller.
40 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
41 * The available {datasource-name}s are defined in a configuration file which
42 * is loaded by the {@link UpdatableRoutingDataSource}. If the
43 * UpdatableRoutingDataSource is not being used in the actual application
44 * context any arbitrary {datasource-name} may be used.
46 * Methods mapped at type level, inherited from super classes ({@link BaseController}):
48 * URI: <b>/{datasource-name}/portal/name/{name-uuid}</b>
50 * Get the {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
51 * The returned TaxonName is initialized by
52 * the following strategy: -- NONE --
55 * @author a.kohlbecker
61 @RequestMapping(value
= {"/portal/name/{uuid}"})
62 public class NamePortalController
extends BaseController
<TaxonName
, INameService
> {
64 private static final Logger logger
= Logger
.getLogger(NamePortalController
.class);
66 private static final List
<String
> TYPEDESIGNATION_INIT_STRATEGY
= TypeDesignationPortalController
.DEFAULT_INIT_STRATEGY
;
69 private static final List
<String
> NAMEDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
71 "elements.multilanguageText",
76 protected <CDM_BASE
extends CdmBase
> List
<String
> complementInitStrategy(Class
<CDM_BASE
> clazz
,
77 List
<String
> pathProperties
) {
79 if(pathProperties
== null){
80 return pathProperties
;
83 EntityInitStrategy initStrategy
= new EntityInitStrategy(pathProperties
);
85 if(pathProperties
.contains("nameRelations")){
86 // nameRelations is a transient property!
87 initStrategy
.getPropertyPaths().remove("nameRelations");
88 initStrategy
.extend("relationsFromThisName", TaxonPortalController
.NAMERELATIONSHIP_INIT_STRATEGY
, true);
89 initStrategy
.extend("relationsToThisName", TaxonPortalController
.NAMERELATIONSHIP_INIT_STRATEGY
, true);
91 if(pathProperties
.contains("relationsFromThisName")){
92 initStrategy
.getPropertyPaths().remove("relationsFromThisName");
93 initStrategy
.extend("relationsFromThisName", TaxonPortalController
.NAMERELATIONSHIP_INIT_STRATEGY
, true);
95 if(pathProperties
.contains("relationsToThisName")){
96 initStrategy
.getPropertyPaths().remove("relationsToThisName");
97 initStrategy
.extend("relationsToThisName", TaxonPortalController
.NAMERELATIONSHIP_INIT_STRATEGY
, true);
101 return initStrategy
.getPropertyPaths();
105 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
109 public void setService(INameService service
) {
110 this.service
= service
;
114 private IDescriptionService descriptionService
;
117 * Get the list of {@link TypeDesignationBase}s of the
118 * {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
120 * URI: <b>/{datasource-name}/portal/name/{name-uuid}/typeDesignations</b>
124 * @return a List of {@link TypeDesignationBase} entities which are initialized
125 * using the following initialization strategy:
126 * {@link #TYPEDESIGNATION_INIT_STRATEGY}
127 * @throws IOException
130 value
= {"typeDesignations"},
131 method
= RequestMethod
.GET
)
132 public List
<TypeDesignationBase
> doGetTypeDesignations(@PathVariable("uuid") UUID uuid
,
133 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
134 TaxonName tnb
= getCdmBaseInstance(uuid
, response
, (List
<String
>)null);
135 Pager
<TypeDesignationBase
> p
= service
.getTypeDesignations(tnb
, null, null, null, TYPEDESIGNATION_INIT_STRATEGY
);
136 return p
.getRecords();
140 * Get the list of {@link TypeDesignationBase}s associated to any name in the same homotypical group to which
141 * the {@link TaxonName} identified by the <code>{name-uuid}</code> belongs.
143 * URI: <b>/{datasource-name}/name/{name-uuid}/typeDesignations</b>
147 * @return a List of {@link TypeDesignationBase} entities which are initialized
148 * using the {@link #TYPEDESIGNATION_INIT_STRATEGY}
149 * @throws IOException
151 @RequestMapping(value
= { "typeDesignationsInHomotypicalGroup" }, method
= RequestMethod
.GET
)
152 public List
<TypeDesignationBase
> doGetTypeDesignationsInHomotypicalGroup(
153 @PathVariable("uuid") UUID uuid
, HttpServletRequest request
,
154 HttpServletResponse response
) throws IOException
{
156 if (request
!= null) {
157 logger
.info("doGetTypeDesignationsInHomotypicalGroup()" + requestPathAndQuery(request
));
159 List
<TypeDesignationBase
> result
= service
.getTypeDesignationsInHomotypicalGroup(uuid
,
160 null, null, TYPEDESIGNATION_INIT_STRATEGY
);
165 * Get the list of {@link TaxonNameDescription}s of the Name associated with the
166 * {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
168 * URI: <b>/{datasource-name}/portal/name/{name-uuid}/descriptions</b>
172 * @return a List of {@link TaxonNameDescription} entities which are initialized
173 * using the following initialization strategy:
174 * {@link #NAMEDESCRIPTION_INIT_STRATEGY}
175 * @throws IOException
178 value
= {"taxonNameDescriptions"},
179 method
= RequestMethod
.GET
)
180 public List
<TaxonNameDescription
> doGetNameDescriptions(@PathVariable("uuid") UUID uuid
,
181 HttpServletRequest request
, HttpServletResponse response
)throws IOException
{
182 logger
.info("doGetNameDescriptions()" + request
.getRequestURI());
183 TaxonName tnb
= service
.load(uuid
, null);
184 Pager
<TaxonNameDescription
> p
= descriptionService
.getTaxonNameDescriptions(tnb
, null, null, NAMEDESCRIPTION_INIT_STRATEGY
);
185 return p
.getRecords();