Project

General

Profile

Revision 7043c4ee

ID7043c4ee44153f6930099c76b88398f78d24b746
Parent 83efeb94
Child db3f7e5d

Added by Andreas Müller 2 months ago

ref #9795 add literature descriptions to matrix aggregation

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/description/StructuredDescriptionAggregation.java
220 220
            ResultHolder resultHolder,
221 221
            Set<TaxonDescription> excludedDescriptions) {
222 222
        StructuredDescriptionResultHolder descriptiveResultHolder = (StructuredDescriptionResultHolder)resultHolder;
223
        addDescriptionElement(descriptiveResultHolder, getSpecimenDescriptions(taxon, dataSet));
223
        Set<SpecimenDescription> specimenDescriptions = getSpecimenDescriptions(taxon, dataSet);
224
        addDescriptionElement(descriptiveResultHolder, specimenDescriptions);
225
        Set<TaxonDescription> literatureDescriptions = getLiteratureDescriptions(taxon, dataSet);
226
        addDescriptionElement(descriptiveResultHolder, literatureDescriptions);
227
        //TODO add defaultDescriptions
228

  
224 229
    }
225 230

  
226 231
    private void addDescriptionElement(StructuredDescriptionResultHolder descriptiveResultHolder,
......
349 354
        return result;
350 355
    }
351 356

  
357
    private Set<TaxonDescription> getLiteratureDescriptions(Taxon taxon, DescriptiveDataSet dataSet) {
358
        Set<TaxonDescription> result = new HashSet<>();
359
        //TODO performance: use DTO service to retrieve specimen descriptions without initializing all taxon descriptions
360
        for(TaxonDescription taxonDescription : taxon.getDescriptions()){
361
            if(dataSet.getDescriptions().contains(taxonDescription)
362
                    && taxonDescription.getTypes().stream().anyMatch(type->type.equals(DescriptionType.SECONDARY_DATA))
363
                    && taxonDescription.getTypes().stream().noneMatch(type->type.equals(DescriptionType.CLONE_FOR_SOURCE)) ){
364
                result.add(taxonDescription);
365
            }
366
        }
367
        return result;
368
    }
369

  
352 370
    private QuantitativeData aggregateSingleQuantitativeData(QuantitativeData sourceQd){
353 371
        QuantitativeData aggQD = QuantitativeData.NewInstance(sourceQd.getFeature());
354 372
        Set<BigDecimal> exactValues = sourceQd.getExactValues();
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/description/StructuredDescriptionAggregationTest.java
18 18
import org.apache.log4j.Logger;
19 19
import org.junit.Assert;
20 20
import org.junit.Before;
21
import org.junit.Ignore;
22 21
import org.junit.Test;
23 22
import org.unitils.dbunit.annotation.DataSet;
24 23
import org.unitils.dbunit.annotation.DataSets;
......
41 40
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
42 41
import eu.etaxonomy.cdm.model.common.CdmBase;
43 42
import eu.etaxonomy.cdm.model.description.CategoricalData;
43
import eu.etaxonomy.cdm.model.description.DescriptionBase;
44 44
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
45 45
import eu.etaxonomy.cdm.model.description.DescriptionType;
46 46
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
......
73 73
 * @author a.mueller
74 74
 * @since 21.11.2019
75 75
 */
76
@Ignore   //preliminary ignore as it does not always work (depending on other tests)
76
//preliminary ignore as it does not always work (depending on other tests)
77 77
public class StructuredDescriptionAggregationTest extends CdmTransactionalIntegrationTest {
78 78

  
79 79
    @SuppressWarnings("unused")
......
254 254
        UpdateResult result = engine.invoke(config, repository);
255 255
        Assert.assertEquals(UpdateResult.Status.OK, result.getStatus());
256 256
        testAggregatedDescription();
257

  
258
        dataSet = datasetService.find(dataSet.getId());
259
        addLiterature(dataSet);
260
        commitAndStartNewTransaction();
261

  
262
        result = engine.invoke(config, repository);
263
        Assert.assertEquals(UpdateResult.Status.OK, result.getStatus());
264
        testAggregatedDescriptionWithLiterature();
265

  
266
    }
267

  
268
    private void addLiterature(DescriptiveDataSet dataSet) {
269

  
270
        //literature description
271
        Taxon taxon = (Taxon)taxonService.find(T_LAPSANA_COMMUNIS_ALPINA_UUID);
272
        TaxonDescription literatureDescription = TaxonDescription.NewInstance(taxon);
273
        literatureDescription.addType(DescriptionType.SECONDARY_DATA);
274
        addQuantitativeData(literatureDescription, uuidFeatureLeafLength, new BigDecimal("4.5"), new BigDecimal("6.5"));
275
        addCategoricalData(literatureDescription, uuidFeatureLeafColor, uuidLeafColorBlue);
276
        dataSet.addDescription(literatureDescription);
257 277
    }
258 278

  
259 279
    private void testAggregatedDescription() {
......
294 314
                new BigDecimal("12.0"), new BigDecimal("8.0"), aggrDescLapsana);
295 315
    }
