use of eu.etaxonomy.cdm.model.description.FeatureState in project cdmlib by cybertaxonomy.
the class StructureTreeOwlImport method createNode.
private <T extends DefinedTermBase> void createNode(TermNode<T> parent, Statement nodeStatement, String treeLabel, Model model, StructureTreeOwlImportState state) {
if (state.getConfig().getProgressMonitor().isCanceled()) {
return;
}
Resource nodeResource = model.createResource(nodeStatement.getObject().toString());
UUID nodeUuid = UUID.fromString(nodeResource.getProperty(OwlUtil.propUuid).getString());
Resource termResource = nodeResource.getPropertyResourceValue(OwlUtil.propHasTerm);
TermNode<?> termNode = getTermNodeService().load(nodeUuid);
if (termNode == null) {
// import term vocabulary
Resource vocabularyResource = termResource.getPropertyResourceValue(OwlUtil.propHasVocabulary);
UUID vocUuid = UUID.fromString(vocabularyResource.getProperty(OwlUtil.propUuid).getString());
TermVocabulary vocabulary = getVocabularyService().load(vocUuid);
if (vocabulary == null) {
vocabulary = OwlImportUtil.createVocabulary(vocabularyResource, this, model, state);
vocabulary = getVocabularyService().save(vocabulary);
}
// import term
UUID termUuid = UUID.fromString(termResource.getProperty(OwlUtil.propUuid).getString());
T term = (T) getTermService().find(termUuid);
if (term == null) {
term = (T) OwlImportUtil.createTerm(termResource, this, model, state);
term = getTermService().save(term);
// only add term if it does not already exist
vocabulary.addTerm(term);
}
getVocabularyService().saveOrUpdate(vocabulary);
termNode = parent.addChild(term);
termNode.setUuid(nodeUuid);
// inapplicable if
StmtIterator inapplicableIterator = nodeResource.listProperties(OwlUtil.propNodeIsInapplicableIf);
while (inapplicableIterator.hasNext()) {
Statement statement = inapplicableIterator.next();
FeatureState featureState = createFeatureState(statement, model, state);
termNode.addInapplicableState(featureState);
}
// only applicable if
StmtIterator onlyApplicableIterator = nodeResource.listProperties(OwlUtil.propNodeIsOnlyApplicableIf);
while (onlyApplicableIterator.hasNext()) {
Statement statement = onlyApplicableIterator.next();
FeatureState featureState = createFeatureState(statement, model, state);
termNode.addApplicableState(featureState);
}
}
state.getConfig().getProgressMonitor().worked(1);
StmtIterator listProperties = nodeResource.listProperties(OwlUtil.propHasSubStructure);
while (listProperties.hasNext()) {
Statement prop = listProperties.next();
createNode(termNode, prop, treeLabel, model, state);
}
}
use of eu.etaxonomy.cdm.model.description.FeatureState in project cdmlib by cybertaxonomy.
the class TermNodeDaoImplTest method createTestDataSet.
@Override
public // @Test
void createTestDataSet() throws FileNotFoundException {
// 1. create the entities and save them
TermTree<Feature> featureTree = TermTree.NewFeatureInstance();
TermNode<Feature> node = featureTree.getRoot().addChild(Feature.NewInstance());
FeatureState applicable = node.addApplicableState(Feature.NewInstance(), State.NewInstance());
FeatureState inApplicable = node.addInapplicableState(Feature.NewInstance(), State.NewInstance());
treeDao.save(featureTree);
termDao.save(node.getTerm());
termDao.save(applicable.getFeature());
termDao.save(inApplicable.getFeature());
termDao.save(applicable.getState());
termDao.save(inApplicable.getState());
// 2. end the transaction so that all data is actually written to the db
setComplete();
endTransaction();
// use the fileNameAppendix if you are creating a data set file which need to be named differently
// from the standard name. For example if a single test method needs different data then the other
// methods the test class you may want to set the fileNameAppendix when creating the data for this method.
String fileNameAppendix = null;
// 3.
writeDbUnitDataSetFile(new String[] { "TERMCOLLECTION", "TERMRELATION", "FEATURESTATE", "TERMNODE_INAPPLICABLEIF", "TERMNODE_ONLYAPPLICABLEIF", // IMPORTANT!!!
"HIBERNATE_SEQUENCES" }, fileNameAppendix, true);
}
use of eu.etaxonomy.cdm.model.description.FeatureState in project cdmlib by cybertaxonomy.
the class TermNode method addApplicableState.
public FeatureState addApplicableState(Feature feature, State applicableState) {
FeatureState featureState = FeatureState.NewInstance(feature, applicableState);
addApplicableState(featureState);
return featureState;
}
use of eu.etaxonomy.cdm.model.description.FeatureState in project cdmlib by cybertaxonomy.
the class OwlExportUtil method createNodeResource.
static Resource createNodeResource(TermNode<?> node, boolean initFeatureTree, ICdmRepository repo, StructureTreeOwlExportState state) {
if (initFeatureTree) {
createFeatureTreeResource(node.getGraph(), repo, state);
return getNodeResource(node, state);
}
Resource nodeResource = getNodeResource(node, state).addProperty(OwlUtil.propIsA, OwlUtil.NODE).addProperty(OwlUtil.propUuid, node.getUuid().toString());
// inapplicable if
Set<FeatureState> inapplicableIf = node.getInapplicableIf();
for (FeatureState featureState : inapplicableIf) {
Resource featureStateResource = state.getModel().createResource(OwlUtil.RESOURCE_SOURCE + featureState.getUuid()).addProperty(OwlUtil.propIsA, OwlUtil.FEATURE_STATE).addProperty(OwlUtil.propUuid, featureState.getUuid().toString()).addProperty(OwlUtil.propFeatureStateHasFeature, createTermResource(featureState.getFeature(), false, repo, state)).addProperty(OwlUtil.propFeatureStateHasState, createTermResource(featureState.getState(), false, repo, state));
nodeResource.addProperty(OwlUtil.propNodeIsInapplicableIf, featureStateResource);
}
// only applicable if
Set<FeatureState> onlyApplicableIf = node.getOnlyApplicableIf();
for (FeatureState featureState : onlyApplicableIf) {
Resource featureStateResource = state.getModel().createResource(OwlUtil.RESOURCE_SOURCE + featureState.getUuid()).addProperty(OwlUtil.propIsA, OwlUtil.FEATURE_STATE).addProperty(OwlUtil.propUuid, featureState.getUuid().toString()).addProperty(OwlUtil.propFeatureStateHasFeature, createTermResource(featureState.getFeature(), false, repo, state)).addProperty(OwlUtil.propFeatureStateHasState, createTermResource(featureState.getState(), false, repo, state));
nodeResource.addProperty(OwlUtil.propNodeIsOnlyApplicableIf, featureStateResource);
}
if (node.getTerm() != null) {
// add term to node
createVocabularyResource(node.getTerm().getVocabulary(), repo, state);
Resource termResource = OwlExportUtil.getTermResource(node.getTerm(), state);
nodeResource.addProperty(OwlUtil.propHasTerm, termResource);
}
return nodeResource;
}
use of eu.etaxonomy.cdm.model.description.FeatureState in project cdmlib by cybertaxonomy.
the class SDDDocumentBuilder method buildBranches.
public void buildBranches(TermNode<Feature> parent, ElementImpl element, boolean isRoot) {
List<TermNode<Feature>> children = parent.getChildNodes();
if (!parent.isLeaf()) {
ElementImpl elCharNode = new ElementImpl(document, NODE);
charnodeCount = buildReference(parent, featuretrees, ID, elCharNode, "cn", charnodeCount);
TermNode grandparent = parent.getParent();
if ((grandparent != null) && (!isRoot)) {
ElementImpl elParent = new ElementImpl(document, PARENT);
charnodeCount = buildReference(grandparent, featuretrees, REF, elParent, "cn", charnodeCount);
elCharNode.appendChild(elParent);
}
ElementImpl elDescriptiveConcept = new ElementImpl(document, DESCRIPTIVE_CONCEPT);
Feature fref = parent.getTerm();
descriptiveConceptCount = buildReference(fref, descriptiveConcepts, REF, elDescriptiveConcept, "dc", descriptiveConceptCount);
elCharNode.appendChild(elDescriptiveConcept);
element.appendChild(elCharNode);
for (Iterator<TermNode<Feature>> ifn = children.iterator(); ifn.hasNext(); ) {
TermNode fn = ifn.next();
buildBranches(fn, element, false);
}
} else {
ElementImpl elCharNode = new ElementImpl(document, CHAR_NODE);
ElementImpl elParent = new ElementImpl(document, PARENT);
TermNode grandparent = parent.getParent();
charnodeCount = buildReference(grandparent, featuretrees, REF, elParent, "cn", charnodeCount);
charnodeCount = buildReference(parent, featuretrees, ID, elCharNode, "cn", charnodeCount);
ElementImpl elCharacter = new ElementImpl(document, CHARACTER);
Feature fref = parent.getTerm();
boolean dependencies = false;
ElementImpl elDependecyRules = new ElementImpl(document, "DependecyRules");
if (parent.getInapplicableIf() != null) {
Set<FeatureState> innaplicableIf = parent.getInapplicableIf();
ElementImpl elInnaplicableIf = new ElementImpl(document, "InapplicableIf");
for (FeatureState featureState : innaplicableIf) {
State state = featureState.getState();
ElementImpl elState = new ElementImpl(document, STATE);
buildReference(state, states, REF, elState, "State", statesCount);
elInnaplicableIf.appendChild(elState);
}
elDependecyRules.appendChild(elInnaplicableIf);
dependencies = true;
}
if (parent.getOnlyApplicableIf() != null) {
Set<FeatureState> onlyApplicableIf = parent.getOnlyApplicableIf();
ElementImpl elOnlyApplicableIf = new ElementImpl(document, "OnlyApplicableIf");
for (FeatureState featureState : onlyApplicableIf) {
ElementImpl elState = new ElementImpl(document, STATE);
State state = featureState.getState();
buildReference(state, states, REF, elState, "State", statesCount);
elOnlyApplicableIf.appendChild(elState);
}
elDependecyRules.appendChild(elOnlyApplicableIf);
dependencies = true;
}
if (dependencies == true) {
elCharNode.appendChild(elDependecyRules);
}
charactersCount = buildReference(fref, characters, REF, elCharacter, "c", charactersCount);
elCharNode.appendChild(elCharacter);
elCharNode.appendChild(elParent);
element.appendChild(elCharNode);
}
}
Aggregations