use of eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO in project cdmlib by cybertaxonomy.
the class DescriptiveDataSetService method createSpecimenRowWrapper.
private SpecimenRowWrapperDTO createSpecimenRowWrapper(DescriptionBaseDto description, UUID taxonNodeUuid, UUID datasetUuid) {
TaxonNodeDto taxonNode = taxonNodeService.dto(taxonNodeUuid);
DescriptiveDataSetBaseDto descriptiveDataSet = getDescriptiveDataSetDtoByUuid(datasetUuid);
// UuidAndTitleCache<SpecimenOrObservationBase> specimen = description.getSpecimenDto();
SpecimenOrObservationBase specimen = occurrenceService.find(description.getSpecimenDto().getUuid());
// supplemental information
if (taxonNode == null) {
taxonNode = findTaxonNodeForDescription(description, descriptiveDataSet);
}
FieldUnit fieldUnit = null;
String identifier = null;
NamedArea country = null;
if (taxonNode == null) {
return null;
}
// taxon node was found
// get field unit
Collection<FieldUnit> fieldUnits = occurrenceService.findFieldUnits(specimen.getUuid(), Arrays.asList(new String[] { "gatheringEvent", "gatheringEvent.country" }));
if (fieldUnits.size() > 1) {
// $NON-NLS-1$
logger.error("More than one or no field unit found for specimen");
return null;
} else {
if (fieldUnits.size() > 0) {
fieldUnit = fieldUnits.iterator().next();
}
}
// get identifier
identifier = occurrenceService.getMostSignificantIdentifier(specimen.getUuid());
// get country
if (fieldUnit != null && fieldUnit.getGatheringEvent() != null) {
country = fieldUnit.getGatheringEvent().getCountry();
}
// get default taxon description
// TaxonDescription defaultTaxonDescription = findDefaultDescription(description.getUuid(), descriptiveDataSet.getUuid());
DescriptionBaseDto defaultTaxonDescription = recurseDefaultDescription(taxonNode, descriptiveDataSet);
TaxonRowWrapperDTO taxonRowWrapper = defaultTaxonDescription != null ? createTaxonRowWrapper(defaultTaxonDescription.getDescriptionUuid(), descriptiveDataSet.getUuid()) : null;
// use description not specimen for specimenRow
SpecimenRowWrapperDTO specimenRowWrapperDTO = new SpecimenRowWrapperDTO(description, SpecimenOrObservationDTOFactory.fromEntity(specimen), specimen.getRecordBasis(), taxonNode, fieldUnit, identifier, country);
specimenRowWrapperDTO.setDefaultDescription(taxonRowWrapper);
return specimenRowWrapperDTO;
}
use of eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO in project cdmlib by cybertaxonomy.
the class DescriptiveDataSetService method createTaxonRowWrapper.
@Override
public TaxonRowWrapperDTO createTaxonRowWrapper(DescriptionBaseDto description, UUID descriptiveDataSetUuid) {
Classification classification = null;
DescriptiveDataSet descriptiveDataSet = dao.load(descriptiveDataSetUuid, null);
Optional<TaxonNode> first = descriptiveDataSet.getTaxonSubtreeFilter().stream().filter(node -> node.getClassification() != null).findFirst();
Optional<Classification> classificationOptional = first.map(node -> node.getClassification());
Set<DescriptionBaseDto> descriptions = new HashSet<>();
TaxonNodeDto nodeDto = null;
if (classificationOptional.isPresent()) {
classification = classificationOptional.get();
nodeDto = taxonNodeService.dto(description.getTaxonDto().getUuid(), classification.getUuid());
}
return new TaxonRowWrapperDTO(description, nodeDto, descriptions);
}
use of eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO 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