296 316

  
317
    private void testAggregatedDescriptionWithLiterature() {
318
        Taxon taxLapsanaCommunisAlpina = (Taxon)taxonService.find(T_LAPSANA_COMMUNIS_ALPINA_UUID);
319
        TaxonDescription aggrDescLapsanaCommunisAlpina = testTaxonDescriptions(taxLapsanaCommunisAlpina, 3);
320
        testState(testCategoricalData(uuidFeatureLeafPA, 1, aggrDescLapsanaCommunisAlpina), State.uuidPresent, 2);
321
        List<StateData> sdAlpinaLeafColor = testCategoricalData(uuidFeatureLeafColor, 1, aggrDescLapsanaCommunisAlpina);
322
        testState(sdAlpinaLeafColor, uuidLeafColorBlue, 3);
323
        testState(sdAlpinaLeafColor, uuidLeafColorYellow, 0);
324
        testQuantitativeData(uuidFeatureLeafLength, null, new BigDecimal("4.5"),
325
                new BigDecimal("7.0"), null, aggrDescLapsanaCommunisAlpina);
326

  
327
        Taxon taxLapsanaCommunisAdenophora = (Taxon)taxonService.find(T_LAPSANA_COMMUNIS_ADENOPHORA_UUID);
328
        TaxonDescription aggrDescLapsanaCommunisAdenophora = testTaxonDescriptions(taxLapsanaCommunisAdenophora, 3);
329
        testState(testCategoricalData(uuidFeatureLeafPA, 1, aggrDescLapsanaCommunisAdenophora), State.uuidPresent, 1);
330
        List<StateData> sdAdenophoraLeafColor = testCategoricalData(uuidFeatureLeafColor, 1, aggrDescLapsanaCommunisAdenophora);
331
        testState(sdAdenophoraLeafColor, uuidLeafColorBlue, 0);
332
        testState(sdAdenophoraLeafColor, uuidLeafColorYellow, 1);
333
        testQuantitativeData(uuidFeatureLeafLength, new BigDecimal("1"), new BigDecimal("12.0"),
334
                new BigDecimal("12.0"), new BigDecimal("12.0"), aggrDescLapsanaCommunisAdenophora);
335

  
336
        Taxon taxLapsanaCommunis = (Taxon)taxonService.find(T_LAPSANA_COMMUNIS_UUID);
337
        TaxonDescription aggrDescLapsanaCommunis = testTaxonDescriptions(taxLapsanaCommunis, 3);
338
        testState(testCategoricalData(uuidFeatureLeafPA, 1, aggrDescLapsanaCommunis), State.uuidPresent, 3);
339
        List<StateData> sdCommunisLeafColor = testCategoricalData(uuidFeatureLeafColor, 2, aggrDescLapsanaCommunis);
340
        testState(sdCommunisLeafColor, uuidLeafColorBlue, 3);
341
        testState(sdCommunisLeafColor, uuidLeafColorYellow, 1);
342
        testQuantitativeData(uuidFeatureLeafLength, null, new BigDecimal("4.5"),
343
                new BigDecimal("12.0"), null, aggrDescLapsanaCommunis);
344

  
345
        Taxon taxLapsana = (Taxon)taxonService.find(T_LAPSANA_UUID);
346
        TaxonDescription aggrDescLapsana = testTaxonDescriptions(taxLapsana, 3);
347
        testState(testCategoricalData(uuidFeatureLeafPA, 1, aggrDescLapsana), State.uuidPresent, 3);
348
        List<StateData> sdLapsanLeafColor = testCategoricalData(uuidFeatureLeafColor, 2, aggrDescLapsana);
349
        testState(sdLapsanLeafColor, uuidLeafColorBlue, 3);
350
        testState(sdLapsanLeafColor, uuidLeafColorYellow, 1);
351
        testQuantitativeData(uuidFeatureLeafLength, null, new BigDecimal("4.5"),
352
                new BigDecimal("12.0"), null, aggrDescLapsana);
353
    }
