Search in sources :

Example 1 with TermVocabularyDto

use of eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto in project cdmlib by cybertaxonomy.

the class DefinedTermDaoImpl method findByTitleAsDtoWithVocDto.

@Override
public Collection<TermDto> findByTitleAsDtoWithVocDto(String title, TermType termType) {
    // terms
    String termQueryString = TermDto.getTermDtoSelect() + " where a.titleCache like :title " + (termType != null ? " and a.termType = :termType " : "");
    title = title.replace("*", "%");
    Query termQuery = getSession().createQuery(termQueryString);
    termQuery.setParameter("title", "%" + title + "%");
    if (termType != null) {
        termQuery.setParameter("termType", termType);
    }
    @SuppressWarnings("unchecked") List<Object[]> termArrayResult = termQuery.list();
    List<TermDto> list = TermDto.termDtoListFrom(termArrayResult);
    // vocabularies
    String vocQueryString = TermCollectionDto.getTermCollectionDtoSelect() + " where a.uuid = :uuid";
    Query vocQuery = getSession().createQuery(vocQueryString);
    Map<UUID, TermVocabularyDto> vocMap = new HashMap<>();
    for (TermDto dto : list) {
        UUID vocUuid = dto.getVocabularyUuid();
        TermVocabularyDto vocDto = vocMap.get(vocUuid);
        if (vocDto == null) {
            vocQuery.setParameter("uuid", dto.getVocabularyUuid());
            @SuppressWarnings("unchecked") List<Object[]> vocArrayResult = vocQuery.list();
            List<TermVocabularyDto> vocs = TermVocabularyDto.termVocabularyDtoListFrom(vocArrayResult);
            if (!vocs.isEmpty()) {
                vocDto = vocs.get(0);
                vocMap.put(vocUuid, vocs.get(0));
            }
        }
        dto.setVocabularyDto(vocDto);
    }
    return list;
}
Also used : TermVocabularyDto(eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto) Query(org.hibernate.Query) AuditQuery(org.hibernate.envers.query.AuditQuery) HashMap(java.util.HashMap) UUID(java.util.UUID) TermDto(eu.etaxonomy.cdm.persistence.dto.TermDto)

Example 2 with TermVocabularyDto

use of eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto in project cdmlib by cybertaxonomy.

the class TermVocabularyDaoImpl method findVocabularyDtoByAvailableFor.

@Override
public List<TermVocabularyDto> findVocabularyDtoByAvailableFor(Set<CdmClass> availableForSet) {
    String queryVocWithFittingTerms = "SELECT DISTINCT(v.uuid) FROM DefinedTermBase term JOIN term.vocabulary as v WHERE ";
    for (CdmClass availableFor : availableForSet) {
        queryVocWithFittingTerms += " term.availableFor like '%" + availableFor.getKey() + "%' AND term.termType = :feature";
    }
    String queryString = TermCollectionDto.getTermCollectionDtoSelect() + " WHERE a.uuid in " + " (" + queryVocWithFittingTerms + ")";
    Query query = getSession().createQuery(queryString);
    query.setParameter("feature", TermType.Feature);
    @SuppressWarnings("unchecked") List<Object[]> result = query.list();
    List<TermVocabularyDto> dtos = TermVocabularyDto.termVocabularyDtoListFrom(result);
    return dtos;
}
Also used : TermVocabularyDto(eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto) Query(org.hibernate.Query) AuditQuery(org.hibernate.envers.query.AuditQuery) CdmClass(eu.etaxonomy.cdm.model.common.CdmClass)

Example 3 with TermVocabularyDto

use of eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto in project cdmlib by cybertaxonomy.

the class FeatureDto_ method fromFeature.

public static FeatureDto_ fromFeature(Feature feature) {
    FeatureDto_ dto = (FeatureDto_) fromTerm(feature);
    if (feature.isSupportsCategoricalData()) {
        dto.supportedDataTypes.add(CdmClass.CATEGORICAL_DATA);
    }
    if (feature.isSupportsCommonTaxonName()) {
        dto.supportedDataTypes.add(CdmClass.COMMON_TAXON_NAME);
    }
    if (feature.isSupportsDistribution()) {
        dto.supportedDataTypes.add(CdmClass.DISTRIBUTION);
    }
    if (feature.isSupportsIndividualAssociation()) {
        dto.supportedDataTypes.add(CdmClass.INDIVIDUALS_ASSOCIATION);
    }
    if (feature.isSupportsQuantitativeData()) {
        dto.supportedDataTypes.add(CdmClass.QUANTITATIVE_DATA);
    }
    if (feature.isSupportsTaxonInteraction()) {
        dto.supportedDataTypes.add(CdmClass.TAXON_INTERACTION);
    }
    if (feature.isSupportsTemporalData()) {
        dto.supportedDataTypes.add(CdmClass.TEMPORAL_DATA);
    }
    if (!feature.isSupportsTextData()) {
        dto.supportedDataTypes.remove(CdmClass.TEXT_DATA);
    }
    TermVocabularyDto vocDto;
    for (TermVocabulary<?> voc : feature.getRecommendedModifierEnumeration()) {
        vocDto = TermVocabularyDto.fromVocabulary(voc);
        dto.recommendedModifierEnumeration.add(vocDto);
    }
    TermDto termDto;
    for (StatisticalMeasure term : feature.getRecommendedStatisticalMeasures()) {
        termDto = TermDto.fromTerm(term);
        dto.recommendedStatisticalMeasures.add(termDto);
    }
    for (TermVocabulary<?> voc : feature.getSupportedCategoricalEnumerations()) {
        vocDto = TermVocabularyDto.fromVocabulary(voc);
        dto.supportedCategoricalEnumerations.add(vocDto);
    }
    for (MeasurementUnit term : feature.getRecommendedMeasurementUnits()) {
        termDto = TermDto.fromTerm(term);
        dto.recommendedMeasurementUnits.add(termDto);
    }
    return dto;
}
Also used : MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) TermVocabularyDto(eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto) StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) TermDto(eu.etaxonomy.cdm.persistence.dto.TermDto)

