Search in sources :

Example 1 with RowWrapperDTO

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

the class DescriptiveDataSetService method getRowWrapper.

@Override
public List<RowWrapperDTO<?>> getRowWrapper(UUID descriptiveDataSetUuid, IProgressMonitor monitor) {
    DescriptiveDataSetBaseDto datasetDto = dao.getDescriptiveDataSetDtoByUuid(descriptiveDataSetUuid);
    // DescriptiveDataSet descriptiveDataSet = load(descriptiveDataSetUuid);
    monitor.beginTask("Load row wrapper", datasetDto.getDescriptionUuids().size());
    List<RowWrapperDTO<?>> wrappers = new ArrayList<>();
    Set<UUID> descriptions = datasetDto.getDescriptionUuids();
    for (UUID description : descriptions) {
        if (monitor.isCanceled()) {
            return new ArrayList<>();
        }
        DescriptionBaseDto descDto = descriptionService.loadDto(description);
        RowWrapperDTO<?> rowWrapper = null;
        if (descDto.getTaxonDto() != null && (descDto.getTypes().contains(DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION) || descDto.getTypes().contains(DescriptionType.AGGREGATED_STRUC_DESC) || descDto.getTypes().contains(DescriptionType.SECONDARY_DATA))) {
            rowWrapper = createTaxonRowWrapper(descDto, datasetDto.getUuid());
        } else if (descDto.getSpecimenDto() != null && (descDto.getTypes() == null || !descDto.getTypes().contains(DescriptionType.CLONE_FOR_SOURCE))) {
            rowWrapper = createSpecimenRowWrapper(descDto, descriptiveDataSetUuid);
        }
        if (rowWrapper != null) {
            wrappers.add(rowWrapper);
        }
        monitor.worked(1);
    }
    return wrappers;
}
Also used : DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) ArrayList(java.util.ArrayList) UUID(java.util.UUID) DescriptiveDataSetBaseDto(eu.etaxonomy.cdm.persistence.dto.DescriptiveDataSetBaseDto) RowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO) TaxonRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO) SpecimenRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO)

Example 2 with RowWrapperDTO

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

the class DescriptiveDataSetServiceTest method testAddQuantitativeData.

// the test currently does not run in suite due to exception during descriptionService.mergeDescriptions(descToUpdate, dataSet.getUuid());
@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 testAddQuantitativeData() {
    createDefaultFeatureTree();
    DescriptiveDataSet dataSet = createTestDataset();
    commitAndStartNewTransaction();
    List<RowWrapperDTO<?>> result = datasetService.getRowWrapper(dataSet.getUuid(), monitor);
    List<DescriptionBaseDto> descToUpdate = new ArrayList<>();
    UUID updatedDescription = null;
    int elementCount = 0;
    for (RowWrapperDTO<?> row : result) {
        if (row instanceof SpecimenRowWrapperDTO) {
            SpecimenRowWrapperDTO specimen = (SpecimenRowWrapperDTO) row;
            DescriptionBaseDto descDto = specimen.getDescription();
            elementCount = descDto.getElements().size();
            Feature feature = (Feature) termService.find(uuidFeatureLeafLength);
            QuantitativeDataDto quantDto = new QuantitativeDataDto(FeatureDto.fromFeature(feature));
            TermDto typeDto = new TermDto(StatisticalMeasure.EXACT_VALUE().getUuid(), null, StatisticalMeasure.EXACT_VALUE().getTermType(), StatisticalMeasure.EXACT_VALUE().getPartOf() != null ? StatisticalMeasure.EXACT_VALUE().getPartOf().getUuid() : null, StatisticalMeasure.EXACT_VALUE().getKindOf() != null ? StatisticalMeasure.EXACT_VALUE().getKindOf().getUuid() : null, StatisticalMeasure.EXACT_VALUE().getVocabulary() != null ? StatisticalMeasure.EXACT_VALUE().getVocabulary().getUuid() : null, null, StatisticalMeasure.EXACT_VALUE().getIdInVocabulary(), StatisticalMeasure.EXACT_VALUE().getTitleCache());
            StatisticalMeasurementValueDto statValue = new StatisticalMeasurementValueDto(typeDto, new BigDecimal("4.5"), null);
            Set<StatisticalMeasurementValueDto> values = new HashSet<>();
            values.add(statValue);
            quantDto.setValues(values);
            descDto.addElement(quantDto);
            descToUpdate.add(descDto);
            updatedDescription = descDto.getDescriptionUuid();
        }
    }
    commitAndStartNewTransaction();
    descriptionService.mergeDescriptions(descToUpdate, dataSet.getUuid());
    commitAndStartNewTransaction();
    DescriptionBase<?> description = descriptionService.load(updatedDescription);
    assertEquals(description.getElements().size(), elementCount + 1);
    for (Object el : description.getElements()) {
        if (el instanceof QuantitativeData) {
            QuantitativeData descEl = (QuantitativeData) el;
            if (descEl.getFeature().getUuid().equals(uuidFeatureLeafLength)) {
                assertEquals(descEl.getExactValues().size(), 1);
            }
        }
    }
}
Also used : DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) SpecimenRowWrapperDTO(eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO) ArrayList(java.util.ArrayList) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) 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) Feature(eu.etaxonomy.cdm.model.description.Feature) TermDto(eu.etaxonomy.cdm.persistence.dto.TermDto) BigDecimal(java.math.BigDecimal) StatisticalMeasurementValueDto(eu.etaxonomy.cdm.api.service.dto.StatisticalMeasurementValueDto) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) UUID(java.util.UUID) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Example 3 with RowWrapperDTO

use of eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO 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)3 RowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO)3 SpecimenRowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO)3 TaxonRowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO)3 QuantitativeDataDto (eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto)2 StatisticalMeasurementValueDto (eu.etaxonomy.cdm.api.service.dto.StatisticalMeasurementValueDto)2 DescriptiveDataSet (eu.etaxonomy.cdm.model.description.DescriptiveDataSet)2 Feature (eu.etaxonomy.cdm.model.description.Feature)2 QuantitativeData (eu.etaxonomy.cdm.model.description.QuantitativeData)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 ICdmRepository (eu.etaxonomy.cdm.api.application.ICdmRepository)1 IClassificationService (eu.etaxonomy.cdm.api.service.IClassificationService)1 IDescriptionService (eu.etaxonomy.cdm.api.service.IDescriptionService)1 IDescriptiveDataSetService (eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService)1 IReferenceService (eu.etaxonomy.cdm.api.service.IReferenceService)1 ITaxonNodeService (eu.etaxonomy.cdm.api.service.ITaxonNodeService)1 ITaxonService (eu.etaxonomy.cdm.api.service.ITaxonService)1 ITermService (eu.etaxonomy.cdm.api.service.ITermService)1 ITermTreeService (eu.etaxonomy.cdm.api.service.ITermTreeService)1