use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyNodeServiceImpl method delete.
@Override
public DeleteResult delete(UUID nodeUUID, boolean deleteChildren) {
DeleteResult result = new DeleteResult();
PolytomousKeyNode node = dao.findByUuid(nodeUUID);
node = HibernateProxyHelper.deproxy(node);
if (node == null) {
// result.addException(new Exception("The polytomouskey node was already deleted."));;
return result;
}
List<PolytomousKeyNode> children = new ArrayList<PolytomousKeyNode>();
node.removeNullValueFromChildren();
for (PolytomousKeyNode child : node.getChildren()) {
children.add(child);
}
PolytomousKeyNode parent = node.getParent();
parent = HibernateProxyHelper.deproxy(parent, PolytomousKeyNode.class);
PolytomousKey key = null;
if (parent == null) {
key = node.getKey();
key = HibernateProxyHelper.deproxy(key, PolytomousKey.class);
}
if (!deleteChildren) {
for (PolytomousKeyNode child : children) {
if (!child.equals(node)) {
parent.addChild(child);
dao.saveOrUpdate(child);
result.addUpdatedObject(child);
}
}
dao.saveOrUpdate(node);
result.addUpdatedObject(node);
}
if (parent != null) {
if (parent.getChildren().contains(null)) {
List<PolytomousKeyNode> parentChildren = parent.getChildren();
HHH_9751_Util.removeAllNull(parentChildren);
}
parent.removeChild(node);
dao.saveOrUpdate(parent);
}
if (node.getKey() != null && key != null) {
key.setRoot(null);
}
if (node.getTaxon() != null) {
node.removeTaxon();
}
if (dao.delete(node) == null) {
result.setAbort();
} else {
result.addDeletedObject(node);
}
if (parent != null) {
dao.saveOrUpdate(parent);
result.addUpdatedObject(parent);
} else {
keyDao.saveOrUpdate(key);
result.addUpdatedObject(key);
}
return result;
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyServiceImplTest method testCount.
// ************************* TESTS ********************************************/
/**
* Test method for {@link eu.etaxonomy.cdm.api.service.ServiceBase#count(java.lang.Class)}.
*/
@Test
public void testCount() {
PolytomousKey key = PolytomousKey.NewTitledInstance("My test key");
service.save(key);
Taxon taxon = Taxon.NewInstance(null, null);
key.addTaxonomicScope(taxon);
// Annotation annotation = Annotation.NewInstance("Any annotation", Language.DEFAULT());
// key.addAnnotation(annotation);
PolytomousKeyNode child = PolytomousKeyNode.NewInstance();
Taxon taxon2 = Taxon.NewInstance(null, null);
child.setTaxon(taxon2);
key.getRoot().addChild(child);
service.save(key);
setComplete();
endTransaction();
System.out.println("Count");
printDataSet(System.out, new String[] { "PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING", "POLYTOMOUSKEY_ANNOTATION", "POLYTOMOUSKEY_CREDIT", "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA", "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE", "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE", "ANNOTATION", "TAXONBASE" });
// printDataSet(System.out);
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyServiceImplTest method testDelete.
/**
* Test method for {@link eu.etaxonomy.cdm.api.service.ServiceBase#delete(eu.etaxonomy.cdm.model.common.CdmBase)}.
*/
@Test
@DataSet
public void testDelete() {
System.out.println("Delete start");
printDataSet(System.out, new String[] { "PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING", "POLYTOMOUSKEY_ANNOTATION", "POLYTOMOUSKEY_CREDIT", "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA", "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE", "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE", "ANNOTATION", "TAXONBASE" });
UUID uuid = UUID.fromString("0a709940-4f2e-43c1-8db1-f4745f2a4889");
PolytomousKey key = service.find(uuid);
PolytomousKeyNode someChild = key.getRoot().getChildren().iterator().next();
// service.delete(key);
key.getRoot().removeChild(someChild);
nodeService.delete(someChild);
setComplete();
endTransaction();
System.out.println("Delete End");
printDataSet(System.out, new String[] { "PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING", "POLYTOMOUSKEY_ANNOTATION", "POLYTOMOUSKEY_CREDIT", "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA", "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE", "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE" });
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyGeneratorTest method testDependencyScore.
@Test
public void testDependencyScore() {
generator = new PolytomousKeyGenerator();
// new PolytomousKeyGeneratorConfigurator();
PolytomousKeyGeneratorConfigurator configurator = createDefaultConfig();
// remove shape feature
configurator.getDataSet().getDescriptiveSystem().getRoot().removeChild(0);
configurator.setMerge(true);
configurator.setUseDependencies(true);
PolytomousKey result = generator.invoke(configurator);
result.setTitleCache("Test Dependency Score Key", true);
if (debug) {
result.print(System.out);
}
// Assertions
assertNotNull("Key should exist.", result);
PolytomousKeyNode root = result.getRoot();
Assert.assertEquals("Root feature should be 'presence' as it inherits score from 'length of wings'", featurePresence, root.getFeature());
// ...otherwise it would be color, both have a score of 12.0 but presence comes first in list
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyGeneratorTest method testTaxonomicHierarchy.
@Test
public void testTaxonomicHierarchy() {
tdGenus.getElements().clear();
tdGenus.addElements(mergeTaxDescriptions(td1, td2, td3, td4));
TaxonNode genus1Node = classification.getRootNode().getChildNodes().iterator().next();
removeTaxon5_8(genus1Node);
UUID uuidTdGenus2 = UUID.fromString("3eed217a-fd40-4a38-997f-1f4360133d0d");
Taxon taxonGenus2 = getTaxon(10);
TaxonDescription tdGenus2 = createTaxonDescription(taxonGenus2, "tdGenus2", uuidTdGenus2);
taxa.add(tdGenus2);
TaxonNode genus2Node = classification.getRootNode().addChildTaxon(taxonGenus2, null, null);
genus2Node.addChildTaxon(taxon5, null, null);
genus2Node.addChildTaxon(taxon6, null, null);
genus2Node.addChildTaxon(taxon7, null, null);
genus2Node.addChildTaxon(taxon8, null, null);
tdGenus2.addElements(mergeTaxDescriptions(td5, td6, td7, td8));
PolytomousKeyGeneratorConfigurator configurator = createDefaultConfig();
PolytomousKey result = generator.invoke(configurator);
result.setTitleCache("Merge Key", true);
assertNotNull("Key should exist (merge mode ON).", result);
if (debug) {
result.print(System.out);
}
// Assertions
assertNotNull("Key should exist.", result);
PolytomousKeyNode root = result.getRoot();
Assert.assertEquals(featureShape, root.getFeature());
Assert.assertNull(root.getTaxon());
// triangular or oval
PolytomousKeyNode triangularNode = root.getChildAt(0);
assertInnerNodeWithTaxon(triangularNode, "Oval or Triangular", featureLength, taxonGenus);
// <3
PolytomousKeyNode lessNode = triangularNode.getChildAt(0);
assertInnerNode(lessNode, LESS_3, featureColour);
// blue
assertSingleTaxon(lessNode.getChildAt(0), taxon1, blue);
// yellow
assertSingleTaxon(lessNode.getChildAt(1), taxon2, yellow);
// >3
PolytomousKeyNode gtNode = triangularNode.getChildAt(1);
assertInnerNode(gtNode, GT_3, featureColour);
// blue
assertSingleTaxon(gtNode.getChildAt(0), taxon3, blue);
// yellow
assertSingleTaxon(gtNode.getChildAt(1), taxon4, yellow);
// circular
PolytomousKeyNode circularNode = root.getChildAt(1);
assertInnerNodeWithTaxon(circularNode, circular, featurePresence, taxonGenus2);
// yes
PolytomousKeyNode yesNode = circularNode.getChildAt(0);
assertInnerNode(yesNode, yes, featureLength);
// <3
assertIsTaxonList(yesNode.getChildAt(0), LESS_3, taxon5, taxon6);
// >3
assertSingleTaxon(yesNode.getChildAt(1), taxon7, GT_3);
// no
assertSingleTaxon(circularNode.getChildAt(1), taxon8, no);
}
Aggregations