From: Andreas Müller Date: Thu, 28 Jul 2022 14:41:59 +0000 (+0200) Subject: cleanup X-Git-Tag: 5.32.0^2~58 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/cdmlib.git/commitdiff_plain/0e628c63084ac8932f893a7bb1633f2f06664959 cleanup --- diff --git a/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmEntityDaoBase.java b/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmEntityDaoBase.java index 204a99d0c6..981e1f4089 100644 --- a/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmEntityDaoBase.java +++ b/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmEntityDaoBase.java @@ -388,6 +388,7 @@ public abstract class CdmEntityDaoBase return null; } + // Ben Clark: // Merge the object in if it is detached // // I think this is preferable to catching lazy initialization errors diff --git a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java index 393826729c..b6e09b2897 100644 --- a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java +++ b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java @@ -46,8 +46,8 @@ public class PolytomousKeyNodeServiceImpl 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."));; + if (node == null) { + // result.addException(new Exception("The polytomouskey node was already deleted.")); return result; } List children = new ArrayList<>(); @@ -64,7 +64,6 @@ public class PolytomousKeyNodeServiceImpl } if(!deleteChildren){ - for (PolytomousKeyNode child: children){ if (!child.equals(node)){ parent.addChild(child); diff --git a/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceTest.java b/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceTest.java index 74e1bf2556..b731d5bc90 100644 --- a/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceTest.java +++ b/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceTest.java @@ -24,6 +24,8 @@ import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest; public class PolytomousKeyNodeServiceTest extends CdmTransactionalIntegrationTest { + String[] tableNames = new String[]{"POLYTOMOUSKEY","POLYTOMOUSKEYNODE","POLYTOMOUSKEYNODE_AUD"}; + @SpringBeanByType private IPolytomousKeyNodeService service; @@ -44,48 +46,49 @@ public class PolytomousKeyNodeServiceTest extends CdmTransactionalIntegrationTes //create key PolytomousKey key = PolytomousKey.NewTitledInstance("TestPolytomousKey"); keyService.save(key); - PolytomousKeyNode node = PolytomousKeyNode.NewInstance("Test statement"); - key.setRoot(node); + PolytomousKeyNode root1 = PolytomousKeyNode.NewInstance("Test statement"); + key.setRoot(root1); key.setStartNumber(0); - PolytomousKeyNode child = PolytomousKeyNode.NewInstance("Test statement Nr 2"); - node.addChild(child,0); - service.save(node); + PolytomousKeyNode child2 = PolytomousKeyNode.NewInstance("Test statement Nr 2"); + UUID uuidChild2 = child2.getUuid(); + root1.addChild(child2,0); + service.save(root1); - PolytomousKeyNode child1 = PolytomousKeyNode.NewInstance("Test statement Nr 3"); - child.addChild(child1,0); - UUID uuidChild = service.save(child).getUuid(); + PolytomousKeyNode child3 = PolytomousKeyNode.NewInstance("Test statement Nr 3"); + UUID uuidChild3 = child3.getUuid(); + child2.addChild(child3, 0); + service.save(child2).getUuid(); - PolytomousKeyNode child2 = PolytomousKeyNode.NewInstance("Test statement Nr 4"); - child1.addChild(child2,0); - UUID uuidChild1 = service.save(child1).getUuid(); + PolytomousKeyNode child4 = PolytomousKeyNode.NewInstance("Test statement Nr 4"); + UUID uuidChild4 = child4.getUuid(); + child3.addChild(child4, 0); + service.save(child3).getUuid(); //assert key - node = service.load(uuidChild1); - UUID uuidChild2 = node.getChildAt(0).getUuid(); - assertNotNull(node); - - //delete - service.delete(uuidChild1, false); - node = service.load(uuidChild1); - assertNull(node); - node = service.load(uuidChild2); - assertNotNull(node); - - node = service.load(uuidChild); - - assertNotNull(node); - service.delete(uuidChild, true); - node = service.load(uuidChild); - assertNull(node); - node = service.load(uuidChild2); - assertNull(node); + PolytomousKeyNode loaded3 = service.load(uuidChild3); + assertNotNull(loaded3); + + //assert delete without children + service.delete(uuidChild3, false); + loaded3 = service.load(uuidChild3); + assertNull(loaded3); + PolytomousKeyNode loaded4 = service.load(uuidChild4); + assertNotNull("Child4 should be moved to " + + "parent child2 but not removed completely", loaded4); + + //assert delete with children + PolytomousKeyNode loaded2 = service.load(uuidChild2); + assertNotNull(loaded2); + service.delete(uuidChild2, true); + loaded2 = service.load(uuidChild2); + assertNull(loaded2); + loaded4 = service.load(uuidChild4); + assertNull("Child4 should be deleted with child3 this time", loaded4); } @Test //8127 //5536 public final void testMerge(){ - String[] tableNames = new String[] {"POLYTOMOUSKEY","POLYTOMOUSKEYNODE","POLYTOMOUSKEYNODE_AUD"}; - logger.warn(tableNames); //create key with 2 child nodes PolytomousKey key = PolytomousKey.NewTitledInstance("TestPolytomousKey"); @@ -109,7 +112,6 @@ public class PolytomousKeyNodeServiceTest extends CdmTransactionalIntegrationTes service.merge(rootNode); commitAndStartNewTransaction(tableNames); - System.out.println("NEXT"); //test result rootNode = service.find(key.getRoot().getUuid()); @@ -119,6 +121,7 @@ public class PolytomousKeyNodeServiceTest extends CdmTransactionalIntegrationTes Assert.assertEquals(child3.getUuid(), rootNode.getChildren().get(1).getUuid()); commitAndStartNewTransaction(); + System.out.println("NEXT"); //same with key //load root node and make it detached PolytomousKey keyLoaded = keyService.find(key.getUuid()); diff --git a/cdmlib-test/src/main/java/eu/etaxonomy/cdm/test/integration/CdmIntegrationTest.java b/cdmlib-test/src/main/java/eu/etaxonomy/cdm/test/integration/CdmIntegrationTest.java index 7ccc8027de..bab2262eaf 100644 --- a/cdmlib-test/src/main/java/eu/etaxonomy/cdm/test/integration/CdmIntegrationTest.java +++ b/cdmlib-test/src/main/java/eu/etaxonomy/cdm/test/integration/CdmIntegrationTest.java @@ -298,7 +298,6 @@ public abstract class CdmIntegrationTest extends UnitilsJUnit4 { */ public void printDataSet(OutputStream out, String ... includeTableNames) { dbTablePrinter.printDataSet(out, includeTableNames); - } /**