use of eu.etaxonomy.cdm.model.term.TermNode in project cdmlib by cybertaxonomy.
the class OwlImportUtil method addCharacterProperties.
static void addCharacterProperties(Character character, Resource termResource, ICdmRepository repo, Model model, StructureTreeOwlImportState state) {
addFeatureProperties(character, termResource, repo, model, state);
// import property
if (character.getProperty() != null) {
Statement propertyStatement = termResource.getProperty(OwlUtil.propCharacterHasProperty);
Resource propertyResource = model.createResource(propertyStatement.getObject().toString());
TermNode propertyNode = loadNode(propertyResource, repo, model, state);
if (propertyNode != null) {
character.setProperty(propertyNode);
} else {
logger.error("Property not found for character: " + character);
return;
}
}
// import structure
if (character.getStructure() != null) {
Statement structureStatement = termResource.getProperty(OwlUtil.propCharacterHasStructure);
Resource structureResource = model.createResource(structureStatement.getObject().toString());
TermNode structureNode = loadNode(structureResource, repo, model, state);
if (structureNode != null) {
character.setStructure(structureNode);
} else {
logger.error("Structure not found for character: " + character);
return;
}
}
// import structure modifier
if (character.getStructureModifier() != null && termResource.hasProperty(OwlUtil.propCharacterHasStructureModfier)) {
Statement structureModifierStatement = termResource.getProperty(OwlUtil.propCharacterHasStructureModfier);
Resource structureModifierResource = model.createResource(structureModifierStatement.getObject().toString());
DefinedTerm structureModifier = findTerm(DefinedTerm.class, structureModifierResource, repo, model, state);
character.setStructureModifier(structureModifier);
}
}
use of eu.etaxonomy.cdm.model.term.TermNode in project cdmlib by cybertaxonomy.
the class SDDDocumentBuilder method buildCharacterTrees.
public void buildCharacterTrees(ElementImpl dataset) throws ParseException {
if (cdmSource.getFeatureData() != null) {
ElementImpl elChartrees = new ElementImpl(document, CHARACTER_TREES);
for (int i = 0; i < cdmSource.getFeatureData().size(); i++) {
VersionableEntity featu = cdmSource.getFeatureData().get(i);
if (featu instanceof TermTree) {
TermTree ft = (TermTree) featu;
ElementImpl elChartree = new ElementImpl(document, CHARACTER_TREE);
chartreeCount = buildReference(featu, featuretrees, ID, elChartree, "ct", chartreeCount);
buildRepresentation(elChartree, ft);
elChartrees.appendChild(elChartree);
ElementImpl elNodes = new ElementImpl(document, NODES);
elChartree.appendChild(elNodes);
List<TermNode> roots = ft.getRootChildren();
for (Iterator<TermNode> fn = roots.iterator(); fn.hasNext(); ) {
TermNode featureNode = fn.next();
buildBranches(featureNode, elNodes, true);
}
}
}
dataset.appendChild(elChartrees);
}
}
use of eu.etaxonomy.cdm.model.term.TermNode in project cdmlib by cybertaxonomy.
the class TermNodeDaoImpl method list.
@Override
public List<TermNode> list() {
Criteria crit = getSession().createCriteria(type);
@SuppressWarnings("unchecked") List<TermNode> result = crit.list();
return result;
}
use of eu.etaxonomy.cdm.model.term.TermNode in project cdmlib by cybertaxonomy.
the class TermNodeDaoImpl method list.
// TODO still needs to be tested
@Override
public List<TermNode> list(TermType termType, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
Criteria criteria = getSession().createCriteria(type);
if (termType != null) {
Set<TermType> types = termType.getGeneralizationOf(true);
types.add(termType);
criteria.add(Restrictions.in("termType", types));
}
addLimitAndStart(criteria, limit, start);
addOrder(criteria, orderHints);
@SuppressWarnings("unchecked") List<TermNode> results = criteria.list();
defaultBeanInitializer.initializeAll(results, propertyPaths);
return results;
}
use of eu.etaxonomy.cdm.model.term.TermNode in project cdmlib by cybertaxonomy.
the class CharacterDto method termDtoListFrom.
public static List<TermDto> termDtoListFrom(List<Object[]> results) {
// list to ensure order
List<TermDto> dtos = new ArrayList<>();
// map to handle multiple representations/media/vocRepresentation because of LEFT JOIN
Map<UUID, TermDto> dtoMap = new HashMap<>(results.size());
for (Object[] elements : results) {
UUID uuid = (UUID) elements[0];
if (dtoMap.containsKey(uuid)) {
// multiple results for one term -> multiple (voc) representation/media
if (elements[1] != null) {
dtoMap.get(uuid).addRepresentation((Representation) elements[1]);
}
// }
if (elements[8] != null) {
dtoMap.get(uuid).addMedia(((Media) elements[8]).getUuid());
}
} else {
// term representation
Set<Representation> representations = new HashSet<>();
if (elements[1] instanceof Representation) {
representations = new HashSet<Representation>(1);
representations.add((Representation) elements[1]);
}
// term media
Set<UUID> mediaUuids = new HashSet<>();
if (elements[8] instanceof Media) {
mediaUuids.add(((Media) elements[8]).getUuid());
}
// voc representation
// Set<Representation> vocRepresentations = new HashSet<>();
// if(elements[6] instanceof Representation) {
// vocRepresentations = new HashSet<Representation>(7);
// vocRepresentations.add((Representation)elements[6]);
// }
boolean isAvailableForTaxon = false;
boolean isAvailableForTaxonName = false;
boolean isAvailableForOccurrence = false;
EnumSet<CdmClass> availableForString = (EnumSet<CdmClass>) elements[9];
if (availableForString.contains(CdmClass.TAXON)) {
isAvailableForTaxon = true;
}
if (availableForString.contains(CdmClass.TAXON_NAME)) {
isAvailableForTaxonName = true;
}
if (availableForString.contains(CdmClass.OCCURRENCE)) {
isAvailableForOccurrence = true;
}
boolean isSupportsCategoricalData = false;
boolean isSupportsQuantitativeData = false;
EnumSet<CdmClass> supportsString = (EnumSet<CdmClass>) elements[11];
if (supportsString.contains(CdmClass.CATEGORICAL_DATA)) {
isSupportsCategoricalData = true;
}
if (supportsString.contains(CdmClass.QUANTITATIVE_DATA)) {
isSupportsQuantitativeData = true;
}
Object o = elements[12];
Set<TermVocabularyDto> recommendedModifierDtos = new HashSet<>();
if (o instanceof TermVocabulary) {
recommendedModifierDtos.add(TermVocabularyDto.fromVocabulary((TermVocabulary) o));
} else if (o instanceof Set) {
Set<TermVocabulary<DefinedTerm>> recommendedModifierEnumeration = (Set<TermVocabulary<DefinedTerm>>) o;
if (recommendedModifierEnumeration != null) {
for (TermVocabulary<DefinedTerm> voc : recommendedModifierEnumeration) {
recommendedModifierDtos.add(TermVocabularyDto.fromVocabulary(voc));
}
}
}
o = elements[13];
Set<TermDto> recommendedStatisticalMeasuresDtos = new HashSet<>();
if (o instanceof StatisticalMeasure) {
recommendedStatisticalMeasuresDtos.add(TermDto.fromTerm((StatisticalMeasure) o));
} else if (o instanceof Set) {
Set<StatisticalMeasure> recommendedStatisticalMeasures = (Set<StatisticalMeasure>) o;
if (recommendedStatisticalMeasures != null) {
for (StatisticalMeasure term : recommendedStatisticalMeasures) {
recommendedStatisticalMeasuresDtos.add(TermDto.fromTerm(term));
}
}
}
o = elements[14];
Set<TermVocabularyDto> supportedCategoricalDtos = new HashSet<>();
if (o instanceof TermVocabulary) {
supportedCategoricalDtos.add(TermVocabularyDto.fromVocabulary((TermVocabulary) o));
} else if (o instanceof Set) {
Set<TermVocabulary> supportedCategoricalEnumerations = (Set<TermVocabulary>) o;
for (TermVocabulary<State> voc : supportedCategoricalEnumerations) {
supportedCategoricalDtos.add(TermVocabularyDto.fromVocabulary(voc));
}
}
o = elements[15];
Set<TermDto> recommendedMeasurementUnitsDtos = new HashSet<>();
if (o instanceof MeasurementUnit) {
recommendedMeasurementUnitsDtos.add(TermDto.fromTerm((MeasurementUnit) o));
} else if (o instanceof Set) {
Set<MeasurementUnit> recommendedMeasurementUnits = (Set<MeasurementUnit>) elements[15];
for (MeasurementUnit term : recommendedMeasurementUnits) {
recommendedMeasurementUnitsDtos.add(TermDto.fromTerm(term));
}
}
o = elements[16];
TermNodeDto prop = null;
if (o instanceof TermNode) {
prop = TermNodeDto.fromNode((TermNode) o, TermTreeDto.fromTree((TermTree) ((TermNode) o).getGraph()));
}
o = elements[17];
TermNodeDto structure = null;
if (o instanceof TermNode) {
structure = TermNodeDto.fromNode((TermNode) o, TermTreeDto.fromTree((TermTree) ((TermNode) o).getGraph()));
}
o = elements[9];
TermNodeDto ratioTo = null;
if (o instanceof TermNode) {
ratioTo = TermNodeDto.fromNode((TermNode) o, TermTreeDto.fromTree((TermTree) ((TermNode) o).getGraph()));
}
TermDto termDto = new CharacterDto(uuid, representations, (UUID) elements[2], (UUID) elements[3], (UUID) elements[4], null, (String) elements[5], // vocRepresentations,
isAvailableForTaxon, isAvailableForTaxonName, isAvailableForOccurrence, (String) elements[10], structure, null, prop, null, ratioTo, isSupportsCategoricalData, // structure, structureModifier, prop, null, isSupportsCategoricalData,
isSupportsQuantitativeData, supportedCategoricalDtos, recommendedModifierDtos, recommendedMeasurementUnitsDtos, recommendedStatisticalMeasuresDtos);
termDto.setUri((URI) elements[7]);
termDto.setMedia(mediaUuids);
dtoMap.put(uuid, termDto);
dtos.add(termDto);
}
}
return dtos;
}
Aggregations