Project

General

Profile

Revision d17b9e90

IDd17b9e90911868cd9038a3f523b7a03b7970ceef
Parent 50355d23
Child fe053257

Added by Andreas Müller over 2 years ago

ref #6065 first implementation of taxonInContext service

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TaxonNodeDto.java
24 24
 */
25 25
public class TaxonNodeDto {
26 26

  
27
    private enum TaxonStatus{
27
    public enum TaxonStatus{
28 28
        Accepted,
29 29
        SynonymObjective,
30 30
        Synonym; //All others including undefined and explicitly subjective /heterotypic synonyms
31

  
32
        public boolean isSynonym(){
33
           return this == SynonymObjective || this == Synonym;
34
        }
31 35
    }
32 36

  
33 37
    /**
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/ClassificationController.java
31 31
import eu.etaxonomy.cdm.api.service.ITermService;
32 32
import eu.etaxonomy.cdm.api.service.NodeSortMode;
33 33
import eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO;
34
import eu.etaxonomy.cdm.api.service.dto.TaxonInContextDTO;
34 35
import eu.etaxonomy.cdm.api.service.pager.Pager;
35 36
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
36 37
import eu.etaxonomy.cdm.model.name.Rank;
......
219 220
        }
220 221
        return rank;
221 222
    }
223

  
224

  
225
   @RequestMapping(
226
           value = {"taxonInContext"},
227
           method = RequestMethod.GET)
228
   public TaxonInContextDTO getTaxonInContext(
229
           @PathVariable("uuid") UUID classificationUuid,
230
           @PathVariable("taxonUuid") UUID taxonUuid,
231
           @RequestParam(value = "doChildren", defaultValue = "false") Boolean doChildren,
232
           @RequestParam(value = "doSynonyms", defaultValue = "false") Boolean doSynonyms,
233
           @RequestParam(value = "sortMode", defaultValue="AlphabeticalOrder") NodeSortMode sortMode,
234
           @RequestParam(value = "ancestorMarker", required = false) List<UUID> ancestorMarkers,
235
           HttpServletResponse response
236
           ) throws IOException {
237

  
238
       TaxonInContextDTO taxonInContextDTO = service.getTaxonInContext(classificationUuid, taxonUuid, doChildren, doSynonyms, ancestorMarkers, sortMode) ;
239

  
240
       return taxonInContextDTO;
241
   }
242

  
243

  
222 244
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImpl.java
30 30
import eu.etaxonomy.cdm.api.service.config.CreateHierarchyForClassificationConfigurator;
31 31
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
32 32
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
33
import eu.etaxonomy.cdm.api.service.dto.EntityDTO;
33 34
import eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO;
35
import eu.etaxonomy.cdm.api.service.dto.TaxonInContextDTO;
34 36
import eu.etaxonomy.cdm.api.service.pager.Pager;
35 37
import eu.etaxonomy.cdm.api.service.pager.PagerUtils;
36 38
import eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl;
......
49 51
import eu.etaxonomy.cdm.model.taxon.Classification;
50 52
import eu.etaxonomy.cdm.model.taxon.ITaxonNodeComparator;
51 53
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
54
import eu.etaxonomy.cdm.model.taxon.Synonym;
52 55
import eu.etaxonomy.cdm.model.taxon.Taxon;
56
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
53 57
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
54 58
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
55 59
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
56 60
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
57 61
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
58 62
import eu.etaxonomy.cdm.persistence.dto.ClassificationLookupDTO;
63
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
64
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto.TaxonStatus;
59 65
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
60 66
import eu.etaxonomy.cdm.persistence.query.OrderHint;
61 67
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
......
78 84
    private ITaxonDao taxonDao;
79 85

  
80 86
    @Autowired
87
    private ITaxonNodeService taxonNodeService;
88

  
89
    @Autowired
81 90
    private IBeanInitializer defaultBeanInitializer;
82 91

  
83 92
    @Override
......
695 704
        return taxonNodeUuid;
696 705
    }
697 706

  
707
    /**
708
     * {@inheritDoc}
709
     */
710
    @Override
711
    public TaxonInContextDTO getTaxonInContext(UUID classificationUuid, UUID taxonUuid,
712
            Boolean doChildren, Boolean doSynonyms, List<UUID> ancestorMarkers,
713
            NodeSortMode sortMode) {
714
        TaxonInContextDTO result = new TaxonInContextDTO();
715
        TaxonBase<?> taxonBase = taxonDao.load(taxonUuid);
716

  
717
        TaxonNameBase<?,?> name = taxonBase.getName();
718
        result.setNameUuid(name.getUuid());
719
        result.setNameLabel(name.getTitleCache());
720
        if (name.isInstanceOf(NonViralName.class)){
721
            NonViralName<?> nvn = CdmBase.deproxy(name, NonViralName.class);
722

  
723
            result.setNameWithoutAuthor(nvn.getNameCache());
724
            result.setGenusOrUninomial(nvn.getGenusOrUninomial());
725
            result.setInfraGenericEpithet(nvn.getInfraGenericEpithet());
726
            result.setSpeciesEpithet(nvn.getSpecificEpithet());
727
            result.setInfraSpecificEpithet(nvn.getInfraSpecificEpithet());
728

  
729
            result.setAuthorship(nvn.getAuthorshipCache());
730

  
731
            Rank rank = name.getRank();
732
            if (rank != null){
733
                result.setRankUuid(rank.getUuid());
734
                result.setRankLabel(rank.getTitleCache());
735
            }
736
        }
737

  
738
        UUID taxonNodeUuid = getTaxonNodeUuidByTaxonUuid(classificationUuid, taxonUuid);
739
        result.setTaxonNodeUuid(taxonNodeUuid);
740

  
741
        boolean recursive = false;
742
        int pageSize = Integer.MAX_VALUE;
743
        int pageIndex = 0;
744
        Pager<TaxonNodeDto> children = taxonNodeService.pageChildNodesDTOs(taxonNodeUuid, recursive, doSynonyms, sortMode, pageSize, pageIndex);
745

  
746
        //children
747
        for (TaxonNodeDto childDto : children.getRecords()){
748
            if (doChildren && childDto.getStatus().equals(TaxonStatus.Accepted)){
749
                EntityDTO<Taxon> child = new EntityDTO<Taxon>(childDto.getTaxonUuid(), childDto.getTitleCache());
750
                result.addChild(child);
751
            }else if (doSynonyms && childDto.getStatus().isSynonym()){
752
                EntityDTO<Synonym> child = new EntityDTO<Synonym>(childDto.getTaxonUuid(), childDto.getTitleCache());
753
                result.addSynonym(child);
754
            }
755
        }
756

  
757
        //marked ancestors
758
        return result;
759
    }
760

  
698 761
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IClassificationService.java
18 18
import eu.etaxonomy.cdm.api.service.config.CreateHierarchyForClassificationConfigurator;
19 19
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
20 20
import eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO;
21
import eu.etaxonomy.cdm.api.service.dto.TaxonInContextDTO;
21 22
import eu.etaxonomy.cdm.api.service.pager.Pager;
22 23
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
23 24
import eu.etaxonomy.cdm.model.name.Rank;
......
336 337
     */
337 338
    List<GroupedTaxonDTO> groupTaxaByHigherTaxon(List<UUID> taxonUuids, UUID classificationUuid, Rank minRank, Rank maxRank);
338 339

  
340
    /**
341
     * Returns the most relevant data of a taxon/taxon node, including children, synonyms
342
     * and certain ancestors if required.
343
     * @param classificationUuid
344
     * @param taxonUuid
345
     * @param doSynonyms
346
     * @param ancestorMarkers
347
     * @return
348
     */
349
    public TaxonInContextDTO getTaxonInContext(UUID classificationUuid, UUID taxonUuid,
350
            Boolean doChildren, Boolean doSynonyms, List<UUID> ancestorMarkers,
351
            NodeSortMode sortMode);
352

  
339 353

  
340 354
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/EntityDTO.java
1
// $Id$
2
/**
3
* Copyright (C) 2014 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10
package eu.etaxonomy.cdm.api.service.dto;
11

  
12
import java.util.UUID;
13

  
14
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
15

  
16
/**
17
 * DTO for any CdmBase.
18
 *
19
 * @author a.mueller
20
 * @date 2016-09-21
21
 *
22
 */
23
//might extend CdmBase in future, when a default formatter is available for all CdmBase classes
24
public class EntityDTO<T extends IdentifiableEntity> extends EntityDTOBase<T> {
25

  
26
	public EntityDTO(T entity){
27
	    super(entity);
28
	}
29

  
30
	public EntityDTO(UUID entityUuid, String titleCache){
31
		super(entityUuid, titleCache);
32
	}
33

  
34
    /**
35
     * {@inheritDoc}
36
     */
37
    @Override
38
    public String toString() {
39
        return "(" + cdmEntity.getTitleCache() + "; " + cdmEntity.cdmUuid +  ")";
40
    }
41

  
42

  
43
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/TaxonInContextDTO.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10
package eu.etaxonomy.cdm.api.service.dto;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import eu.etaxonomy.cdm.model.taxon.Synonym;
17
import eu.etaxonomy.cdm.model.taxon.Taxon;
18

  
19
/**
20
 * @author a.mueller
21
 * @date 21.09.2016
22
 *
23
 */
24
public class TaxonInContextDTO {
25
    private UUID classificationUuid;
26
    private UUID taxonNodeUuid;
27
    private UUID taxonUuid;
28
    private String taxonLabel;
29

  
30
    //name
31
    private UUID nameUuid;
32
    private String nameLabel;
33
    private String nameWithoutAuthor;
34
    private UUID rankUuid;
35
    private String rankLabel;
36
    private String genusOrUninomial;
37
    private String infraGenericEpithet;
38
    private String speciesEpithet;
39
    private String infraSpecificEpithet;
40
    private String authorship;
41

  
42
    //sec
43
    private UUID secundumUuid;
44
    private String secundumLabel;
45

  
46
    private List<EntityDTO<Taxon>> children = new ArrayList<>();
47

  
48
    private List<EntityDTO<Synonym>> synonyms = new ArrayList<>();
49

  
50
    private List<MarkedEntityDTO<Taxon>> markedAncestors = new ArrayList<>();
51

  
52

  
53

  
54
//********************* GETTER / SETTER ****************************/
55

  
56
    /**
57
     * @return the classificationUuid
58
     */
59
    public UUID getClassificationUuid() {
60
        return classificationUuid;
61
    }
62

  
63
    /**
64
     * @param classificationUuid the classificationUuid to set
65
     */
66
    public void setClassificationUuid(UUID classificationUuid) {
67
        this.classificationUuid = classificationUuid;
68
    }
69

  
70
    /**
71
     * @param taxonNodeUuid the taxonNodeUuid to set
72
     */
73
    public void setTaxonNodeUuid(UUID taxonNodeUuid) {
74
        this.taxonNodeUuid = taxonNodeUuid;
75
    }
76

  
77
    /**
78
     * @param taxonUuid the taxonUuid to set
79
     */
80
    public void setTaxonUuid(UUID taxonUuid) {
81
        this.taxonUuid = taxonUuid;
82
    }
83

  
84
    /**
85
     * @param nameUuid the nameUuid to set
86
     */
87
    public void setNameUuid(UUID nameUuid) {
88
        this.nameUuid = nameUuid;
89
    }
90

  
91
    /**
92
     * @param rankUuid the rankUuid to set
93
     */
94
    public void setRankUuid(UUID rankUuid) {
95
        this.rankUuid = rankUuid;
96
    }
97

  
98
    /**
99
     * @param rankLabel the rankLabel to set
100
     */
101
    public void setRankLabel(String rankLabel) {
102
        this.rankLabel = rankLabel;
103
    }
104

  
105
    /**
106
     * @param genusOrUninomial the genusOrUninomial to set
107
     */
108
    public void setGenusOrUninomial(String genusOrUninomial) {
109
        this.genusOrUninomial = genusOrUninomial;
110
    }
111

  
112
    /**
113
     * @param infragenericEpithet the infragenericEpithet to set
114
     */
115
    public void setInfraGenericEpithet(String infraGenericEpithet) {
116
        this.infraGenericEpithet = infraGenericEpithet;
117
    }
118

  
119
    /**
120
     * @param speciesEpithet the speciesEpithet to set
121
     */
122
    public void setSpeciesEpithet(String speciesEpithet) {
123
        this.speciesEpithet = speciesEpithet;
124
    }
125

  
126
    /**
127
     * @param infraspecificEpithet the infraspecificEpithet to set
128
     */
129
    public void setInfraSpecificEpithet(String infraSpecificEpithet) {
130
        this.infraSpecificEpithet = infraSpecificEpithet;
131
    }
132

  
133
    /**
134
     * @param authorship the authorship to set
135
     */
136
    public void setAuthorship(String authorship) {
137
        this.authorship = authorship;
138
    }
139

  
140
    /**
141
     * @param secundumUuid the secundumUuid to set
142
     */
143
    public void setSecundumUuid(UUID secundumUuid) {
144
        this.secundumUuid = secundumUuid;
145
    }
146

  
147
    /**
148
     * @param secundumLabel the secundumLabel to set
149
     */
150
    public void setSecundumLabel(String secundumLabel) {
151
        this.secundumLabel = secundumLabel;
152
    }
153

  
154
    /**
155
     * @param children the children to set
156
     */
157
    public void setChildren(List<EntityDTO<Taxon>> children) {
158
        this.children = children;
159
    }
160

  
161

  
162
    /**
163
     * @param markedAncestors the markedAncestors to set
164
     */
165
    public void setMarkedAncestors(List<MarkedEntityDTO<Taxon>> markedAncestors) {
166
        this.markedAncestors = markedAncestors;
167
    }
168

  
169
    /**
170
     * @return the taxonNodeUuid
171
     */
172
    public UUID getTaxonNodeUuid() {
173
        return taxonNodeUuid;
174
    }
175

  
176
    /**
177
     * @return the taxonUuid
178
     */
179
    public UUID getTaxonUuid() {
180
        return taxonUuid;
181
    }
182

  
183
    /**
184
     * @return the nameUuid
185
     */
186
    public UUID getNameUuid() {
187
        return nameUuid;
188
    }
189

  
190
    /**
191
     * @return the rankUuid
192
     */
193
    public UUID getRankUuid() {
194
        return rankUuid;
195
    }
196

  
197
    /**
198
     * @return the rankLabel
199
     */
200
    public String getRankLabel() {
201
        return rankLabel;
202
    }
203

  
204
    /**
205
     * @return the genusOrUninomial
206
     */
207
    public String getGenusOrUninomial() {
208
        return genusOrUninomial;
209
    }
210

  
211
    /**
212
     * @return the infragenericEpithet
213
     */
214
    public String getInfraGenericEpithet() {
215
        return infraGenericEpithet;
216
    }
217

  
218
    /**
219
     * @return the speciesEpithet
220
     */
221
    public String getSpeciesEpithet() {
222
        return speciesEpithet;
223
    }
224

  
225
    /**
226
     * @return the infraspecificEpithet
227
     */
228
    public String getInfraSpecificEpithet() {
229
        return infraSpecificEpithet;
230
    }
231

  
232
    /**
233
     * @return the authorship
234
     */
235
    public String getAuthorship() {
236
        return authorship;
237
    }
238

  
239
    /**
240
     * @return the secundumUuid
241
     */
242
    public UUID getSecundumUuid() {
243
        return secundumUuid;
244
    }
245

  
246
    /**
247
     * @return the secundumLabel
248
     */
249
    public String getSecundumLabel() {
250
        return secundumLabel;
251
    }
252

  
253

  
254
    /**
255
     * @return the taxonLabel
256
     */
257
    public String getTaxonLabel() {
258
        return taxonLabel;
259
    }
260

  
261
    /**
262
     * @param taxonLabel the taxonLabel to set
263
     */
264
    public void setTaxonLabel(String taxonLabel) {
265
        this.taxonLabel = taxonLabel;
266
    }
267

  
268
    /**
269
     * @return the nameLabel
270
     */
271
    public String getNameLabel() {
272
        return nameLabel;
273
    }
274

  
275
    /**
276
     * @param nameLabel the nameLabel to set
277
     */
278
    public void setNameLabel(String nameLabel) {
279
        this.nameLabel = nameLabel;
280
    }
281

  
282
    /**
283
     * @return the nameWithoutAuthor
284
     */
285
    public String getNameWithoutAuthor() {
286
        return nameWithoutAuthor;
287
    }
288

  
289
    /**
290
     * @param nameWithoutAuthor the nameWithoutAuthor to set
291
     */
292
    public void setNameWithoutAuthor(String nameWithoutAuthor) {
293
        this.nameWithoutAuthor = nameWithoutAuthor;
294
    }
295

  
296

  
297
    /**
298
     * @return the children
299
     */
300
    public List<EntityDTO<Taxon>> getChildren() {
301
        return children;
302
    }
303

  
304
    /**
305
     * @return the synonyms
306
     */
307
    public List<EntityDTO<Synonym>> getSynonyms() {
308
        return synonyms;
309
    }
310
    /**
311
     * @param synonyms the synonyms to set
312
     */
313
    public void setSynonyms(List<EntityDTO<Synonym>> synonyms) {
314
        this.synonyms = synonyms;
315
    }
316

  
317
    /**
318
     * @return the markedAncestors
319
     */
320
    public List<MarkedEntityDTO<Taxon>> getMarkedAncestors() {
321
        return markedAncestors;
322
    }
323

  
324
// *************************** ADDER *******************************/
325

  
326
    public void addChild(EntityDTO<Taxon> childDto){
327
        this.children.add(childDto);
328
    }
329

  
330

  
331
    public void addSynonym(EntityDTO<Synonym> synonymDto){
332
        this.synonyms.add(synonymDto);
333
    }
334

  
335
    public void addMarkedAncestor(MarkedEntityDTO<Taxon> markedAncestor){
336
        this.markedAncestors.add(markedAncestor);
337
    }
338

  
339
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)