Example 4 with TermVocabularyDto

use of eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto in project cdmlib by cybertaxonomy.

the class TermVocabularyDaoImpl method findVocabularyDtoByUuids.

@Override
public List<TermVocabularyDto> findVocabularyDtoByUuids(List<UUID> vocUuids) {
    if (vocUuids == null || vocUuids.isEmpty()) {
        return null;
    }
    List<TermVocabularyDto> list = new ArrayList<>();
    String queryString = TermCollectionDto.getTermCollectionDtoSelect() + "where a.uuid in :uuidList ";
    // + "order by a.titleCache";
    Query query = getSession().createQuery(queryString);
    query.setParameterList("uuidList", vocUuids);
    @SuppressWarnings("unchecked") List<Object[]> result = query.list();
    list = TermVocabularyDto.termVocabularyDtoListFrom(result);
    return list;
}
Also used : TermVocabularyDto(eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto) Query(org.hibernate.Query) AuditQuery(org.hibernate.envers.query.AuditQuery) ArrayList(java.util.ArrayList)

Example 5 with TermVocabularyDto

use of eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto in project cdmlib by cybertaxonomy.

the class TermVocabularyDaoImpl method findVocabularyDtoByTermTypes.

@Override
public List<TermVocabularyDto> findVocabularyDtoByTermTypes(Set<TermType> termTypes, String pattern, boolean includeSubtypes) {
    Set<TermType> termTypeWithSubType = new HashSet<>();
    if (!(termTypes.isEmpty() || (termTypes.size() == 1 && termTypes.iterator().next() == null))) {
        termTypeWithSubType = new HashSet<>(termTypes);
    }
    if (includeSubtypes) {
        if (!termTypes.isEmpty()) {
            for (TermType termType : termTypes) {
                if (termType != null) {
                    termTypeWithSubType.addAll(termType.getGeneralizationOf(true));
                }
            }
        }
    }
    String queryString = TermVocabularyDto.getTermCollectionDtoSelect();
    if (!termTypeWithSubType.isEmpty()) {
        queryString += " WHERE a.termType in (:termTypes) ";
        if (pattern != null) {
            queryString += " AND a.titleCache like :pattern";
        }
    } else {
        if (pattern != null) {
            queryString += " WHERE a.titleCache like :pattern";
        }
    }
    Query query = getSession().createQuery(queryString);
    if (!termTypeWithSubType.isEmpty()) {
        query.setParameterList("termTypes", termTypeWithSubType);
    }
    if (pattern != null) {
        pattern = pattern.replace("*", "%");
        pattern = "%" + pattern + "%";
        query.setParameter("pattern", pattern);
    }
    @SuppressWarnings("unchecked") List<Object[]> result = query.list();
    List<TermVocabularyDto> dtos = TermVocabularyDto.termVocabularyDtoListFrom(result);
    return dtos;
}
Also used : TermVocabularyDto(eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto) Query(org.hibernate.Query) AuditQuery(org.hibernate.envers.query.AuditQuery) TermType(eu.etaxonomy.cdm.model.term.TermType) HashSet(java.util.HashSet)

Aggregations

TermVocabularyDto (eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto)6 Query (org.hibernate.Query)4 AuditQuery (org.hibernate.envers.query.AuditQuery)4 TermDto (eu.etaxonomy.cdm.persistence.dto.TermDto)3 MeasurementUnit (eu.etaxonomy.cdm.model.description.MeasurementUnit)2 StatisticalMeasure (eu.etaxonomy.cdm.model.description.StatisticalMeasure)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 UUID (java.util.UUID)2 CdmClass (eu.etaxonomy.cdm.model.common.CdmClass)1 Character (eu.etaxonomy.cdm.model.description.Character)1 DefinedTerm (eu.etaxonomy.cdm.model.term.DefinedTerm)1 DefinedTermBase (eu.etaxonomy.cdm.model.term.DefinedTermBase)1 Representation (eu.etaxonomy.cdm.model.term.Representation)1 TermNode (eu.etaxonomy.cdm.model.term.TermNode)1 TermType (eu.etaxonomy.cdm.model.term.TermType)1 TermVocabulary (eu.etaxonomy.cdm.model.term.TermVocabulary)1 CharacterDto (eu.etaxonomy.cdm.persistence.dto.CharacterDto)1 CharacterNodeDto (eu.etaxonomy.cdm.persistence.dto.CharacterNodeDto)1 HashMap (java.util.HashMap)1