Search in sources :

Example 16 with TermNode

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);
    }
}
Also used : Statement(com.hp.hpl.jena.rdf.model.Statement) Resource(com.hp.hpl.jena.rdf.model.Resource) TermNode(eu.etaxonomy.cdm.model.term.TermNode) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm)

Example 17 with TermNode

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);
    }
}
Also used : TermTree(eu.etaxonomy.cdm.model.term.TermTree) ElementImpl(org.apache.xerces.dom.ElementImpl) TermNode(eu.etaxonomy.cdm.model.term.TermNode) VersionableEntity(eu.etaxonomy.cdm.model.common.VersionableEntity)

Example 18 with TermNode

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;
}
Also used : Criteria(org.hibernate.Criteria) TermNode(eu.etaxonomy.cdm.model.term.TermNode)

Example 19 with TermNode

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;
}
Also used : Criteria(org.hibernate.Criteria) TermNode(eu.etaxonomy.cdm.model.term.TermNode) TermType(eu.etaxonomy.cdm.model.term.TermType)

Example 20 with TermNode

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TermNode(eu.etaxonomy.cdm.model.term.TermNode) CdmClass(eu.etaxonomy.cdm.model.common.CdmClass) StatisticalMeasure(eu.etaxonomy.cdm.model.description.StatisticalMeasure) UUID(java.util.UUID) HashSet(java.util.HashSet) MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) EnumSet(java.util.EnumSet) Media(eu.etaxonomy.cdm.model.media.Media) TermVocabulary(eu.etaxonomy.cdm.model.term.TermVocabulary) Representation(eu.etaxonomy.cdm.model.term.Representation) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm)

Aggregations

TermNode (eu.etaxonomy.cdm.model.term.TermNode)25 ArrayList (java.util.ArrayList)12 Feature (eu.etaxonomy.cdm.model.description.Feature)7 TermTree (eu.etaxonomy.cdm.model.term.TermTree)7 UUID (java.util.UUID)7 DefinedTerm (eu.etaxonomy.cdm.model.term.DefinedTerm)5 Representation (eu.etaxonomy.cdm.model.term.Representation)5 TermVocabulary (eu.etaxonomy.cdm.model.term.TermVocabulary)5 TermDto (eu.etaxonomy.cdm.persistence.dto.TermDto)4 HashSet (java.util.HashSet)4 Resource (com.hp.hpl.jena.rdf.model.Resource)3 ReferencedObjectUndeletableException (eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException)3 Media (eu.etaxonomy.cdm.model.media.Media)3 DefinedTermBase (eu.etaxonomy.cdm.model.term.DefinedTermBase)3 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)3 Test (org.junit.Test)3 DataChangeNoRollbackException (eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException)2 MeasurementUnit (eu.etaxonomy.cdm.model.description.MeasurementUnit)2 StatisticalMeasure (eu.etaxonomy.cdm.model.description.StatisticalMeasure)2 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)2