Project

General

Profile

« Previous | Next » 

Revision 108ef8d8

Added by Katja Luther over 2 years ago

ref #9843: fix taxonnode dto creation and add parent uuid - continue

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/SortableTaxonNodeQueryResult.java
23 23
    protected String taxonTitleCache;
24 24
    protected String nameTitleCache;
25 25
    protected Rank nameRank = Rank.UNKNOWN_RANK();
26
    protected UUID parentNodeUuid;
26 27

  
27 28
    /**Is this the reason
28 29
     * @param taxonNodeUuid
......
31 32
     * @param nameRank {@link Rank.#UNKNOWN_RANK()} will be used in case this is <code>null</code>
32 33
     */
33 34
    public SortableTaxonNodeQueryResult(UUID taxonNodeUuid, Integer taxonNodeId, String taxonTitleCache, String nameTitleCache,
34
            Rank nameRank) {
35
            Rank nameRank, UUID parentNodeUuid) {
35 36
        this.taxonNodeUuid = taxonNodeUuid;
36 37
        this.taxonNodeId = taxonNodeId;
37 38
        this.taxonTitleCache = taxonTitleCache;
......
39 40
        if(nameRank != null){
40 41
            this.nameRank = nameRank;
41 42
        }
43
        this.parentNodeUuid = parentNodeUuid;
42 44
    }
43 45

  
44 46
    /**
......
48 50
     * @param nameRank {@link Rank.#UNKNOWN_RANK()} will be used in case this is <code>null</code>
49 51
     */
50 52
    public SortableTaxonNodeQueryResult(UUID taxonNodeUuid, Integer taxonNodeId, String taxonTitleCache,
51
            Rank nameRank) {
52
        this(taxonNodeUuid, taxonNodeId, taxonTitleCache, null, nameRank);
53
            Rank nameRank, UUID parentNodeUuid) {
54
        this(taxonNodeUuid, taxonNodeId, taxonTitleCache, null, nameRank, parentNodeUuid);
53 55
    }
