Search in sources :

Example 6 with QuantitativeDataDto

use of eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto in project cdmlib by cybertaxonomy.

the class DescriptiveDataSetServiceTest method testGetRowWrapper.

// the tesat fails when running in suite because no dataset is available, running the test in eclipse works as expected.
@Ignore
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"), @DataSet(value = "/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"), @DataSet(value = "StructuredDescriptionAggregationTest.xml") })
public void testGetRowWrapper() {
    createDefaultFeatureTree();
    DescriptiveDataSet dataSet = createTestDataset();
    commitAndStartNewTransaction();
    List<RowWrapperDTO<?>> rowWrappers = datasetService.getRowWrapper(dataSet.getUuid(), monitor);
    // There are 4 specimen descriptions and one literature description (taxon association)
    assertTrue(rowWrappers.size() == 5);
    // check rowWrapper
    // specimen_1 2 categorical and 1 quantitative
    List<SpecimenRowWrapperDTO> alpinaSpec1List = rowWrappers.stream().filter(r -> r instanceof SpecimenRowWrapperDTO).map(r -> (SpecimenRowWrapperDTO) r).filter(s -> s.getSpecimenDto().getLabel().equals("alpina specimen1")).collect(Collectors.toList());
    Assert.assertEquals(1, alpinaSpec1List.size());
    SpecimenRowWrapperDTO alpinaSpec1Dto = alpinaSpec1List.get(0);
    // leafColor
    Set<DescriptionElementDto> leafColorElements = alpinaSpec1Dto.getDataValueForFeature(uuidFeatureLeafColor);
    Assert.assertNotNull(leafColorElements);
    Assert.assertTrue(leafColorElements.size() == 1);
    DescriptionElementDto dto = leafColorElements.iterator().next();
    Assert.assertTrue(dto instanceof CategoricalDataDto);
    CategoricalDataDto cDto = (CategoricalDataDto) dto;
    assertTrue("The states should contain one element", cDto.getStates().size() == 1);
    StateDataDto stateData = cDto.getStates().iterator().next();
    assertEquals(uuidLeafColorBlue, stateData.getState().getUuid());
    // leaf length
    Set<DescriptionElementDto> leafLengthElements = alpinaSpec1Dto.getDataValueForFeature(uuidFeatureLeafLength);
    Assert.assertNotNull(leafLengthElements);
    Assert.assertTrue(leafLengthElements.size() == 1);
    dto = leafLengthElements.iterator().next();
    Assert.assertTrue(dto instanceof QuantitativeDataDto);
    QuantitativeDataDto qDto = (QuantitativeDataDto) dto;
    assertTrue("The statistical values should contain one element", qDto.getValues().size() == 1);
    StatisticalMeasurementValueDto statValue = qDto.getValues().iterator().next();
    assertEquals(new BigDecimal("5.0"), statValue.getValue());
    Set<DescriptionElementDto> leafPAElements = alpinaSpec1Dto.getDataValueForFeature(uuidFeatureLeafPA);
    Assert.assertNotNull(leafPAElements);
    Assert.assertTrue(leafPAElements.size() == 1);
    dto = leafPAElements.iterator().next();
    Assert.assertTrue(dto instanceof CategoricalDataDto);
    cDto = (CategoricalDataDto) dto;
    assertTrue("The statistical values should contain one element", cDto.getStates().size() == 1);
    stateData = cDto.getStates().iterator().next();
    assertEquals(State.uuidPresent, stateData.getState().getUuid());
    // taxon descriptions
    List<TaxonRowWrapperDTO> taxonDescList = rowWrappers.stream().filter(r -> r instanceof TaxonRowWrapperDTO).map(r -> (TaxonRowWrapperDTO) r).collect(Collectors.toList());
    Assert.assertEquals(1, taxonDescList.size());
    // .filter(s->s.getTaxonDto().getLabel().equals("alpina specimen1")).collect(Collectors.toList());
    TaxonRowWrapperDTO taxonDto = taxonDescList.get(0);
    leafLengthElements = taxonDto.getDataValueForFeature(uuidFeatureLeafLength);
    Assert.assertNotNull(leafLengthElements);
    Assert.assertTrue(leafLengthElements.size() == 1);
    dto = leafLengthElements.iterator().next();
    Assert.assertTrue(dto instanceof QuantitativeDataDto);
    qDto = (QuantitativeDataDto) dto;
    assertTrue("The statistical values should contain one element", qDto.getValues().size() == 2);
    List<StatisticalMeasurementValueDto> minList = qDto.getValues().stream().filter(vs -> vs.getValue().equals(new BigDecimal("4.5"))).collect(Collectors.toList());
    Assert.assertEquals(1, minList.size());
    TermDto minDtoType = minList.get(0).getType();
    Assert.assertTrue(minDtoType.getUuid().equals(StatisticalMeasure.MIN().getUuid()));
    Assert.assertTrue(minDtoType.getTermType().equals(TermType.StatisticalMeasure));
}
Also used : SpringBeanByType(org.unitils.spring.annotation.SpringBeanByType) TermVocabulary(eu.etaxonomy.cdm.model.term.TermVocabulary) TermDto(eu.etaxonomy.cdm.persistence.dto.TermDto) IProgressMonitor(eu.etaxonomy.cdm.common.monitor.IProgressMonitor) FeatureDto(eu.etaxonomy.cdm.persistence.dto.FeatureDto) StatisticalMeasurementValueDto(eu.etaxonomy.cdm.api.service.dto.StatisticalMeasurementValueDto) CategoricalData(eu.etaxonomy.cdm.model.description.CategoricalData) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) IDescriptionService(eu.etaxonomy.cdm.api.service.IDescriptionService) BigDecimal(java.math.BigDecimal) Logger(org.apache.log4j.Logger) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) Classification(eu.etaxonomy.cdm.model.taxon.Classification) QuantitativeDataDto(eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto) IClassificationService(eu.etaxonomy.cdm.api.service.IClassificationService) DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) DataSet(org.unitils.dbunit.annotation.DataSet) ReferenceFactory(eu.etaxonomy.cdm.model.reference.ReferenceFactory) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) TermNode(eu.etaxonomy.cdm.model.term.TermNode) Set(java.util.Set) StateDataDto(eu.etaxonomy.cdm.api.service.dto.StateDataDto) UUID(java.util.UUID) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) ITaxonNodeService(eu.etaxonomy.cdm.api.service.ITaxonNodeService) IVocabularyService(eu.etaxonomy.cdm.api.service.IVocabularyService) List(java.util.List) IReferenceService(eu.etaxonomy.cdm.api.service.IReferenceService) DescriptionType(eu.etaxonomy.cdm.model.description.DescriptionType) DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) ITermService(eu.etaxonomy.cdm.api.service.ITermService) IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) IDescriptiveDataSetService(eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService) DataSets(org.unitils.dbunit.annotation.DataSets) Reference(eu.etaxonomy.cdm.model.reference.Reference) StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) IndividualsAssociation(eu.etaxonomy.cdm.model.description.IndividualsAssociation) RowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO) ArrayList(java.util.ArrayList) CleanSweepInsertLoadStrategy(eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy) HashSet(java.util.HashSet) TaxonNameFactory(eu.etaxonomy.cdm.model.name.TaxonNameFactory) TermTree(eu.etaxonomy.cdm.model.term.TermTree) State(eu.etaxonomy.cdm.model.description.State) StatisticalMeasurementValue(eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue) Before(org.junit.Before) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Rank(eu.etaxonomy.cdm.model.name.Rank) TaxonRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO) DescriptionElementDto(eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) ICdmRepository(eu.etaxonomy.cdm.api.application.ICdmRepository) CategoricalDataDto(eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto) ITermTreeService(eu.etaxonomy.cdm.api.service.ITermTreeService) TermType(eu.etaxonomy.cdm.model.term.TermType) ITaxonService(eu.etaxonomy.cdm.api.service.ITaxonService) Ignore(org.junit.Ignore) DefaultProgressMonitor(eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor) SpecimenRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO) Feature(eu.etaxonomy.cdm.model.description.Feature) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) StateDataDto(eu.etaxonomy.cdm.api.service.dto.StateDataDto) SpecimenRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO) TaxonRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO) DescriptionElementDto(eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto) QuantitativeDataDto(eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto) RowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO) TaxonRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO) SpecimenRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO) CategoricalDataDto(eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto) BigDecimal(java.math.BigDecimal) TermDto(eu.etaxonomy.cdm.persistence.dto.TermDto) StatisticalMeasurementValueDto(eu.etaxonomy.cdm.api.service.dto.StatisticalMeasurementValueDto) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) Ignore(org.junit.Ignore) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Aggregations

