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
.ArrayList
;
14 import java
.util
.Arrays
;
15 import java
.util
.Collection
;
16 import java
.util
.HashSet
;
17 import java
.util
.List
;
19 import java
.util
.UUID
;
20 import java
.util
.stream
.Collectors
;
22 import javax
.persistence
.EntityNotFoundException
;
23 import javax
.servlet
.http
.HttpServletRequest
;
24 import javax
.servlet
.http
.HttpServletResponse
;
26 import org
.apache
.log4j
.Logger
;
27 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
28 import org
.springframework
.stereotype
.Controller
;
29 import org
.springframework
.web
.bind
.WebDataBinder
;
30 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
31 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
32 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
33 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
34 import org
.springframework
.web
.servlet
.ModelAndView
;
36 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
37 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
38 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
39 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
40 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
41 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
42 import eu
.etaxonomy
.cdm
.api
.service
.config
.FindOccurrencesConfigurator
;
43 import eu
.etaxonomy
.cdm
.api
.service
.config
.IncludedTaxonConfiguration
;
44 import eu
.etaxonomy
.cdm
.api
.service
.dto
.FieldUnitDTO
;
45 import eu
.etaxonomy
.cdm
.api
.service
.dto
.IncludedTaxaDTO
;
46 import eu
.etaxonomy
.cdm
.api
.service
.dto
.SpecimenOrObservationBaseDTO
;
47 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonRelationshipsDTO
;
48 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
49 import eu
.etaxonomy
.cdm
.exception
.UnpublishedException
;
50 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
51 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
52 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
.Direction
;
53 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
54 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionType
;
55 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
56 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
57 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
58 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
59 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
60 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
61 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
62 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNodeAgentRelation
;
63 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
64 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
65 import eu
.etaxonomy
.cdm
.persistence
.dao
.initializer
.EntityInitStrategy
;
66 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
67 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
68 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
69 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.PagerParameters
;
70 import eu
.etaxonomy
.cdm
.remote
.dto
.common
.StringResultDTO
;
71 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBasePropertyEditor
;
72 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
73 import io
.swagger
.annotations
.Api
;
76 * TODO write controller documentation
78 * @author a.kohlbecker
83 @RequestMapping(value
= {"/taxon/{uuid}"})
84 public class TaxonController
extends AbstractIdentifiableController
<TaxonBase
, ITaxonService
>{
86 public static final Logger logger
= Logger
.getLogger(TaxonController
.class);
89 private IOccurrenceService occurrenceService
;
92 private INameService nameService
;
95 private ITaxonNodeService nodeService
;
98 private IDescriptionService descriptionService
;
101 private ITermService termService
;
103 protected static final EntityInitStrategy TAXONNODE_INIT_STRATEGY
= new EntityInitStrategy(Arrays
.asList(new String
[]{
104 "taxonNodes.classification",
106 "taxonNodes.parent.childNodes", //currently needed to compute sortindex //TODO improve
107 "taxonNodes.taxon.name",
108 "taxonNodes.taxon.secSource.citation",
109 "taxonNodes.statusNote",
110 "acceptedTaxon.taxonNodes.classification"
113 public TaxonController(){
115 setInitializationStrategy(Arrays
.asList(new String
[]{
117 "name.nomenclaturalSource.citation"
124 public void setService(ITaxonService service
) {
125 this.service
= service
;
129 public void initBinder(WebDataBinder binder
) {
130 super.initBinder(binder
);
131 binder
.registerCustomEditor(MarkerType
.class, new TermBasePropertyEditor
<>(termService
));
134 protected List
<String
> getTaxonDescriptionInitStrategy() {
135 return getInitializationStrategy(); // return Arrays.asList("$", "")
138 protected List
<String
> getTaxonDescriptionElementInitStrategy() {
139 return getInitializationStrategy();
142 @RequestMapping(params
="subtree", method
= RequestMethod
.GET
)
143 public TaxonBase
<?
> doGet(@PathVariable("uuid") UUID uuid
,
144 @RequestParam(value
= "subtree", required
= true) UUID subtreeUuid
, //if subtree does not exist the base class method is used, therefore required
145 HttpServletRequest request
,
146 HttpServletResponse response
) throws IOException
{
147 if(request
!= null) {
148 logger
.info("doGet() " + requestPathAndQuery(request
));
150 //TODO do we want to allow Synonyms at all? Maybe needs initialization
151 EntityInitStrategy initStrategy
= new EntityInitStrategy(getInitializationStrategy());
152 initStrategy
.extend(null, getTaxonNodeInitStrategy(), false);
153 TaxonBase
<?
> taxonBase
= getCdmBaseInstance(uuid
, response
, initStrategy
.getPropertyPaths());
154 //TODO we should move subtree check down to service or persistence
155 TaxonNode subtree
= getSubtreeOrError(subtreeUuid
, nodeService
, response
);
156 taxonBase
= checkExistsSubtreeAndAccess(taxonBase
, subtree
, NO_UNPUBLISHED
, response
);
161 * Checks if a {@link TaxonBase taxonBase} is public and belongs to a {@link TaxonNode subtree}
162 * as accepted taxon or synonym.
163 * If not the according {@link HttpStatusMessage http messages} are send to response.
165 * Not (yet) checked is the relation to a subtree via a concept relationship.
167 * @param includeUnpublished
170 * @throws IOException
172 protected <S
extends TaxonBase
<?
>> S
checkExistsSubtreeAndAccess(S taxonBase
,
173 TaxonNode subtree
, boolean includeUnpublished
,
174 HttpServletResponse response
) throws IOException
{
175 taxonBase
= checkExistsAndAccess(taxonBase
, NO_UNPUBLISHED
, response
);
176 if (subtree
== null){
178 }else if(taxonBase
!= null){
179 //TODO synonyms maybe can not be initialized
180 Taxon taxon
= taxonBase
.isInstanceOf(Synonym
.class)?
181 CdmBase
.deproxy(taxonBase
, Synonym
.class).getAcceptedTaxon():
182 CdmBase
.deproxy(taxonBase
, Taxon
.class);
183 //check if taxon has any node that is a descendant of subtree
184 for (TaxonNode taxonNode
:taxon
.getTaxonNodes()){
185 if (subtree
.isAncestor(taxonNode
)){
189 HttpStatusMessage
.ACCESS_DENIED
.send(response
);
196 * Get the accepted {@link Taxon} for a given
197 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
199 * URI: <b>/{datasource-name}/taxon/{taxon-uuid}/accepted</b>
203 * @return a set on a list of {@link Taxon} entities which are initialized
204 * using the following initialization strategy:
205 * {@link #DEFAULT_INIT_STRATEGY}
206 * @throws IOException
208 @RequestMapping(value
= "accepted", method
= RequestMethod
.GET
)
209 public Taxon
doGetAcceptedFor(
210 @PathVariable("uuid") UUID uuid
,
211 @RequestParam(value
= "classificationFilter", required
= false) UUID classification_uuid
,
212 HttpServletRequest request
,
213 HttpServletResponse response
)
216 logger
.info("doGetAcceptedFor() " + requestPathAndQuery(request
));
220 boolean includeUnpublished
= NO_UNPUBLISHED
;
221 Taxon result
= service
.findAcceptedTaxonFor(uuid
, classification_uuid
, includeUnpublished
, getInitializationStrategy());
222 result
= checkExistsAndAccess(result
, includeUnpublished
, response
);
225 } catch (EntityNotFoundException e
){
226 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
, e
.getMessage());
227 } catch (UnpublishedException e
) {
228 HttpStatusMessage
.ACCESS_DENIED
.send(response
, e
.getMessage());
234 @RequestMapping(value
= "classifications", method
= RequestMethod
.GET
)
235 public List
<Classification
> doGetClassifications(
236 @PathVariable("uuid") UUID uuid
,
237 HttpServletRequest request
,
238 HttpServletResponse response
) throws IOException
{
240 boolean includeUnpublished
= NO_UNPUBLISHED
;
242 logger
.info("doGetClassifications(): " + request
.getRequestURI());
243 TaxonBase
<?
> taxonBase
= service
.load(uuid
);
244 taxonBase
= checkExistsAndAccess(taxonBase
, includeUnpublished
, response
);
246 return service
.listClassifications(taxonBase
, null, null, getInitializationStrategy());
249 @RequestMapping(value
= "taxonNodes", method
= RequestMethod
.GET
)
250 public Collection
<TaxonNodeDto
> doGetTaxonNodes(
251 @PathVariable("uuid") UUID taxonUuid
,
252 @RequestParam(value
= "subtree", required
= false) UUID subtreeUuid
,
253 HttpServletRequest request
,
254 HttpServletResponse response
) throws IOException
{
256 logger
.info("doGetTaxonNodes" + requestPathAndQuery(request
));
257 TaxonBase
<?
> taxonBase
= null;
258 if (subtreeUuid
!= null){
259 taxonBase
= doGet(taxonUuid
, subtreeUuid
, request
, response
);
261 // taxonBase = service.load(taxonUuid, NO_UNPUBLISHED, getTaxonNodeInitStrategy().getPropertyPaths());
263 if(taxonBase
!= null && taxonBase
instanceof Taxon
){
264 return ((Taxon
)taxonBase
).getTaxonNodes().stream().map(e
-> new TaxonNodeDto(e
)).collect(Collectors
.toSet());
267 return nodeService
.getTaxonNodeDtosFromTaxon(taxonUuid
);
268 }catch(Exception e
) {
269 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
279 protected EntityInitStrategy
getTaxonNodeInitStrategy() {
280 return TAXONNODE_INIT_STRATEGY
;
284 * See also {@link AgentController#doGetTaxonNodeAgentRelations(UUID, UUID, Integer, Integer, HttpServletRequest, HttpServletResponse)}
286 @RequestMapping(value
= "taxonNodeAgentRelations/{classification_uuid}", method
= RequestMethod
.GET
)
287 public Pager
<TaxonNodeAgentRelation
> doGetTaxonNodeAgentRelations(
288 @PathVariable("uuid") UUID uuid
,
289 @PathVariable("classification_uuid") UUID classificationUuid
,
290 @RequestParam(value
= "relType_uuid" , required
= false) UUID relTypeUuid
,
291 @RequestParam(value
= "pageIndex", required
= false) Integer pageIndex
,
292 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
293 HttpServletRequest request
,
294 HttpServletResponse response
) throws IOException
{
296 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageIndex
);
297 pagerParams
.normalizeAndValidate(response
);
299 Pager
<TaxonNodeAgentRelation
> pager
= nodeService
.pageTaxonNodeAgentRelations(uuid
, classificationUuid
,
300 null, null, relTypeUuid
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(), null);
305 @RequestMapping(value
= "specimensOrObservationsCount", method
= RequestMethod
.GET
)
306 public StringResultDTO
doCountSpecimensOrObservations(
307 @PathVariable("uuid") UUID uuid
,
308 HttpServletRequest request
,
309 HttpServletResponse response
) {
310 logger
.info("doListSpecimensOrObservations() - " + request
.getRequestURI());
312 List
<OrderHint
> orderHints
= new ArrayList
<>();
313 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
314 FindOccurrencesConfigurator config
= new FindOccurrencesConfigurator();
315 config
.setAssociatedTaxonUuid(uuid
);
316 long countSpecimen
= occurrenceService
.countOccurrences(config
);
317 return new StringResultDTO(String
.valueOf(countSpecimen
));
321 * @deprecated replaced by rootUnitDTOs
324 @RequestMapping(value
= "fieldUnitDTOs", method
= RequestMethod
.GET
)
325 public List
<SpecimenOrObservationBaseDTO
> doListFieldUnitDTOs(
326 @PathVariable("uuid") UUID uuid
,
327 HttpServletRequest request
,
328 HttpServletResponse response
) {
329 logger
.info("doListFieldUnitDTOs() - " + request
.getRequestURI());
331 List
<SpecimenOrObservationBaseDTO
> rootUnitDtos
= occurrenceService
.listRootUnitDTOsByAssociatedTaxon(null, uuid
, OccurrenceController
.DERIVED_UNIT_INIT_STRATEGY
);
332 return rootUnitDtos
.stream().filter(dto
-> dto
instanceof FieldUnitDTO
).collect(Collectors
.toList());
335 @RequestMapping(value
= "rootUnitDTOs", method
= RequestMethod
.GET
)
336 public List
<SpecimenOrObservationBaseDTO
> doListRooUnitDTOs(
337 @PathVariable("uuid") UUID uuid
,
338 HttpServletRequest request
,
339 HttpServletResponse response
) {
340 logger
.info("rootUnitDTOs() - " + request
.getRequestURI());
342 List
<SpecimenOrObservationBaseDTO
> rootUnitDtos
= occurrenceService
.listRootUnitDTOsByAssociatedTaxon(null, uuid
, OccurrenceController
.DERIVED_UNIT_INIT_STRATEGY
);
343 // List<SpecimenOrObservationBase<?>> specimensOrObservations = occurrenceService.listByAssociatedTaxon(null, null, (Taxon)tb, null, null, null, orderHints, null);
347 @RequestMapping(value
= "specimensOrObservations", method
= RequestMethod
.GET
)
348 public List
<SpecimenOrObservationBase
<?
>> doListSpecimensOrObservations(
349 @PathVariable("uuid") UUID uuid
,
350 HttpServletRequest request
,
351 HttpServletResponse response
) throws IOException
{
352 logger
.info("doListSpecimensOrObservations() - " + request
.getRequestURI());
354 TaxonBase
<?
> tb
= service
.load(uuid
);
355 List
<OrderHint
> orderHints
= new ArrayList
<>();
356 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
357 if(tb
instanceof Taxon
){
358 List
<SpecimenOrObservationBase
<?
>> specimensOrObservations
= occurrenceService
.listByAssociatedTaxon(null, null, (Taxon
)tb
, null, null, null, orderHints
, null);
359 return specimensOrObservations
;
361 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
366 @RequestMapping(value
= "associatedRootUnits", method
= RequestMethod
.GET
)
367 public Pager
<SpecimenOrObservationBase
> doGetAssociatedRootUnits(
368 @PathVariable("uuid") UUID uuid
,
369 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
370 @RequestParam(value
= "pageIndex", required
= false) Integer pageIndex
,
371 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
372 HttpServletRequest request
,
373 HttpServletResponse response
) throws IOException
{
374 logger
.info("doGetAssociatedRootUnits() - " + request
.getRequestURI());
376 TaxonBase
<?
> taxonBase
= service
.load(uuid
);
377 taxonBase
= checkExistsAndAccess(taxonBase
, NO_UNPUBLISHED
, response
);
379 List
<OrderHint
> orderHints
= new ArrayList
<>();
380 orderHints
.add(new OrderHint("titleCache", SortOrder
.ASCENDING
));
382 if(taxonBase
instanceof Taxon
){
383 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageIndex
);
384 pagerParams
.normalizeAndValidate(response
);
386 return occurrenceService
.pageRootUnitsByAssociatedTaxon(null, null, (Taxon
) taxonBase
, maxDepth
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(), orderHints
, null);
388 // FIXME proper HTTP code response
393 @RequestMapping(value
= "taggedName", method
= RequestMethod
.GET
)
394 public ModelAndView
doGetTaggedName(
395 @PathVariable("uuid") UUID uuid
,
396 HttpServletRequest request
) {
397 logger
.info("doGetDescriptionElementsByType() - " + request
.getRequestURI());
399 ModelAndView mv
= new ModelAndView();
401 TaxonBase
<?
> tb
= service
.load(uuid
, NO_UNPUBLISHED
, Arrays
.asList(new String
[] {"name"}));
402 mv
.addObject(nameService
.getTaggedName(tb
.getName().getUuid()));
407 * This webservice endpoint returns all taxa which are congruent or included in the taxon represented by the given taxon uuid.
408 * The result also returns the path to these taxa represented by the uuids of the taxon relationships types and doubtful information.
409 * If classificationUuids is set only taxa of classifications are returned which are included in the given classifications.
410 * Also the path to these taxa may not include taxa from other classifications.
412 @RequestMapping(value
= { "includedTaxa" }, method
= { RequestMethod
.GET
})
413 public IncludedTaxaDTO
doGetIncludedTaxa(
414 @PathVariable("uuid") UUID uuid
,
415 @RequestParam(value
="classificationFilter", required
=false) final List
<String
> classificationStringList
,
416 @RequestParam(value
="includeDoubtful", required
=false) final boolean includeDoubtful
,
417 @RequestParam(value
="onlyCongruent", required
=false) final boolean onlyCongruent
,
418 HttpServletResponse response
,
419 HttpServletRequest request
) {
423 logger
.info("doGetIncludedTaxa()" + requestPathAndQuery(request
));
426 List
<UUID
> classificationFilter
= null;
427 if( classificationStringList
!= null ){
428 classificationFilter
= new ArrayList
<>();
429 for(String classString
:classificationStringList
){
430 classificationFilter
.add(UUID
.fromString(classString
));
433 IncludedTaxonConfiguration configuration
=
434 new IncludedTaxonConfiguration(classificationFilter
, includeDoubtful
, onlyCongruent
);
435 IncludedTaxaDTO listIncludedTaxa
= service
.listIncludedTaxa(uuid
, configuration
);
436 return listIncludedTaxa
;
439 // TODO ================================================================================ //
440 // move all description and descriptionElement related methods into the according
441 // Description Controllers
444 * Get the list of {@link TaxonDescription}s of the
445 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code>.
447 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/descriptions</b>
451 * @return a List of {@link TaxonDescription} entities which are initialized
452 * using the following initialization strategy:
453 * {@link #TAXONDESCRIPTION_INIT_STRATEGY}
454 * @throws IOException
457 value
= {"descriptions"},
458 method
= RequestMethod
.GET
)
459 public Pager
<TaxonDescription
> doGetDescriptions(
460 @PathVariable("uuid") UUID uuid
,
461 @RequestParam(value
= "markerTypes", required
= false) List
<MarkerType
> markerTypes
,
462 @RequestParam(value
= "descriptionTypes", required
= false) List
<DescriptionType
> descriptionTypes
,
463 HttpServletRequest request
,
464 HttpServletResponse response
)throws IOException
{
467 logger
.info("doGetDescriptions()" + requestPathAndQuery(request
));
470 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
471 taxon
= checkExistsAndAccess(taxon
, NO_UNPUBLISHED
, response
);
473 Set
<MarkerType
> markerTypesSet
= new HashSet
<>();
474 if (markerTypes
!= null) {
475 markerTypesSet
.addAll(markerTypes
);
477 Set
<DescriptionType
> descriptionTypesSet
= new HashSet
<>();
478 if (descriptionTypes
!= null) {
479 descriptionTypesSet
.addAll(descriptionTypes
);
482 List
<String
> taxonDescriptionInitStrategy
= getTaxonDescriptionInitStrategy();
483 Pager
<TaxonDescription
> p
= descriptionService
.pageTaxonDescriptions(taxon
, null, null, markerTypesSet
, descriptionTypesSet
, null, null, taxonDescriptionInitStrategy
);
488 @RequestMapping(value
= "descriptions/elementsByType/{classSimpleName}", method
= RequestMethod
.GET
)
489 public ModelAndView
doGetDescriptionElementsByType(
490 @PathVariable("uuid") UUID uuid
,
491 @PathVariable("classSimpleName") String classSimpleName
,
492 @RequestParam(value
= "markerTypes", required
= false) List
<MarkerType
> markerTypes
,
493 @RequestParam(value
= "descriptionTypes", required
= false) List
<DescriptionType
> descriptionTypes
,
494 @RequestParam(value
= "count", required
= false, defaultValue
= "false") Boolean doCount
,
495 HttpServletRequest request
,
496 HttpServletResponse response
) throws IOException
{
497 logger
.info("doGetDescriptionElementsByType() - " + requestPathAndQuery(request
));
500 boolean includeUnpublished
= NO_UNPUBLISHED
;
502 ModelAndView mv
= new ModelAndView();
504 List
<DescriptionElementBase
> allElements
= new ArrayList
<>();
505 List
<DescriptionElementBase
> elements
;
508 List
<String
> initStrategy
= doCount ?
null : getTaxonDescriptionElementInitStrategy();
510 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
512 taxon
= checkExistsAndAccess(taxon
, includeUnpublished
, response
);
515 Set
<MarkerType
> markerTypesSet
= new HashSet
<>();
516 if (markerTypes
!= null) {
517 markerTypesSet
.addAll(markerTypes
);
519 Set
<DescriptionType
> descriptionTypesSet
= new HashSet
<>();
520 if (descriptionTypes
!= null) {
521 descriptionTypesSet
.addAll(descriptionTypes
);
524 List
<TaxonDescription
> taxonDescriptions
= descriptionService
.listTaxonDescriptions(
525 taxon
, null, null, markerTypesSet
, descriptionTypesSet
, null, null, null);
528 type
= Class
.forName("eu.etaxonomy.cdm.model.description."
530 if (taxonDescriptions
!= null) {
531 for (TaxonDescription description
: taxonDescriptions
) {
532 elements
= descriptionService
.listDescriptionElements(description
, null, type
, null, 0, initStrategy
);
533 allElements
.addAll(elements
);
534 count
+= elements
.size();
538 } catch (ClassNotFoundException e
) {
539 HttpStatusMessage
.create(e
.getLocalizedMessage(), 400).send(response
);
544 mv
.addObject(allElements
);
549 @RequestMapping(value
= "taxonRelationshipsDTO", method
= RequestMethod
.GET
)
550 public TaxonRelationshipsDTO
doGetTaxonRelationshipsDTO(
551 @PathVariable("uuid") UUID taxonUuid
,
552 @RequestParam(value
= "directTypes", required
= false) UuidList directTypeUuids
,
553 @RequestParam(value
= "inversTypes", required
= false) UuidList inversTypeUuids
,
554 @RequestParam(value
= "direction", required
= false) Direction direction
,
555 @RequestParam(value
="groupMisapplications", required
=false, defaultValue
="false") final boolean groupMisapplications
,
556 HttpServletRequest request
,
557 HttpServletResponse response
) throws IOException
{
559 boolean includeUnpublished
= NO_UNPUBLISHED
;
561 logger
.info("doGetTaxonRelationshipDTOs(): " + request
.getRequestURI());
562 TaxonBase
<?
> taxonBase
= service
.load(taxonUuid
);
563 checkExistsAccessType(taxonBase
, includeUnpublished
, Taxon
.class, response
);
565 Set
<TaxonRelationshipType
> directTypes
= getTermsByUuidSet(TaxonRelationshipType
.class, directTypeUuids
);
566 Set
<TaxonRelationshipType
> inversTypes
= getTermsByUuidSet(TaxonRelationshipType
.class, inversTypeUuids
);
568 // Set<TaxonRelationshipType> inversTypes = null;
569 // if (directTypeUuids != null && !directTypeUuids.isEmpty()){
570 // types = new HashSet<>();
571 // List<TaxonRelationshipType> typeList = termService.find(TaxonRelationshipType.class, new HashSet<>(directTypeUuids));
572 // types.addAll(typeList);
573 // //TODO should we handle missing uuids as error response
574 //// HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
579 // boolean deduplicateMisapplications = true;
580 Integer pageSize
= null;
581 Integer pageNumber
= null;
582 return service
.listTaxonRelationships(taxonUuid
, directTypes
, inversTypes
, direction
, groupMisapplications
,
583 includeUnpublished
, pageSize
, pageNumber
);
587 * @param directTypeUuids
590 protected <T
extends DefinedTermBase
<T
>> Set
<T
> getTermsByUuidSet(Class
<T
> clazz
, UuidList directTypeUuids
) {
591 Set
<T
> directTypes
= null;
593 if (directTypeUuids
!= null && !directTypeUuids
.isEmpty()){
594 directTypes
= new HashSet
<>();
595 List
<T
> typeList
= termService
.find(clazz
, new HashSet
<>(directTypeUuids
));
596 directTypes
.addAll(typeList
);
597 //TODO should we handle missing uuids as error response
598 // HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
603 // TODO ================================================================================ //