minor changes
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / DistributionTree.java
index fe2d8523ce9bc795e78d8e8d9587a54d15ca4665..6d7f41f62d8f3ed30d6f4c2c20509ffa433a7975 100644 (file)
@@ -19,7 +19,7 @@ public class DistributionTree extends Tree<Distribution>{
                NamedArea area = new NamedArea();\r
                Distribution data = Distribution.NewInstance();\r
                data.setArea(area);\r
                NamedArea area = new NamedArea();\r
                Distribution data = Distribution.NewInstance();\r
                data.setArea(area);\r
-               data.addModifyingText("test", Language.ENGLISH());\r
+               //data.addModifyingText("test", Language.ENGLISH());\r
                TreeNode<Distribution> rootElement = new TreeNode<Distribution>();\r
                List<TreeNode<Distribution>> children = new ArrayList<TreeNode<Distribution>>();\r
                \r
                TreeNode<Distribution> rootElement = new TreeNode<Distribution>();\r
                List<TreeNode<Distribution>> children = new ArrayList<TreeNode<Distribution>>();\r
                \r
@@ -96,34 +96,33 @@ public class DistributionTree extends Tree<Distribution>{
                                                  NamedAreaLevel level,\r
                                                  List<NamedArea> areaHierarchieList, \r
                                                  TreeNode<Distribution> root){\r
                                                  NamedAreaLevel level,\r
                                                  List<NamedArea> areaHierarchieList, \r
                                                  TreeNode<Distribution> root){\r
+               boolean containsChild, sameLevel = false;\r
                TreeNode<Distribution> highestDistNode;\r
                TreeNode<Distribution> child;// the new child to add or the child to follow through the tree\r
                //if the list to merge is empty finish the execution\r
                if (areaHierarchieList.isEmpty()) {\r
                        return;\r
                }\r
                TreeNode<Distribution> highestDistNode;\r
                TreeNode<Distribution> child;// the new child to add or the child to follow through the tree\r
                //if the list to merge is empty finish the execution\r
                if (areaHierarchieList.isEmpty()) {\r
                        return;\r
                }\r
-               //getting the highest area and inserting it into the tree\r
+               //getting the highest area and inserting it (if neccesary) into the tree\r
                NamedArea highestArea = areaHierarchieList.get(0);\r
                NamedArea highestArea = areaHierarchieList.get(0);\r
-               //NamedAreaLevel highestAreaLevel = (NamedAreaLevel) HibernateProxyHelper.deproxy(highestArea.getLevel());\r
-               //NamedAreaLevel currentLevel = (NamedAreaLevel) HibernateProxyHelper.deproxy(level);\r
-               //if (highestAreaLevel.compareTo(currentLevel) == 0){//if distribution.status is relevant\r
-               \r
-               if (highestArea.getLevel().getLabel().compareTo(level.getLabel()) == 0){\r
-                       highestDistNode = new TreeNode<Distribution>(distribution);//distribution.area comes from proxy!!!!\r
+               sameLevel = highestArea.getLevel().getLabel().compareTo(level.getLabel()) == 0;\r
+               if (sameLevel){\r
+                       highestDistNode = new TreeNode<Distribution>(distribution);\r
                }else{ //if distribution.status is not relevant\r
                        Distribution data = Distribution.NewInstance(highestArea, null);\r
                        highestDistNode = new TreeNode<Distribution>(data);\r
                }\r
                }else{ //if distribution.status is not relevant\r
                        Distribution data = Distribution.NewInstance(highestArea, null);\r
                        highestDistNode = new TreeNode<Distribution>(data);\r
                }\r
-               if(highestDistNode.data.getModifyingText().isEmpty()){\r
-                       highestDistNode.data.addModifyingText("test", Language.ENGLISH());\r
-               }\r
-\r
-               if (root.getChildren().isEmpty() || !containsChild(root, highestDistNode)) {\r
+               containsChild = containsChild(root, highestDistNode);\r
+               if (root.getChildren().isEmpty() || !containsChild) {\r
                        //if the highest level is not on the depth-1 of the tree we add it.\r
                        //child = highestDistNode;\r
                        //if the highest level is not on the depth-1 of the tree we add it.\r
                        //child = highestDistNode;\r
-                       child = new TreeNode<Distribution>(highestDistNode.data);\r
-                       root.addChild(child);//child.getData().getArea().getUuid().toString().equals("8cfc1722-e1e8-49d3-95a7-9879de6de490");\r
+                       child = new TreeNode<Distribution>(highestDistNode.data); \r
+                       root.addChild(child);\r
                }else {\r
                }else {\r
+                       //adding the sources to the child\r
+                       if(containsChild && sameLevel){\r
+                               getChild(root, highestDistNode).data.getSources().addAll(highestDistNode.data.getSources());\r
+                       }\r
                        //if the deepth-1 of the tree contains the highest area level\r
                        //get the subtree or create it in order to continuing merging\r
                        child = getChild(root,highestDistNode);\r
                        //if the deepth-1 of the tree contains the highest area level\r
                        //get the subtree or create it in order to continuing merging\r
                        child = getChild(root,highestDistNode);\r
@@ -135,12 +134,12 @@ public class DistributionTree extends Tree<Distribution>{
        \r
        private List<NamedArea> getAreaLevelPathList(NamedArea area, Set<NamedAreaLevel> omitLevels){\r
                List<NamedArea> result = new ArrayList<NamedArea>();\r
        \r
        private List<NamedArea> getAreaLevelPathList(NamedArea area, Set<NamedAreaLevel> omitLevels){\r
                List<NamedArea> result = new ArrayList<NamedArea>();\r
-               if (!omitLevels.contains(area.getLevel())){\r
+               if (omitLevels == null || !omitLevels.contains(area.getLevel())){\r
                        result.add(area);               \r
                }\r
                while (area.getPartOf() != null) {\r
                        area = area.getPartOf();\r
                        result.add(area);               \r
                }\r
                while (area.getPartOf() != null) {\r
                        area = area.getPartOf();\r
-                       if (!omitLevels.contains(area.getLevel())){\r
+                       if (omitLevels == null || !omitLevels.contains(area.getLevel())){\r
                                result.add(0, area);\r
                        }\r
                }\r
                                result.add(0, area);\r
                        }\r
                }\r