DescriptionBaseDto (eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto)6 QuantitativeDataDto (eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto)6 TermDto (eu.etaxonomy.cdm.persistence.dto.TermDto)6 ArrayList (java.util.ArrayList)6 UUID (java.util.UUID)6 CategoricalDataDto (eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto)5 StatisticalMeasurementValueDto (eu.etaxonomy.cdm.api.service.dto.StatisticalMeasurementValueDto)4 DescriptiveDataSet (eu.etaxonomy.cdm.model.description.DescriptiveDataSet)4 Feature (eu.etaxonomy.cdm.model.description.Feature)4 QuantitativeData (eu.etaxonomy.cdm.model.description.QuantitativeData)4 FeatureDto (eu.etaxonomy.cdm.persistence.dto.FeatureDto)4 DescriptionElementDto (eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto)3 RowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO)3 SpecimenRowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO)3 StateDataDto (eu.etaxonomy.cdm.api.service.dto.StateDataDto)3 TaxonRowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO)3 IProgressMonitor (eu.etaxonomy.cdm.common.monitor.IProgressMonitor)3 CategoricalData (eu.etaxonomy.cdm.model.description.CategoricalData)3 DescriptionBase (eu.etaxonomy.cdm.model.description.DescriptionBase)3 DescriptionType (eu.etaxonomy.cdm.model.description.DescriptionType)3