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;
}
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);
}
}
}
}
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));
}
Aggregations