54 56

  
55
    public SortableTaxonNodeQueryResult(UUID taxonNodeUuid, Integer taxonNodeId, String taxonTitleCache) {
56
        this(taxonNodeUuid, taxonNodeId, taxonTitleCache, null);
57
    public SortableTaxonNodeQueryResult(UUID taxonNodeUuid, Integer taxonNodeId, String taxonTitleCache, UUID parentNodeUuid) {
58
        this(taxonNodeUuid, taxonNodeId, taxonTitleCache, null, parentNodeUuid);
57 59
    }
58 60

  
59 61
    public UUID getTaxonNodeUuid() {
......
62 64
    public void setTaxonNodeUuid(UUID taxonNodeUuid) {
63 65
        this.taxonNodeUuid = taxonNodeUuid;
64 66
    }
67
    /**
68
     * @return the parentNodeUuid
69
     */
70
    public UUID getParentNodeUuid() {
71
        return parentNodeUuid;
72
    }
73

  
74
    /**
75
     * @param parentNodeUuid the parentNodeUuid to set
76
     */
77
    public void setParentNodeUuid(UUID parentNodeUuid) {
78
        this.parentNodeUuid = parentNodeUuid;
79
    }
80

  
65 81
    public Integer getTaxonNodeId() {
66 82
        return taxonNodeId;
67 83
    }
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java
916 916
        return dao.getDescriptiveDataSetDtoByUuid(uuid);
917 917
    }
918 918

  
919
    @Override
920
    public TaxonRowWrapperDTO createTaxonRowWrapper(UUID taxonDescriptionUuid, UUID descriptiveDataSetUuid) {
921
        Classification classification = null;
922
        DescriptionBaseDto description = descriptionService.loadDto(taxonDescriptionUuid);
923

  
924
        DescriptiveDataSet descriptiveDataSet = dao.load(descriptiveDataSetUuid, null);
925
        Optional<TaxonNode> first = descriptiveDataSet.getTaxonSubtreeFilter().stream()
926
                .filter(node->node.getClassification()!=null).findFirst();
927
        Optional<Classification> classificationOptional = first.map(node->node.getClassification());
928
        Set<DescriptionBaseDto> descriptions = new HashSet<>();
929
        TaxonNodeDto nodeDto = null;
930
        if(classificationOptional.isPresent()){
931
            classification = classificationOptional.get();
932
            nodeDto = taxonNodeService.dto(description.getTaxonDto().getUuid(), classification.getUuid());
933
        }
934

  
935
        return new TaxonRowWrapperDTO(description, nodeDto, descriptions);
936
    }
937

  
919 938
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IDescriptiveDataSetService.java
125 125
    public TaxonRowWrapperDTO createTaxonRowWrapper(TaxonDescription taxonDescription, UUID descriptiveDataSetUuid);
126 126

  
127 127
    /**
128
     * Creates a taxon row wrapper object for the given description UUID
129
     * @param taxonDescriptionUUID the taxon description for which the wrapper should be created
130
     * @param descriptiveDataSetUUID the data set it should be used in
131
     * @return the created row wrapper
132
     */
133
    public TaxonRowWrapperDTO createTaxonRowWrapper(UUID taxonDescriptionUuid, UUID descriptiveDataSetUuid);
134

  
135

  
136
    /**
128 137
     * Returns a {@link SpecimenDescription} for a given specimen with corresponding
129 138
     * features according to the {@link DescriptiveDataSet}.<br>
130 139
     * If a description is found that matches all features of the data set this description
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/CategoricalDataDto.java
17 17
import eu.etaxonomy.cdm.model.description.CategoricalData;
18 18
import eu.etaxonomy.cdm.model.description.State;
19 19
import eu.etaxonomy.cdm.model.description.StateData;
20
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
20 21
import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
21 22
import eu.etaxonomy.cdm.persistence.dto.TermDto;
22 23

  
......
31 32

  
32 33
    public CategoricalDataDto (UUID elementUuid, FeatureDto feature, List<StateDataDto> states){
33 34
       super(elementUuid, feature);
34
       this.states = states;
35
       if (states != null){
36
           this.states = states;
37
       }
35 38
    }
36 39

  
37 40
    public CategoricalDataDto(FeatureDto feature){
......
107 110
        states.clear();
108 111
    }
109 112

  
110
    public static String getCategoricalDtoSelect(UUID fromDescription){
111
        String[] result = createSqlParts(fromDescription);
113
    public static String getCategoricalDtoSelect(){
114
        String[] result = createSqlParts();
112 115

  
113 116
        return result[0]+result[1]+result[2] + result[3];
114 117
    }
115 118

  
116
    private static String[] createSqlParts(UUID fromDescription) {
119
    private static String[] createSqlParts() {
117 120
        //featureDto, uuid, states
118 121

  
119 122
        String sqlSelectString = ""
120 123
                + "select a.uuid, "
121 124
                + "feature.uuid, "
122
                + "state.uuid  ";
125
                + "state.uuid,  "
126
                + "state.count, "
127
                + "state.state ";
123 128

  
124 129
        String sqlFromString =   " FROM CategoricalData as a ";
125 130

  
126
        String sqlJoinString =  "LEFT JOIN a.states as state "
131
        String sqlJoinString =  "LEFT JOIN a.stateData as state "
127 132
                + "LEFT JOIN a.feature as feature ";
128 133

  
129
        String sqlWhereString =  "WHERE a.description.uuid like "+ fromDescription;
134
        String sqlWhereString =  " WHERE a.inDescription.uuid = :uuid";
135

  
130 136

  
131 137
        String[] result = new String[4];
132 138
        result[0] = sqlSelectString;
......
136 142
        return result;
137 143
    }
138 144

  
145
    /**
146
     * @param result
147
     * @return
148
     */
149
    public static List<CategoricalDataDto> categoricalDataDtoListFrom(List<Object[]> result) {
150
        List<CategoricalDataDto> dtoResult = new ArrayList<>();
151
        CategoricalDataDto dto = null;
152

  
153
        for (Object[] o: result){
154
            UUID uuid = (UUID)o[0];
155
            UUID featureUuid = (UUID)o[1];
156
            if (dto == null || !dto.getElementUuid().equals(uuid)){
157
                dto = new CategoricalDataDto(uuid, new FeatureDto(featureUuid, null, null, null, null, null, null, true, false, true, null, true, false, null, null, null, null), null);
158
                dtoResult.add(dto);
159
            }
160
            StateDataDto state = new StateDataDto(TermDto.fromTerm((DefinedTermBase)o[4]),(Integer) o[3], uuid);
161
            dto.addState(state);
162
        }
163

  
164

  
165
        return dtoResult;
166

  
167
    }
168

  
139 169

  
140 170
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/DescriptionBaseDto.java
109 109
        return result;
110 110
    }
