Project

General

Profile

Revision 19ef2a42

ID19ef2a42eb8e032460b8daf91e004ad0de8054eb
Parent 1d5f625c
Child 9f1aa368

Added by Andreas Müller almost 3 years ago

fix #6066 Implement doPageChildNodes with doSynonyms

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TaxonNodeDto.java
12 12
import java.util.List;
13 13
import java.util.UUID;
14 14

  
15
import eu.etaxonomy.cdm.model.taxon.Synonym;
16
import eu.etaxonomy.cdm.model.taxon.Taxon;
15 17
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
16 18
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
17 19

  
......
22 24
 */
23 25
public class TaxonNodeDto {
24 26

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

  
26 33
    /**
27 34
     * The TaxonNode uuid
......
69 76
     */
70 77
    private final String rankLabel;
71 78

  
79
    private final TaxonStatus status;
80

  
72 81
    /**
73 82
     * @param taxonNode
74 83
     */
75 84
    public TaxonNodeDto(TaxonNode taxonNode) {
76 85
        uuid = taxonNode.getUuid();
77 86
        taxonomicChildrenCount = taxonNode.getCountChildren();
78
        secUuid = taxonNode.getTaxon().getSec().getUuid();
79
        taxonUuid = taxonNode.getTaxon().getUuid();
80
        titleCache = taxonNode.getTaxon().getName().getTitleCache();
81
        taggedTitle = taxonNode.getTaxon().getName().getTaggedName();
82
        unplaced = taxonNode.getTaxon().isUnplaced();
83
        excluded = taxonNode.getTaxon().isExcluded();
84
        rankLabel = taxonNode.getTaxon().getName().getRank().getLabel();
87
        Taxon taxon = taxonNode.getTaxon();
88
        secUuid = taxon.getSec().getUuid();
89
        taxonUuid = taxon.getUuid();
90
        titleCache = taxon.getName().getTitleCache();
91
        taggedTitle = taxon.getName().getTaggedName();
92
        unplaced = taxon.isUnplaced();
93
        excluded = taxon.isExcluded();
94
        rankLabel = taxon.getName().getRank().getLabel();
95
        status = TaxonStatus.Accepted;
96
    }
97

  
98
    /**
99
     * @param taxonNode
100
     */
101
    public TaxonNodeDto(Synonym synonym, boolean isHomotypic) {
102
        uuid = null;
103
        taxonomicChildrenCount = 0;
104
        secUuid = synonym.getSec().getUuid();
105
        taxonUuid = synonym.getUuid();
106
        titleCache = synonym.getName().getTitleCache();
107
        taggedTitle = synonym.getName().getTaggedName();
108
        unplaced = false;
109
        excluded = false;
110
        rankLabel = synonym.getName().getRank().getLabel();
111
        status = isHomotypic ? TaxonStatus.SynonymObjective : TaxonStatus.Synonym;
85 112
    }
86 113

  
87 114
    /**
......
147 174
        return rankLabel;
148 175
    }
149 176

  
177
    /**
178
     * @return the status
179
     */
180
    public TaxonStatus getStatus() {
181
        return status;
182
    }
183

  
150 184

  
151 185
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonNodeController.java
10 10

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

  
13
import io.swagger.annotations.Api;
14

  
15 13
import java.io.IOException;
16 14
import java.util.UUID;
17 15

  
......
30 28
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
31 29
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
32 30
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
31
import io.swagger.annotations.Api;
33 32

  
34 33
/**
35 34
 *
......
42 41
@RequestMapping(value = {"/taxonNode/{uuid}"})
43 42
public class TaxonNodeController extends AbstractController<TaxonNode, ITaxonNodeService> {
44 43

  
45

  
46
    /* (non-Javadoc)
47
     * @see eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy.cdm.api.service.IService)
48
     */
49 44
    @Override
50 45
    @Autowired
51 46
    public void setService(ITaxonNodeService service) {
......
89 84
            @RequestParam(value = "pageNumber", required = false) Integer pageIndex,
90 85
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
91 86
            @RequestParam(value="sortMode", defaultValue="AlphabeticalOrder") NodeSortMode sortMode,
87
            @RequestParam(value="doSynonyms", defaultValue="false") Boolean doSynonyms,
92 88
            HttpServletResponse response
93 89
            ) throws IOException {
94 90

  
95 91
        PagerParameters pagerParameters = new PagerParameters(pageSize, pageIndex);
96 92
        pagerParameters.normalizeAndValidate(response);
97 93

  
98
        return service.pageChildNodesDTOs(uuid, false, sortMode, pagerParameters.getPageSize(), pagerParameters.getPageIndex());
94
        return service.pageChildNodesDTOs(uuid, false, doSynonyms, sortMode, pagerParameters.getPageSize(), pagerParameters.getPageIndex());
99 95
    }
100 96
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITaxonNodeService.java
49 49
     *
50 50
     * @param taxonNode
51 51
     * @param recursive
52
     * @param doSynonyms if true also synonyms are returned as children
52 53
     * @param sortMode
53 54
     * @param pageSize
54 55
     * @param pageIndex
55 56
     *
56 57
     * @return List<TaxonNodeDto>
57 58
     */
58
    public Pager<TaxonNodeDto> pageChildNodesDTOs(UUID taxonNodeUuid, boolean recursive, NodeSortMode sortMode, Integer pageSize, Integer pageIndex);
59
    public Pager<TaxonNodeDto> pageChildNodesDTOs(UUID taxonNodeUuid, boolean recursive,
60
            boolean doSynonyms, NodeSortMode sortMode,
61
            Integer pageSize, Integer pageIndex);
59 62

  
60 63
    public TaxonNodeDto parentDto(UUID taxonNodeUuid);
61 64

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java
35 35
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
36 36
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
37 37
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
38
import eu.etaxonomy.cdm.model.common.CdmBase;
38 39
import eu.etaxonomy.cdm.model.common.DefinedTerm;
39 40
import eu.etaxonomy.cdm.model.description.TaxonDescription;
40 41
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
41 42
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
42 43
import eu.etaxonomy.cdm.model.reference.Reference;
43 44
import eu.etaxonomy.cdm.model.taxon.Classification;
45
import eu.etaxonomy.cdm.model.taxon.HomotypicGroupTaxonComparator;
44 46
import eu.etaxonomy.cdm.model.taxon.Synonym;
45 47
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
46 48
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
......
107 109
     * {@inheritDoc}
108 110
     */
109 111
    @Override
110
    public Pager<TaxonNodeDto> pageChildNodesDTOs(UUID taxonNodeUuid, boolean recursive, NodeSortMode sortMode,
112
    public Pager<TaxonNodeDto> pageChildNodesDTOs(UUID taxonNodeUuid, boolean recursive,
113
            boolean doSynonyms, NodeSortMode sortMode,
111 114
            Integer pageSize, Integer pageIndex) {
112 115

  
116
        TaxonNode parentNode = dao.load(taxonNodeUuid);
113 117

  
114
        List<TaxonNode> childNodes = loadChildNodesOfTaxonNode(dao.load(taxonNodeUuid), null, recursive, sortMode);
118
        List<CdmBase> allRecords = new ArrayList<>();
119

  
120
        //acceptedTaxa
121
        List<TaxonNode> childNodes = loadChildNodesOfTaxonNode(parentNode, null, recursive, sortMode);
122
        allRecords.addAll(childNodes);
123

  
124
        //add synonyms if pager is not yet full synonyms
125
        List<Synonym> synList = new ArrayList<>(parentNode.getTaxon().getSynonyms());
126
        Collections.sort(synList, new HomotypicGroupTaxonComparator(null));
127
        //TODO: test sorting
128

  
129
        allRecords.addAll(synList);
115 130

  
116
        if (sortMode != null){
117
            Comparator<TaxonNode> comparator = sortMode.newComparator();
118
            Collections.sort(childNodes, comparator);
119
        }
120 131

  
121 132
        List<TaxonNodeDto> dtos = new ArrayList<>(pageSize);
122 133
        int start = PagerUtils.startFor(pageSize, pageIndex);
123 134
        int limit = PagerUtils.limitFor(pageSize);
124
        Long totalCount = Long.valueOf(childNodes.size());
135
        Long totalCount = Long.valueOf(allRecords.size());
136

  
125 137
        if(PagerUtils.hasResultsInRange(totalCount, pageIndex, pageSize)) {
138
            TaxonNameBase<?,?> parentName = null;
139

  
126 140
            for(int i = start; i < start + limit; i++) {
127
                dtos.add(new TaxonNodeDto(childNodes.get(i)));
141
                CdmBase record = allRecords.get(i);
142

  
143
                if (record.isInstanceOf(TaxonNode.class)){
144
                    dtos.add(new TaxonNodeDto(CdmBase.deproxy(record, TaxonNode.class)));
145
                }else if (record.isInstanceOf(Synonym.class)){
146
                    Synonym synonym = CdmBase.deproxy(record, Synonym.class);
147
                    parentName = parentName == null? parentNode.getTaxon().getName(): parentName;
148
                    boolean isHomotypic = synonym.getName().isHomotypic(parentName);
149
                    dtos.add(new TaxonNodeDto(synonym, isHomotypic));
150
                }
128 151
            }
129 152
        }
130 153

  
131

  
132 154
        return new DefaultPagerImpl<TaxonNodeDto>(pageIndex, totalCount, pageSize , dtos);
133 155
    }
134 156

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)