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