111 111

  
112
    public static String getDescriptionBaseDtoForTaxonSelect(UUID uuidTaxon ){
113
        String[] result = createSqlPartsForTaxon(uuidTaxon);
112
    public static String getDescriptionBaseDtoForTaxonSelect(){
113
        String[] result = createSqlPartsForTaxon();
114 114

  
115 115
        return result[0]+result[1]+result[2];
116 116
    }
117 117

  
118
    private static String[] createSqlPartsForTaxon(UUID uuidTaxon) {
118
    private static String[] createSqlPartsForTaxon() {
119 119

  
120 120

  
121 121

  
......
135 135

  
136 136
        String sqlJoinString =  " LEFT JOIN a.taxon as t ";
137 137

  
138
        String sqlWhereString = " WHERE a.taxon.uuid like "+ uuidTaxon.toString();
138
        String sqlWhereString = " WHERE a.taxon.uuid = :uuid";
139 139

  
140 140
        String[] result = new String[4];
141 141
        result[0] = sqlSelectString;
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/QuantitativeDataDto.java
9 9
package eu.etaxonomy.cdm.api.service.dto;
10 10

  
11 11
import java.math.BigDecimal;
12
import java.util.ArrayList;
12 13
import java.util.HashSet;
14
import java.util.List;
13 15
import java.util.Set;
14 16
import java.util.UUID;
15 17

  
16 18
import eu.etaxonomy.cdm.model.description.QuantitativeData;
17 19
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
20
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
18 21
import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
19 22
import eu.etaxonomy.cdm.persistence.dto.TermDto;
20 23

  
......
70 73
        this.values = values;
71 74
    }
72 75

  
76
    public void addValue(StatisticalMeasurementValueDto value) {
77
        this.values.add(value);
78
    }
79

  
73 80
    public BigDecimal getSpecificStatisticalValue(UUID typeUUID){
74 81
        BigDecimal result = null;
75 82
        for (StatisticalMeasurementValueDto value : values){
......
85 92
        return measurementUnitDto.getIdInVocabulary();
86 93
    }
87 94

  
95
    public static String getQuantitativeDataDtoSelect(){
96
        String[] result = createSqlParts();
97

  
98
        return result[0]+result[1]+result[2] + result[3];
99
    }
100

  
101
    private static String[] createSqlParts() {
102
        //featureDto, uuid, states
103

  
104
        String sqlSelectString = ""
105
                + "select a.uuid, "
106
                + "feature.uuid, "
107
                + "statVal.uuid,  "
108
                + "statVal.value, "
109
                + "statVal.type, "
110
                + "unit";
111

  
112
        String sqlFromString =   " FROM QuantitativeData as a ";
113

  
114
        String sqlJoinString =  "LEFT JOIN a.statisticalValues as statVal "
115
                + "LEFT JOIN a.feature as feature "
116
                + "LEFT JOIN a.unit as unit ";
117

  
118
        String sqlWhereString =  "WHERE a.inDescription.uuid = :uuid";
119

  
120
        String[] result = new String[4];
121
        result[0] = sqlSelectString;
122
        result[1] = sqlFromString;
123
        result[2] = sqlJoinString;
124
        result[3] = sqlWhereString;
125
        return result;
126
    }
127

  
128
    /**
129
     * @param result
130
     * @return
131
     */
132
    public static List<QuantitativeDataDto> quantitativeDataDtoListFrom(List<Object[]> result) {
133
        List<QuantitativeDataDto> dtoResult = new ArrayList<>();
134
        QuantitativeDataDto dto = null;
135

  
136
        for (Object[] o: result){
137
            UUID uuid = (UUID)o[0];
138
            UUID featureUuid = (UUID)o[1];
139
            if (dto == null || !dto.getElementUuid().equals(uuid)){
140
                dto = new QuantitativeDataDto(uuid, new FeatureDto(featureUuid, null, null, null, null, null, null, true, false, true, null, true, false, null, null, null, null));
141
                dtoResult.add(dto);
142
            }
143
            StatisticalMeasurementValueDto statVal = new StatisticalMeasurementValueDto(TermDto.fromTerm((DefinedTermBase)o[4]),(BigDecimal)o[3], (UUID)o[2]) ;
144
            dto.addValue(statVal);
145
        }
146

  
147

  
148
        return dtoResult;
149

  
150
    }
151

  
88 152

  
89 153
}

Also available in: Unified diff