]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.core/src/main/java/org/argeo/slc/hibernate/structure/tree/TreeSRegistryDaoHibernate.java
Start adding enhancement toward v0.8.1
[gpl/argeo-slc.git] / org.argeo.slc.core / src / main / java / org / argeo / slc / hibernate / structure / tree / TreeSRegistryDaoHibernate.java
index 57d06dd1470972eb5d238719f2a91b7b649726f1..15a7cede53ae186f5e9d475d3bc92b81c09e1cf0 100644 (file)
@@ -4,8 +4,15 @@ import java.util.List;
 \r
 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;\r
 \r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+\r
+import org.argeo.slc.core.structure.SimpleSElement;\r
+import org.argeo.slc.core.structure.StructureElement;\r
+import org.argeo.slc.core.structure.StructureRegistry;\r
 import org.argeo.slc.core.structure.tree.TreeSPath;\r
 import org.argeo.slc.core.structure.tree.TreeSRegistry;\r
+import org.argeo.slc.dao.structure.tree.TreeSPathDao;\r
 import org.argeo.slc.dao.structure.tree.TreeSRegistryDao;\r
 \r
 /**\r
@@ -16,8 +23,9 @@ import org.argeo.slc.dao.structure.tree.TreeSRegistryDao;
 public class TreeSRegistryDaoHibernate extends HibernateDaoSupport implements\r
                TreeSRegistryDao {\r
 \r
-       // private static Log log =\r
-       // LogFactory.getLog(TreeSRegistryDaoHibernate.class);\r
+       private TreeSPathDao treeSPathDao;\r
+\r
+       private static Log log = LogFactory.getLog(TreeSRegistryDaoHibernate.class);\r
 \r
        public void create(TreeSRegistry registry) {\r
                getHibernateTemplate().save(registry);\r
@@ -29,7 +37,8 @@ public class TreeSRegistryDaoHibernate extends HibernateDaoSupport implements
 \r
        public TreeSRegistry getActiveTreeSRegistry() {\r
                List<?> list = getHibernateTemplate().find(\r
-                               "from TreeSRegistry where status=?", TreeSRegistry.STATUS_ACTIVE);\r
+                               "from TreeSRegistry where status=?",\r
+                               TreeSRegistry.STATUS_ACTIVE);\r
                if (list.size() == 0) {\r
                        return null;\r
                } else {\r
@@ -37,4 +46,41 @@ public class TreeSRegistryDaoHibernate extends HibernateDaoSupport implements
                }\r
        }\r
 \r
+       public void syncPath(TreeSRegistry registry,\r
+                       StructureRegistry<TreeSPath> localRegistry, TreeSPath path) {\r
+               if (path.getParent() != null) {\r
+                       TreeSPath parent = treeSPathDao.getOrCreate(path.getParent());\r
+                       syncPath(registry, localRegistry, parent);\r
+               }\r
+\r
+               if (log.isDebugEnabled())\r
+                       log.debug("Synchronize path " + path);\r
+               \r
+               if (registry.getElement(path) == null) {\r
+                       if (localRegistry != null) {\r
+                               registry.register(path, getElement(registry, localRegistry, path));\r
+                       } else {\r
+                               registry.register(path, new SimpleSElement(path.getName()));\r
+                       }\r
+                       update(registry);\r
+               } else {\r
+                       if (localRegistry != null) {\r
+                               StructureElement sElement = getElement(registry, localRegistry, path);\r
+                               if (sElement != null) {\r
+                                       registry.register(path, sElement);\r
+                                       update(registry);\r
+                               }\r
+                       }\r
+               }\r
+\r
+       }\r
+\r
+       public void setTreeSPathDao(TreeSPathDao treeSPathDao) {\r
+               this.treeSPathDao = treeSPathDao;\r
+       }\r
+\r
+       protected StructureElement getElement(TreeSRegistry registry,\r
+                       StructureRegistry<TreeSPath> localRegistry, TreeSPath path){\r
+               return localRegistry.getElement(path);\r
+       }\r
 }\r