Search in sources :

Example 1 with FeatureDto

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;
}
Also used : DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) Query(org.hibernate.Query) ArrayList(java.util.ArrayList) QuantitativeDataDto(eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto) CategoricalDataDto(eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto) TermDto(eu.etaxonomy.cdm.persistence.dto.TermDto) UUID(java.util.UUID) FeatureDto(eu.etaxonomy.cdm.persistence.dto.FeatureDto)

Example 2 with FeatureDto

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;
}
Also used : DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) ArrayList(java.util.ArrayList) UUID(java.util.UUID) FeatureDto(eu.etaxonomy.cdm.persistence.dto.FeatureDto)

Example 3 with FeatureDto

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;
    }
}
Also used : DescriptionBaseDto(eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto) Query(org.hibernate.Query) ArrayList(java.util.ArrayList) QuantitativeDataDto(eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto) CategoricalDataDto(eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto) TermDto(eu.etaxonomy.cdm.persistence.dto.TermDto) UUID(java.util.UUID) FeatureDto(eu.etaxonomy.cdm.persistence.dto.FeatureDto)

Example 4 with FeatureDto

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;
}
Also used : SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) ArrayList(java.util.ArrayList) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) Feature(eu.etaxonomy.cdm.model.description.Feature) CategoricalData(eu.etaxonomy.cdm.model.description.CategoricalData) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) FeatureDto(eu.etaxonomy.cdm.persistence.dto.FeatureDto)

Example 5 with FeatureDto

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;
}
Also used : DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) ArrayList(java.util.ArrayList) UUID(java.util.UUID) FeatureDto(eu.etaxonomy.cdm.persistence.dto.FeatureDto)

Aggregations

FeatureDto (eu.etaxonomy.cdm.persistence.dto.FeatureDto)5 ArrayList (java.util.ArrayList)5 UUID (java.util.UUID)4 CategoricalDataDto (eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto)2 DescriptionBaseDto (eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto)2 QuantitativeDataDto (eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto)2 DefinedTermBase (eu.etaxonomy.cdm.model.term.DefinedTermBase)2 TermDto (eu.etaxonomy.cdm.persistence.dto.TermDto)2 Query (org.hibernate.Query)2 CategoricalData (eu.etaxonomy.cdm.model.description.CategoricalData)1 Feature (eu.etaxonomy.cdm.model.description.Feature)1 QuantitativeData (eu.etaxonomy.cdm.model.description.QuantitativeData)1 SpecimenDescription (eu.etaxonomy.cdm.model.description.SpecimenDescription)1 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)1 TaxonNameDescription (eu.etaxonomy.cdm.model.description.TaxonNameDescription)1 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)1 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)1 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)1