use of eu.etaxonomy.cdm.persistence.dto.FeatureDto in project cdmlib by cybertaxonomy.
the class DescriptionServiceImpl method loadDtos.
@Override
public List<DescriptionBaseDto> loadDtos(Set<UUID> descriptionUuids) {
String sqlSelect = DescriptionBaseDto.getDescriptionBaseDtoSelect();
Query query = getSession().createQuery(sqlSelect);
query.setParameterList("uuid", descriptionUuids);
@SuppressWarnings("unchecked") List<Object[]> result = query.list();
List<DescriptionBaseDto> list = DescriptionBaseDto.descriptionBaseDtoListFrom(result);
for (DescriptionBaseDto dto : list) {
// get categorical data
sqlSelect = CategoricalDataDto.getCategoricalDtoSelect();
query = getSession().createQuery(sqlSelect);
query.setParameter("uuid", dto.getDescriptionUuid());
@SuppressWarnings("unchecked") List<Object[]> resultCat = query.list();
List<CategoricalDataDto> listCategorical = CategoricalDataDto.categoricalDataDtoListFrom(resultCat);
List<UUID> featureUuids = new ArrayList<>();
for (CategoricalDataDto catDto : listCategorical) {
featureUuids.add(catDto.getFeatureUuid());
}
Map<UUID, TermDto> featureDtos = termService.findFeatureByUUIDsAsDtos(featureUuids);
for (CategoricalDataDto catDto : listCategorical) {
FeatureDto featuredto = (FeatureDto) featureDtos.get(catDto.getFeatureUuid());
catDto.setFeatureDto(featuredto);
}
dto.getElements().addAll(listCategorical);
// get quantitative data
sqlSelect = QuantitativeDataDto.getQuantitativeDataDtoSelect();
query = getSession().createQuery(sqlSelect);
query.setParameter("uuid", dto.getDescriptionUuid());
@SuppressWarnings("unchecked") List<Object[]> resultQuant = query.list();
List<QuantitativeDataDto> listQuant = QuantitativeDataDto.quantitativeDataDtoListFrom(resultQuant);
dto.getElements().addAll(listQuant);
}
return list;
}
use of eu.etaxonomy.cdm.persistence.dto.FeatureDto in project cdmlib by cybertaxonomy.
the class CategoricalDataDto method categoricalDataDtoListFrom.
/**
* @param result
* @return
*/
public static List<CategoricalDataDto> categoricalDataDtoListFrom(List<Object[]> result) {
List<CategoricalDataDto> dtoResult = new ArrayList<>();
CategoricalDataDto dto = null;
for (Object[] o : result) {
UUID uuid = (UUID) o[0];
UUID featureUuid = (UUID) o[1];
if (dto == null || !dto.getElementUuid().equals(uuid)) {
dto = new CategoricalDataDto(uuid, new FeatureDto(featureUuid, null, null, null, null, null, null, true, false, true, null, true, false, null, null, null, null), null);
dtoResult.add(dto);
}
StateDataDto state = new StateDataDto(TermDto.fromTerm((DefinedTermBase) o[4]), (Integer) o[3], uuid);
dto.addState(state);
}
return dtoResult;
}
use of eu.etaxonomy.cdm.persistence.dto.FeatureDto in project cdmlib by cybertaxonomy.
the class DescriptionServiceImpl method loadDto.
@Override
public DescriptionBaseDto loadDto(UUID descriptionUuid) {
String sqlSelect = DescriptionBaseDto.getDescriptionBaseDtoSelect();
Query query = getSession().createQuery(sqlSelect);
List<UUID> uuids = new ArrayList<UUID>();
uuids.add(descriptionUuid);
query.setParameterList("uuid", uuids);
@SuppressWarnings("unchecked") List<Object[]> result = query.list();
List<DescriptionBaseDto> list = DescriptionBaseDto.descriptionBaseDtoListFrom(result);
if (list.size() == 1) {
DescriptionBaseDto dto = list.get(0);
// get categorical data
sqlSelect = CategoricalDataDto.getCategoricalDtoSelect();
query = getSession().createQuery(sqlSelect);
query.setParameter("uuid", descriptionUuid);
@SuppressWarnings("unchecked") List<Object[]> resultCat = query.list();
List<CategoricalDataDto> listCategorical = CategoricalDataDto.categoricalDataDtoListFrom(resultCat);
List<UUID> featureUuids = new ArrayList<>();
for (CategoricalDataDto catDto : listCategorical) {
featureUuids.add(catDto.getFeatureUuid());
}
Map<UUID, TermDto> featureDtos = termService.findFeatureByUUIDsAsDtos(featureUuids);
for (CategoricalDataDto catDto : listCategorical) {
FeatureDto featuredto = (FeatureDto) featureDtos.get(catDto.getFeatureUuid());
catDto.setFeatureDto(featuredto);
}
dto.getElements().addAll(listCategorical);
// get quantitative data
sqlSelect = QuantitativeDataDto.getQuantitativeDataDtoSelect();
query = getSession().createQuery(sqlSelect);
query.setParameter("uuid", descriptionUuid);
@SuppressWarnings("unchecked") List<Object[]> resultQuant = query.list();
List<QuantitativeDataDto> listQuant = QuantitativeDataDto.quantitativeDataDtoListFrom(resultQuant);
dto.getElements().addAll(listQuant);
return dto;
} else {
return null;
}
}
use of eu.etaxonomy.cdm.persistence.dto.FeatureDto in project cdmlib by cybertaxonomy.
the class DescriptionBaseDto method fromDescription.
public static DescriptionBaseDto fromDescription(DescriptionBase desc) {
UuidAndTitleCache<Taxon> taxonUuidAndTitleCache = null;
UuidAndTitleCache<SpecimenOrObservationBase> specimenDto = null;
UuidAndTitleCache<TaxonName> nameUuidAndTitleCache = null;
if (desc instanceof TaxonDescription) {
Taxon taxon = HibernateProxyHelper.deproxy(((TaxonDescription) desc).getTaxon(), Taxon.class);
if (taxon != null) {
taxonUuidAndTitleCache = new UuidAndTitleCache<Taxon>(taxon.getUuid(), taxon.getId(), taxon.getTitleCache());
}
}
if (desc instanceof SpecimenDescription) {
SpecimenDescription specimenDesc = HibernateProxyHelper.deproxy(desc, SpecimenDescription.class);
SpecimenOrObservationBase specimen = specimenDesc.getDescribedSpecimenOrObservation();
specimenDto = new UuidAndTitleCache<>(specimen.getUuid(), specimen.getId(), specimen.getTitleCache());
// if (specimen != null){
// if (specimen instanceof FieldUnit){
// specimenDto = FieldUnitDTO.fromEntity((FieldUnit)specimen);
// }else{
// specimenDto = DerivedUnitDTO.fromEntity((DerivedUnit)specimen);
// }
// }
}
if (desc instanceof TaxonNameDescription) {
TaxonNameDescription nameDesc = HibernateProxyHelper.deproxy(desc, TaxonNameDescription.class);
TaxonName name = nameDesc.getTaxonName();
if (name != null) {
nameUuidAndTitleCache = new UuidAndTitleCache<TaxonName>(name.getUuid(), name.getId(), name.getTitleCache());
}
}
List<DescriptionElementDto> elements = new ArrayList<>();
for (Object element : desc.getElements()) {
if (element instanceof CategoricalData) {
Feature feature = ((CategoricalData) element).getFeature();
// FeatureDto featureDto = FeatureDto.fromFeature(feature);
CategoricalDataDto dto = CategoricalDataDto.fromCategoricalData((CategoricalData) element);
elements.add(dto);
}
if (element instanceof QuantitativeData) {
Feature feature = ((QuantitativeData) element).getFeature();
FeatureDto featureDto = FeatureDto.fromFeature(feature);
QuantitativeDataDto dto = QuantitativeDataDto.fromQuantitativeData((QuantitativeData) element);
elements.add(dto);
}
}
DescriptionBaseDto dto = new DescriptionBaseDto(desc.getUuid(), desc.getTitleCache(), taxonUuidAndTitleCache, specimenDto, nameUuidAndTitleCache, desc.getId(), elements, desc.getTypes());
return dto;
}
use of eu.etaxonomy.cdm.persistence.dto.FeatureDto in project cdmlib by cybertaxonomy.
the class QuantitativeDataDto method quantitativeDataDtoListFrom.
/**
* @param result
* @return
*/
public static List<QuantitativeDataDto> quantitativeDataDtoListFrom(List<Object[]> result) {
List<QuantitativeDataDto> dtoResult = new ArrayList<>();
QuantitativeDataDto dto = null;
for (Object[] o : result) {
UUID uuid = (UUID) o[0];
UUID featureUuid = (UUID) o[1];
if (dto == null || !dto.getElementUuid().equals(uuid)) {
dto = new QuantitativeDataDto(uuid, new FeatureDto(featureUuid, null, null, null, null, null, null, true, false, true, null, true, false, null, null, null, null));
dtoResult.add(dto);
}
StatisticalMeasurementValueDto statVal = new StatisticalMeasurementValueDto(TermDto.fromTerm((DefinedTermBase) o[4]), (BigDecimal) o[3], (UUID) o[2]);
dto.addValue(statVal);
if (o[5] != null) {
dto.setMeasurementUnit(TermDto.fromTerm((DefinedTermBase) o[5]));
}
}
return dtoResult;
}
Aggregations