use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyDaoImpl method delete.
@Override
public UUID delete(PolytomousKey key) {
key = this.load(key.getUuid());
key = HibernateProxyHelper.deproxy(key, PolytomousKey.class);
if (key.getRoot() != null) {
PolytomousKeyNode root = HibernateProxyHelper.deproxy(key.getRoot(), PolytomousKeyNode.class);
key.setRoot(null);
nodeDao.delete(root);
}
getSession().delete(key);
return key.getUuid();
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class IkeyPlusImportTest method testDoInvoke.
@Test
@DataSets({ @DataSet(/*loadStrategy=CleanSweepInsertLoadStrategy.class,*/
value = "/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"), @DataSet(value = "/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml") })
public void testDoInvoke() {
UUID newKeyUuid = null;
try {
ikeyPlusImport.getKey(sddUri, null);
newKeyUuid = ikeyPlusImport.getCdmKey().getUuid();
} catch (Exception e) {
throw new RuntimeException(e);
}
commitAndStartNewTransaction(null);
PolytomousKey pk = polytomousKeyService.find(newKeyUuid);
Assert.assertNotNull(pk);
// assertEquals("Number of TaxonNames should be 1", 1, nameService.count(null));
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyGeneratorTest method testInvokeWithoutDependencies.
/**
* With dependencies is difficult to check because it only changes the performance
* if data is clean. So in this test we first check some dirty data with
* dependency check and then without.
* In the first run it correctly removes the length of wings check at the end
* as length of wings is not applicable if presence of wings = no.
* In the second run it does the length of wings check as it does not
* use dependency check.
*/
@Test
public void testInvokeWithoutDependencies() {
generator = new PolytomousKeyGenerator();
PolytomousKeyGeneratorConfigurator configurator = createDefaultConfig();
configurator.setMerge(true);
configurator.setUseDependencies(true);
catd27.getStateData().get(0).setState(no);
td8.addElement(qtd38);
PolytomousKey result = generator.invoke(configurator);
result.setTitleCache("Merge Key with dependency", true);
assertNotNull("Key should exist (dependency on)", result);
if (debug) {
result.print(System.out);
}
// Assertions
assertNotNull("Key should exist.", result);
PolytomousKeyNode root = result.getRoot();
Assert.assertEquals(featureShape, root.getFeature());
// circular
PolytomousKeyNode circularNode = root.getChildAt(1);
assertInnerNode(circularNode, circular, featurePresence);
// no
assertIsTaxonList(circularNode.getChildAt(0), no, taxon8, taxon7);
// yes
assertIsTaxonList(circularNode.getChildAt(1), yes, taxon5, taxon6);
// and now without dependency check
configurator.setUseDependencies(false);
result = generator.invoke(configurator);
result.setTitleCache("Merge Key without dependency", true);
assertNotNull("Key should exist (dependency off)", result);
if (debug) {
result.print(System.out);
}
// Assertions
assertNotNull("Key should exist.", result);
root = result.getRoot();
Assert.assertEquals(featureShape, root.getFeature());
// circular
circularNode = root.getChildAt(1);
assertInnerNode(circularNode, circular, featurePresence);
// no
PolytomousKeyNode noNode = assertInnerNode(circularNode.getChildAt(0), no, featureLength);
// as dependency check is switched off we distinguish length, though length should be inapplicable here
assertSingleTaxon(noNode.getChildAt(0), taxon8, LESS_3);
assertSingleTaxon(noNode.getChildAt(1), taxon7, GT_3);
// yes
assertIsTaxonList(circularNode.getChildAt(1), yes, taxon5, taxon6);
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyGeneratorTest method testInvokeMergeModeOff.
// *************************** TESTS *********************** /
@Test
public void testInvokeMergeModeOff() {
PolytomousKeyGeneratorConfigurator configurator = createDefaultConfig();
configurator.setMerge(false);
PolytomousKey result = generator.invoke(configurator);
result.setTitleCache("No Merge Key", true);
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());
// circular
PolytomousKeyNode circularNode = root.getChildAt(0);
assertInnerNode(circularNode, circular, featurePresence);
// yes
PolytomousKeyNode yesNode = circularNode.getChildAt(0);
assertInnerNode(yesNode, yes, featureLength);
// <3
PolytomousKeyNode less3Node = yesNode.getChildAt(0);
assertIsTaxonList(less3Node, LESS_3, taxon5, taxon6);
// >3
assertSingleTaxon(yesNode.getChildAt(1), taxon7, GT_3);
// no
assertSingleTaxon(circularNode.getChildAt(1), taxon8, no);
// triangular
PolytomousKeyNode triangularNode = root.getChildAt(1);
assertInnerNode(triangularNode, triangular, featureLength);
// <3
less3Node = triangularNode.getChildAt(0);
// blue
assertSingleTaxon(less3Node.getChildAt(0), taxon1, blue);
// yellow
assertSingleTaxon(less3Node.getChildAt(1), taxon2, yellow);
// >3
PolytomousKeyNode gt3Node = triangularNode.getChildAt(1);
assertInnerNode(gt3Node, GT_3, featureColour);
// blue
assertSingleTaxon(gt3Node.getChildAt(0), taxon3, blue);
// yellow
assertSingleTaxon(gt3Node.getChildAt(1), taxon4, yellow);
// oval
assertSingleTaxon(root.getChildAt(2), taxon1, oval);
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PostMergeEntityListener method removeNullFromCollections.
private static void removeNullFromCollections(Object entity) {
if (entity != null) {
Class<?> entityClazz = entity.getClass();
if (TaxonNode.class.isAssignableFrom(entityClazz)) {
TaxonNode node = (TaxonNode) entity;
node.removeNullValueFromChildren();
} else if (PolytomousKeyNode.class.isAssignableFrom(entityClazz)) {
PolytomousKeyNode node = (PolytomousKeyNode) entity;
if (node.getChildren() != null && Hibernate.isInitialized(node.getChildren())) {
node.removeNullValueFromChildren();
for (PolytomousKeyNode childNode : node.getChildren()) {
removeNullFromCollections(childNode);
}
}
} else if (PolytomousKey.class.isAssignableFrom(entityClazz)) {
PolytomousKey key = (PolytomousKey) entity;
PolytomousKeyNode node = key.getRoot();
if (node != null && node.getChildren() != null && Hibernate.isInitialized(node.getChildren())) {
node.removeNullValueFromChildren();
for (PolytomousKeyNode childNode : node.getChildren()) {
removeNullFromCollections(childNode);
}
}
} else if (TermTree.class.isAssignableFrom(entityClazz)) {
TermTree<?> tree = (TermTree<?>) entity;
tree.removeNullValueFromChildren();
try {
for (TermNode<?> node : tree.getRootChildren()) {
node.removeNullValueFromChildren();
if (node.getChildNodes() != null) {
for (TermNode<?> childNode : node.getChildNodes()) {
removeNullFromCollections(childNode);
}
}
}
} catch (LazyInitializationException e) {
logger.warn("Cannot clean up uninitialized children without a session, skipping.");
}
} else if (TermNode.class.isAssignableFrom(entityClazz)) {
TermNode<?> node = (TermNode<?>) entity;
if (Hibernate.isInitialized(node.getChildNodes())) {
node.removeNullValueFromChildren();
}
}
}
}
Aggregations