Project

General

Profile

Download (24.8 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.cdm.remote.controller;
11

    
12
import java.io.IOException;
13
import java.util.ArrayList;
14
import java.util.Arrays;
15
import java.util.HashSet;
16
import java.util.List;
17
import java.util.Set;
18
import java.util.UUID;
19

    
20
import javax.persistence.EntityNotFoundException;
21
import javax.servlet.http.HttpServletRequest;
22
import javax.servlet.http.HttpServletResponse;
23

    
24
import org.apache.log4j.Logger;
25
import org.springframework.beans.factory.annotation.Autowired;
26
import org.springframework.stereotype.Controller;
27
import org.springframework.web.bind.WebDataBinder;
28
import org.springframework.web.bind.annotation.PathVariable;
29
import org.springframework.web.bind.annotation.RequestMapping;
30
import org.springframework.web.bind.annotation.RequestMethod;
31
import org.springframework.web.bind.annotation.RequestParam;
32
import org.springframework.web.servlet.ModelAndView;
33

    
34
import eu.etaxonomy.cdm.api.service.IDescriptionService;
35
import eu.etaxonomy.cdm.api.service.INameService;
36
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
37
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
38
import eu.etaxonomy.cdm.api.service.ITaxonService;
39
import eu.etaxonomy.cdm.api.service.ITermService;
40
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
41
import eu.etaxonomy.cdm.api.service.config.IncludedTaxonConfiguration;
42
import eu.etaxonomy.cdm.api.service.dto.FieldUnitDTO;
43
import eu.etaxonomy.cdm.api.service.dto.IncludedTaxaDTO;
44
import eu.etaxonomy.cdm.api.service.dto.TaxonRelationshipsDTO;
45
import eu.etaxonomy.cdm.api.service.pager.Pager;
46
import eu.etaxonomy.cdm.exception.UnpublishedException;
47
import eu.etaxonomy.cdm.model.common.CdmBase;
48
import eu.etaxonomy.cdm.model.common.MarkerType;
49
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
50
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
51
import eu.etaxonomy.cdm.model.description.TaxonDescription;
52
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
53
import eu.etaxonomy.cdm.model.taxon.Classification;
54
import eu.etaxonomy.cdm.model.taxon.Synonym;
55
import eu.etaxonomy.cdm.model.taxon.Taxon;
56
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
57
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
58
import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
59
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
60
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
61
import eu.etaxonomy.cdm.persistence.query.OrderHint;
62
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
63
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
64
import eu.etaxonomy.cdm.remote.dto.common.StringResultDTO;
65
import eu.etaxonomy.cdm.remote.editor.TermBasePropertyEditor;
66
import eu.etaxonomy.cdm.remote.editor.UuidList;
67
import io.swagger.annotations.Api;
68

    
69
/**
70
 * TODO write controller documentation
71
 *
72
 * @author a.kohlbecker
73
 * @since 20.07.2009
74
 *
75
 */
76
@Controller
77
@Api("taxon")
78
@RequestMapping(value = {"/taxon/{uuid}"})
79
public class TaxonController extends AbstractIdentifiableController<TaxonBase, ITaxonService>{
80

    
81
    public static final Logger logger = Logger.getLogger(TaxonController.class);
82

    
83
    @Autowired
84
    private IOccurrenceService occurrenceService;
85

    
86
    @Autowired
87
    private INameService nameService;
88

    
89
    @Autowired
90
    private ITaxonNodeService nodeService;
91

    
92
    @Autowired
93
    private IDescriptionService descriptionService;
94

    
95
    @Autowired
96
    private ITermService termService;
97

    
98
    protected static final List<String> TAXONNODE_INIT_STRATEGY = Arrays.asList(new String []{
99
            "taxonNodes.classification","acceptedTaxon.taxonNodes.classification"
100
    });
101

    
102
    public TaxonController(){
103
        super();
104
        setInitializationStrategy(Arrays.asList(new String[]{
105
                "$",
106
                "name.nomenclaturalReference"
107
                }
108
        ));
109
    }
110

    
111
    @Override
112
    @Autowired
113
    public void setService(ITaxonService service) {
114
        this.service = service;
115
    }
116

    
117
    /**
118
     * {@inheritDoc}
119
     */
120
    @Override
121
    public void initBinder(WebDataBinder binder) {
122
        super.initBinder(binder);
123
        binder.registerCustomEditor(MarkerType.class, new TermBasePropertyEditor<>(termService));
124
    }
125

    
126
    protected List<String> getTaxonDescriptionInitStrategy() {
127
        return getInitializationStrategy();
128
    }
129

    
130
    protected List<String> getTaxonDescriptionElementInitStrategy() {
131
        return getInitializationStrategy();
132
    }
133

    
134
    @RequestMapping(params="subtree", method = RequestMethod.GET)
135
    public TaxonBase<?> doGet(@PathVariable("uuid") UUID uuid,
136
            @RequestParam(value = "subtree", required = true) UUID subtreeUuid,  //if subtree does not exist the base class method is used, therefore required
137
            HttpServletRequest request,
138
            HttpServletResponse response) throws IOException {
139
        if(request != null) {
140
            logger.info("doGet() " + requestPathAndQuery(request));
141
        }
142
        //TODO do we want to allow Synonyms at all? Maybe needs initialization
143
        TaxonBase<?> taxonBase = getCdmBaseInstance(uuid, response, TAXONNODE_INIT_STRATEGY);
144
        //TODO we should move subtree check down to service or persistence
145
        TaxonNode subtree = getSubtreeOrError(subtreeUuid, nodeService, response);
146
        taxonBase = checkExistsSubtreeAndAccess(taxonBase, subtree, NO_UNPUBLISHED, response);
147
        return taxonBase;
148
    }
149

    
150
    /**
151
     * Checks if a {@link TaxonBase taxonBase} is public and belongs to a {@link TaxonNode subtree}
152
     * as accepted taxon or synonym.
153
     * If not the according {@link HttpStatusMessage http messages} are send to response.
154
     * <BR>
155
     * Not (yet) checked is the relation to a subtree via a concept relationship.
156
     * @param taxonBase
157
     * @param includeUnpublished
158
     * @param response
159
     * @return
160
     * @throws IOException
161
     */
162
    protected <S extends TaxonBase<?>> S checkExistsSubtreeAndAccess(S taxonBase,
163
            TaxonNode subtree, boolean includeUnpublished,
164
            HttpServletResponse response) throws IOException {
165
        taxonBase = checkExistsAndAccess(taxonBase, NO_UNPUBLISHED, response);
166
        if (subtree == null){
167
            return taxonBase;
168
        }else if(taxonBase != null){
169
            //TODO synonyms maybe can not be initialized
170
            Taxon taxon = taxonBase.isInstanceOf(Synonym.class)?
171
                    CdmBase.deproxy(taxonBase, Synonym.class).getAcceptedTaxon():
172
                    CdmBase.deproxy(taxonBase, Taxon.class);
173
            //check if taxon has any node that is a descendant of subtree
174
            for (TaxonNode taxonNode :taxon.getTaxonNodes()){
175
                if (subtree.isAncestor(taxonNode)){
176
                    return taxonBase;
177
                }
178
            }
179
            HttpStatusMessage.ACCESS_DENIED.send(response);
180
        }
181
        return null;
182
    }
183

    
184

    
185
    /**
186
     * Get the accepted {@link Taxon} for a given
187
     * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
188
     * <p>
189
     * URI: <b>&#x002F;{datasource-name}&#x002F;taxon&#x002F;{taxon-uuid}&#x002F;accepted</b>
190
     *
191
     * @param request
192
     * @param response
193
     * @return a set on a list of {@link Taxon} entities which are initialized
194
     *         using the following initialization strategy:
195
     *         {@link #DEFAULT_INIT_STRATEGY}
196
     * @throws IOException
197
     */
198
    @RequestMapping(value = "accepted", method = RequestMethod.GET)
199
    public Taxon doGetAcceptedFor(
200
            @PathVariable("uuid") UUID uuid,
201
            @RequestParam(value = "classificationFilter", required = false) UUID classification_uuid,
202
            HttpServletRequest request,
203
            HttpServletResponse response)
204
            throws IOException {
205
        if(request != null){
206
            logger.info("doGetAcceptedFor() " + requestPathAndQuery(request));
207
        }
208

    
209
        try {
210
            boolean includeUnpublished = NO_UNPUBLISHED;
211
            Taxon result = service.findAcceptedTaxonFor(uuid, classification_uuid, includeUnpublished, getInitializationStrategy());
212
            result = checkExistsAndAccess(result, includeUnpublished, response);
213

    
214
            return result;
215
        } catch (EntityNotFoundException e){
216
            HttpStatusMessage.UUID_NOT_FOUND.send(response, e.getMessage());
217
        } catch (UnpublishedException e) {
218
            HttpStatusMessage.ACCESS_DENIED.send(response, e.getMessage());
219
        }
220
        return null;
221

    
222
    }
223

    
224
    @RequestMapping(value = "classifications", method = RequestMethod.GET)
225
    public List<Classification> doGetClassifications(
226
            @PathVariable("uuid") UUID uuid,
227
            HttpServletRequest request,
228
            HttpServletResponse response) throws IOException {
229

    
230
        boolean includeUnpublished = NO_UNPUBLISHED;
231

    
232
        logger.info("doGetClassifications(): " + request.getRequestURI());
233
        TaxonBase<?> taxonBase = service.load(uuid);
234
        taxonBase = checkExistsAndAccess(taxonBase, includeUnpublished, response);
235

    
236
        return service.listClassifications(taxonBase, null, null, getInitializationStrategy());
237
    }
238

    
239
    @RequestMapping(value = "taxonNodes", method = RequestMethod.GET)
240
    public Set<TaxonNode>  doGetTaxonNodes(
241
            @PathVariable("uuid") UUID taxonUuid,
242
            @RequestParam(value = "subtree", required = false) UUID subtreeUuid,
243
            HttpServletRequest request,
244
            HttpServletResponse response) throws IOException {
245

    
246
        logger.info("doGetTaxonNodes" + requestPathAndQuery(request));
247
        TaxonBase<?> taxonBase;
248
        if (subtreeUuid != null){
249
            taxonBase = doGet(taxonUuid, subtreeUuid, request, response);
250
        }else{
251
            taxonBase = service.load(taxonUuid, NO_UNPUBLISHED, TAXONNODE_INIT_STRATEGY);
252
        }
253
        if(taxonBase instanceof Taxon){
254
            return ((Taxon)taxonBase).getTaxonNodes();
255
        } else {
256
            HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
257
            return null;
258
        }
259
    }
260

    
261
    /**
262
    *
263
    * See also {@link AgentController#doGetTaxonNodeAgentRelations(UUID, UUID, Integer, Integer, HttpServletRequest, HttpServletResponse)}
264
    *
265
    * @param uuid
266
    * @param classificationUuid
267
    * @param pageNumber
268
    * @param pageSize
269
    * @param request
270
    * @param response
271
    * @return
272
    * @throws IOException
273
    *
274
    */
275
    @RequestMapping(value = "taxonNodeAgentRelations/{classification_uuid}", method = RequestMethod.GET)
276
    public Pager<TaxonNodeAgentRelation>  doGetTaxonNodeAgentRelations(
277
            @PathVariable("uuid") UUID uuid,
278
            @PathVariable("classification_uuid") UUID classificationUuid,
279
            @RequestParam(value = "relType_uuid" , required = false) UUID relTypeUuid,
280
            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
281
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
282
            HttpServletRequest request,
283
            HttpServletResponse response) throws IOException {
284

    
285
        PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
286
        pagerParams.normalizeAndValidate(response);
287

    
288
        Pager<TaxonNodeAgentRelation> pager = nodeService.pageTaxonNodeAgentRelations(uuid, classificationUuid,
289
                null, null, relTypeUuid, pagerParams.getPageSize(), pagerParams.getPageIndex(), null);
290
        return pager;
291
    }
292

    
293

    
294
    @RequestMapping(value = "specimensOrObservationsCount", method = RequestMethod.GET)
295
    public StringResultDTO doCountSpecimensOrObservations(
296
            @PathVariable("uuid") UUID uuid,
297
            HttpServletRequest request,
298
            HttpServletResponse response) throws IOException {
299
        logger.info("doListSpecimensOrObservations() - " + request.getRequestURI());
300

    
301
        List<OrderHint> orderHints = new ArrayList<>();
302
        orderHints.add(new OrderHint("titleCache", SortOrder.DESCENDING));
303
        FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
304
        config.setAssociatedTaxonUuid(uuid);
305
        long countSpecimen = occurrenceService.countOccurrences(config);
306
        return new StringResultDTO(String.valueOf(countSpecimen));
307
    }
308

    
309
    @RequestMapping(value = "specimensOrObservationDTOs", method = RequestMethod.GET)
310
    public ModelAndView doListSpecimensOrObservationDTOs(
311
            @PathVariable("uuid") UUID uuid,
312
            HttpServletRequest request,
313
            HttpServletResponse response) throws IOException {
314
        logger.info("doListSpecimensOrObservations() - " + request.getRequestURI());
315

    
316
        ModelAndView mv = new ModelAndView();
317
        List<FieldUnitDTO> fieldUnitDtos = occurrenceService.findFieldUnitDTOByAssociatedTaxon(null, uuid);
318
           // List<SpecimenOrObservationBase<?>> specimensOrObservations = occurrenceService.listByAssociatedTaxon(null, null, (Taxon)tb, null, null, null, orderHints, null);
319
        mv.addObject(fieldUnitDtos);
320
        return mv;
321
    }
322

    
323
    @RequestMapping(value = "specimensOrObservations", method = RequestMethod.GET)
324
    public ModelAndView doListSpecimensOrObservations(
325
            @PathVariable("uuid") UUID uuid,
326
            HttpServletRequest request,
327
            HttpServletResponse response) throws IOException {
328
        logger.info("doListSpecimensOrObservations() - " + request.getRequestURI());
329
        ModelAndView mv = new ModelAndView();
330
        TaxonBase<?> tb = service.load(uuid);
331
        List<OrderHint> orderHints = new ArrayList<>();
332
        orderHints.add(new OrderHint("titleCache", SortOrder.DESCENDING));
333
        if(tb instanceof Taxon){
334
            List<SpecimenOrObservationBase<?>> specimensOrObservations = occurrenceService.listByAssociatedTaxon(null, null, (Taxon)tb, null, null, null, orderHints, null);
335
            mv.addObject(specimensOrObservations);
336
        } else {
337
            HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
338
            return null;
339
        }
340
        return mv;
341
    }
342

    
343
    @RequestMapping(value = "associatedFieldUnits", method = RequestMethod.GET)
344
    public Pager<SpecimenOrObservationBase> doGetFieldUnits(
345
            @PathVariable("uuid") UUID uuid,
346
            @RequestParam(value = "maxDepth", required = false) Integer maxDepth,
347
            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
348
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
349
            HttpServletRequest request,
350
            HttpServletResponse response) throws IOException {
351
        logger.info("doGetFieldUnits() - " + request.getRequestURI());
352

    
353
        TaxonBase<?> taxonBase = service.load(uuid);
354
        taxonBase = checkExistsAndAccess(taxonBase, NO_UNPUBLISHED, response);
355

    
356
        List<OrderHint> orderHints = new ArrayList<>();
357
        orderHints.add(new OrderHint("titleCache", SortOrder.ASCENDING));
358

    
359
        if(taxonBase instanceof Taxon){
360
            PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
361
            pagerParams.normalizeAndValidate(response);
362

    
363
            return occurrenceService.pageFieldUnitsByAssociatedTaxon(null, (Taxon) taxonBase, null, pagerParams.getPageSize(), pagerParams.getPageIndex(), orderHints, null);
364
        }else{
365
            return null;
366
        }
367
    }
368

    
369
    @RequestMapping(value = "taggedName", method = RequestMethod.GET)
370
    public ModelAndView doGetTaggedName(
371
            @PathVariable("uuid") UUID uuid,
372
            HttpServletRequest request) {
373
        logger.info("doGetDescriptionElementsByType() - " + request.getRequestURI());
374

    
375
        ModelAndView mv = new ModelAndView();
376

    
377
        TaxonBase<?> tb = service.load(uuid, NO_UNPUBLISHED, Arrays.asList(new String[] {"name"}));
378
        mv.addObject(nameService.getTaggedName(tb.getName().getUuid()));
379
        return mv;
380
    }
381

    
382
    /**
383
     * This webservice endpoint returns all taxa which are congruent or included in the taxon represented by the given taxon uuid.
384
     * The result also returns the path to these taxa represented by the uuids of the taxon relationships types and doubtful information.
385
     * If classificationUuids is set only taxa of classifications are returned which are included in the given classifications.
386
     * Also the path to these taxa may not include taxa from other classifications.
387
     *
388
     * @param taxonUUIDString
389
     * @param classificationStringList
390
     * @param includeDoubtful
391
     * @param onlyCongruent
392
     * @param response
393
     * @param request
394
     * @return
395
     * @throws IOException
396
     */
397
    @RequestMapping(value = { "includedTaxa" }, method = { RequestMethod.GET })
398
    public IncludedTaxaDTO doGetIncludedTaxa(
399
            @PathVariable("uuid") UUID uuid,
400
            @RequestParam(value="classificationFilter", required=false) final List<String> classificationStringList,
401
            @RequestParam(value="includeDoubtful", required=false) final boolean includeDoubtful,
402
            @RequestParam(value="onlyCongruent", required=false) final boolean onlyCongruent,
403
            HttpServletResponse response,
404
            HttpServletRequest request) throws IOException {
405

    
406

    
407
        if(request != null){
408
            logger.info("doGetIncludedTaxa()" + requestPathAndQuery(request));
409
        }
410

    
411
        List<UUID> classificationFilter = null;
412
        if( classificationStringList != null ){
413
            classificationFilter = new ArrayList<>();
414
            for(String classString :classificationStringList){
415
                classificationFilter.add(UUID.fromString(classString));
416
            }
417
        }
418
        IncludedTaxonConfiguration configuration =
419
                new IncludedTaxonConfiguration(classificationFilter, includeDoubtful, onlyCongruent);
420
        IncludedTaxaDTO listIncludedTaxa = service.listIncludedTaxa(uuid, configuration);
421
        return listIncludedTaxa;
422
    }
423

    
424
    // TODO ================================================================================ //
425
    // move all description and descriptionElement related methods into the according
426
    // Description Controllers
427

    
428
    /**
429
     * Get the list of {@link TaxonDescription}s of the
430
     * {@link Taxon} instance identified by the <code>{taxon-uuid}</code>.
431
     * <p>
432
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;taxon&#x002F;{taxon-uuid}&#x002F;descriptions</b>
433
     *
434
     * @param request
435
     * @param response
436
     * @return a List of {@link TaxonDescription} entities which are initialized
437
     *         using the following initialization strategy:
438
     *         {@link #TAXONDESCRIPTION_INIT_STRATEGY}
439
     * @throws IOException
440
     */
441
    @RequestMapping(
442
            value = {"descriptions"},
443
            method = RequestMethod.GET)
444
    public Pager<TaxonDescription> doGetDescriptions(
445
            @PathVariable("uuid") UUID uuid,
446
            @RequestParam(value = "markerTypes", required = false) List<MarkerType> markerTypes,
447
            HttpServletRequest request,
448
            HttpServletResponse response)throws IOException {
449

    
450
        if(request != null){
451
            logger.info("doGetDescriptions()" + requestPathAndQuery(request));
452
        }
453

    
454
        Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
455
        taxon = checkExistsAndAccess(taxon, NO_UNPUBLISHED, response);
456

    
457
        Set<MarkerType> markerTypesSet = new HashSet<>();
458
        if (markerTypes != null) {
459
            markerTypesSet.addAll(markerTypes);
460
        }
461

    
462
        Pager<TaxonDescription> p = descriptionService.pageTaxonDescriptions(taxon, null, null, markerTypesSet, null, null, getTaxonDescriptionInitStrategy());
463

    
464
        return p;
465
    }
466

    
467
    @RequestMapping(value = "descriptions/elementsByType/{classSimpleName}", method = RequestMethod.GET)
468
    public ModelAndView doGetDescriptionElementsByType(
469
            @PathVariable("uuid") UUID uuid,
470
            @PathVariable("classSimpleName") String classSimpleName,
471
            @RequestParam(value = "markerTypes", required = false) List<MarkerType> markerTypes,
472
            @RequestParam(value = "count", required = false, defaultValue = "false") Boolean doCount,
473
            HttpServletRequest request,
474
            HttpServletResponse response) throws IOException {
475
        logger.info("doGetDescriptionElementsByType() - " + requestPathAndQuery(request));
476

    
477

    
478
        boolean includeUnpublished = NO_UNPUBLISHED;
479

    
480
        ModelAndView mv = new ModelAndView();
481

    
482
        List<DescriptionElementBase> allElements = new ArrayList<>();
483
        List<DescriptionElementBase> elements;
484
        int count = 0;
485

    
486
        List<String> initStrategy = doCount ? null : getTaxonDescriptionElementInitStrategy();
487

    
488
        Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
489

    
490
        taxon = checkExistsAndAccess(taxon, includeUnpublished, response);
491

    
492

    
493
        Set<MarkerType> markerTypesSet = new HashSet<>();
494
        if (markerTypes == null) {
495
            markerTypesSet.addAll(markerTypes);
496
        }
497

    
498
        List<TaxonDescription> taxonDescriptions = descriptionService.listTaxonDescriptions(
499
                taxon, null, null, markerTypesSet, null, null, null);
500
        try {
501
            Class type;
502
            type = Class.forName("eu.etaxonomy.cdm.model.description."
503
                    + classSimpleName);
504
            if (taxonDescriptions != null) {
505
                for (TaxonDescription description : taxonDescriptions) {
506
                    elements = descriptionService.listDescriptionElements(description, null, type, null, 0, initStrategy);
507
                    allElements.addAll(elements);
508
                    count += elements.size();
509
                }
510

    
511
            }
512
        } catch (ClassNotFoundException e) {
513
            HttpStatusMessage.create(e.getLocalizedMessage(), 400).send(response);
514
        }
515
        if(doCount){
516
            mv.addObject(count);
517
        } else {
518
            mv.addObject(allElements);
519
        }
520
        return mv;
521
    }
522

    
523
    @RequestMapping(value = "taxonRelationshipsDTO", method = RequestMethod.GET)
524
    public TaxonRelationshipsDTO doGetTaxonRelationshipsDTO(
525
            @PathVariable("uuid") UUID taxonUuid,
526
            @RequestParam(value = "directTypes", required = false) UuidList directTypeUuids,
527
            @RequestParam(value = "inversTypes", required = false) UuidList inversTypeUuids,
528
            @RequestParam(value = "direction", required = false) Direction direction,
529
            @RequestParam(value="groupMisapplications", required=false, defaultValue="false") final boolean groupMisapplications,
530
            HttpServletRequest request,
531
            HttpServletResponse response) throws IOException {
532

    
533
        boolean includeUnpublished = NO_UNPUBLISHED;
534

    
535
        logger.info("doGetTaxonRelationshipDTOs(): " + request.getRequestURI());
536
        TaxonBase<?> taxonBase = service.load(taxonUuid);
537
        checkExistsAccessType(taxonBase, includeUnpublished, Taxon.class, response);
538

    
539
        Set<TaxonRelationshipType> directTypes = getTermsByUuidSet(TaxonRelationshipType.class, directTypeUuids);
540
        Set<TaxonRelationshipType> inversTypes = getTermsByUuidSet(TaxonRelationshipType.class, inversTypeUuids);
541

    
542
//        Set<TaxonRelationshipType> inversTypes = null;
543
//        if (directTypeUuids != null && !directTypeUuids.isEmpty()){
544
//            types = new HashSet<>();
545
//            List<TaxonRelationshipType> typeList = termService.find(TaxonRelationshipType.class, new HashSet<>(directTypeUuids));
546
//            types.addAll(typeList);
547
//            //TODO should we handle missing uuids as error response
548
////            HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
549
//        }
550

    
551

    
552

    
553
//        boolean deduplicateMisapplications = true;
554
        Integer pageSize = null;
555
        Integer pageNumber = null;
556
        return service.listTaxonRelationships(taxonUuid, directTypes, inversTypes, direction, groupMisapplications,
557
                includeUnpublished, pageSize, pageNumber);
558
    }
559

    
560
    /**
561
     * @param directTypeUuids
562
     * @return
563
     */
564
    protected <T extends DefinedTermBase<T>> Set<T> getTermsByUuidSet(Class<T> clazz, UuidList directTypeUuids) {
565
        Set<T> directTypes = null;
566

    
567
        if (directTypeUuids != null && !directTypeUuids.isEmpty()){
568
            directTypes = new HashSet<>();
569
            List<T> typeList = termService.find(clazz, new HashSet<>(directTypeUuids));
570
            directTypes.addAll(typeList);
571
            //TODO should we handle missing uuids as error response
572
//            HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
573
        }
574
        return directTypes;
575
    }
576

    
577
    // TODO ================================================================================ //
578

    
579
}
(57-57/70)