]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/internal/kernel/CmsDeployment.java
Move Eclipse components which are JCR specific.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / kernel / CmsDeployment.java
index a19bbaf353daf78a3f375c1bb7004a59c552cdd6..026f9186bc710fdac802ee13d650db681555818f 100644 (file)
@@ -11,9 +11,11 @@ import java.lang.management.ManagementFactory;
 import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -44,9 +46,11 @@ import org.argeo.cms.ArgeoNames;
 import org.argeo.cms.internal.http.CmsRemotingServlet;
 import org.argeo.cms.internal.http.CmsWebDavServlet;
 import org.argeo.cms.internal.http.HttpUtils;
+import org.argeo.cms.internal.jcr.JcrInitUtils;
 import org.argeo.jcr.Jcr;
 import org.argeo.jcr.JcrException;
 import org.argeo.jcr.JcrUtils;
+import org.argeo.maintenance.backup.LogicalRestore;
 import org.argeo.naming.LdapAttrs;
 import org.argeo.osgi.useradmin.UserAdminConf;
 import org.argeo.util.LangUtils;
@@ -153,6 +157,7 @@ public class CmsDeployment implements NodeDeployment {
                                        throw new IllegalStateException("Cannot analyse clean state", e);
                                }
                                deployConfig = new DeployConfig(configurationAdmin, dataModels, isClean);
+                               JcrInitUtils.addToDeployment(CmsDeployment.this);
                                httpExpected = deployConfig.getProps(KernelConstants.JETTY_FACTORY_PID, "default") != null;
                                try {
                                        Configuration[] configs = configurationAdmin
@@ -179,6 +184,20 @@ public class CmsDeployment implements NodeDeployment {
                KernelUtils.asyncOpen(confAdminSt);
        }
 
+       public void addFactoryDeployConfig(String factoryPid, Dictionary<String, Object> props) {
+               deployConfig.putFactoryDeployConfig(factoryPid, props);
+               deployConfig.save();
+               try {
+                       deployConfig.loadConfigs();
+               } catch (IOException e) {
+                       throw new IllegalStateException(e);
+               }
+       }
+
+       public Dictionary<String, Object> getProps(String factoryPid, String cn) {
+               return deployConfig.getProps(factoryPid, cn);
+       }
+
        private String httpPortsMsg(Object httpPort, Object httpsPort) {
                return (httpPort != null ? "HTTP " + httpPort + " " : " ") + (httpsPort != null ? "HTTPS " + httpsPort : "");
        }
@@ -292,6 +311,18 @@ public class CmsDeployment implements NodeDeployment {
                // home
                prepareDataModel(NodeConstants.NODE_REPOSITORY, deployedNodeRepository, publishAsLocalRepo);
 
+               // init from backup
+               if (deployConfig.isFirstInit()) {
+                       Path restorePath = Paths.get(System.getProperty("user.dir"), "restore");
+                       if (Files.exists(restorePath)) {
+                               if (log.isDebugEnabled())
+                                       log.debug("Found backup " + restorePath + ", restoring it...");
+                               LogicalRestore logicalRestore = new LogicalRestore(bc, deployedNodeRepository, restorePath);
+                               KernelUtils.doAsDataAdmin(logicalRestore);
+                               log.info("Restored backup from " + restorePath);
+                       }
+               }
+
                // init from repository
                Collection<ServiceReference<Repository>> initRepositorySr;
                try {
@@ -320,6 +351,9 @@ public class CmsDeployment implements NodeDeployment {
                        workspaces: for (String workspaceName : initSession.getWorkspace().getAccessibleWorkspaceNames()) {
                                if ("security".equals(workspaceName))
                                        continue workspaces;
+                               if (log.isDebugEnabled())
+                                       log.debug("Copying workspace " + workspaceName + " from init repository...");
+                               long begin = System.currentTimeMillis();
                                Session targetSession = null;
                                Session sourceSession = null;
                                try {
@@ -335,8 +369,16 @@ public class CmsDeployment implements NodeDeployment {
                                                targetSession = NodeUtils.openDataAdminSession(deployedNodeRepository, workspaceName);
                                        }
                                        sourceSession = initRepository.login(workspaceName);
+//                                     JcrUtils.copyWorkspaceXml(sourceSession, targetSession);
+                                       // TODO deal with referenceable nodes
                                        JcrUtils.copy(sourceSession.getRootNode(), targetSession.getRootNode());
                                        targetSession.save();
+                                       long duration = System.currentTimeMillis() - begin;
+                                       if (log.isDebugEnabled())
+                                               log.debug("Copied workspace " + workspaceName + " from init repository in " + (duration / 1000)
+                                                               + " s");
+                               } catch (Exception e) {
+                                       log.error("Cannot copy workspace " + workspaceName + " from init repository.", e);
                                } finally {
                                        Jcr.logout(sourceSession);
                                        Jcr.logout(targetSession);
@@ -570,6 +612,7 @@ public class CmsDeployment implements NodeDeployment {
                        if (cn != null) {
                                List<String> publishAsLocalRepo = new ArrayList<>();
                                if (cn.equals(NodeConstants.NODE_REPOSITORY)) {
+//                                     JackrabbitDataModelMigration.clearRepositoryCaches(repoContext.getRepositoryConfig());
                                        prepareNodeRepository(repoContext.getRepository(), publishAsLocalRepo);
                                        // TODO separate home repository
                                        prepareHomeRepository(repoContext.getRepository());