354

  
297 355
    private StructuredDescriptionAggregationConfiguration createConfig(DescriptiveDataSet dataSet) {
298 356
        TaxonNodeFilter filter = TaxonNodeFilter.NewSubtreeInstance(TN_LAPSANA_UUID);
299 357
        StructuredDescriptionAggregationConfiguration config =
......
388 446
        Assert.assertEquals(stateUuid, stateData.getState().getUuid());
389 447
    }
390 448

  
391
    private void addQuantitativeData(SpecimenDescription specDesc, UUID uuidFeature, StatisticalMeasure type, BigDecimal value) {
449
    private void addQuantitativeData(DescriptionBase<?> desc, UUID uuidFeature, StatisticalMeasure type, BigDecimal value) {
392 450
        Feature feature = (Feature)termService.find(uuidFeature);
393 451
        QuantitativeData qd = QuantitativeData.NewInstance(feature);
394 452
        StatisticalMeasurementValue smv = StatisticalMeasurementValue.NewInstance(type, value);
395 453
        qd.addStatisticalValue(smv);
396
        specDesc.addElement(qd);
454
        desc.addElement(qd);
455
    }
456

  
457
    private void addQuantitativeData(DescriptionBase<?> desc, UUID uuidFeature, BigDecimal min, BigDecimal max) {
458
        Feature feature = (Feature)termService.find(uuidFeature);
459
        QuantitativeData qd = QuantitativeData.NewInstance(feature);
460
        StatisticalMeasurementValue smv = StatisticalMeasurementValue.NewInstance(StatisticalMeasure.MIN(), min);
461
        qd.addStatisticalValue(smv);
462
        smv = StatisticalMeasurementValue.NewInstance(StatisticalMeasure.MAX(), max);
463
        qd.addStatisticalValue(smv);
464
        desc.addElement(qd);
397 465
    }
398 466

  
399
    private void addCategoricalData(SpecimenDescription specDesc, UUID featureUuid, UUID stateUUID) {
467
    private void addCategoricalData(DescriptionBase<?> desc, UUID featureUuid, UUID stateUUID) {
400 468
        Feature feature = (Feature)termService.find(featureUuid);
401 469
        State state = (State)termService.find(stateUUID);
402 470
        CategoricalData cd = CategoricalData.NewInstance(state, feature);
403
        specDesc.addElement(cd);
471
        desc.addElement(cd);
404 472
    }
405 473

  
406 474
    private SpecimenDescription createSpecimenDescription(DescriptiveDataSet dataSet, UUID taxonUuid, String specLabel ) {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)