Start simplifying and clarifying CMS initialisation. Remove Jackrabbit
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / kernel / CmsDeployment.java
index 7a6ae064667817ff764d0bc3dc37e2da1ea1a45a..34d6e1f2482cac3cce54234f8eee249204dd6bdc 100644 (file)
@@ -1,8 +1,9 @@
 package org.argeo.cms.internal.kernel;
 
-import static org.argeo.node.DataModelNamespace.CMS_DATA_MODEL_NAMESPACE;
+import static org.argeo.api.DataModelNamespace.CMS_DATA_MODEL_NAMESPACE;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.lang.management.ManagementFactory;
@@ -26,15 +27,15 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.commons.cnd.CndImporter;
 import org.apache.jackrabbit.core.RepositoryContext;
 import org.apache.jackrabbit.core.RepositoryImpl;
+import org.argeo.api.DataModelNamespace;
+import org.argeo.api.NodeConstants;
+import org.argeo.api.NodeDeployment;
+import org.argeo.api.NodeState;
+import org.argeo.api.security.CryptoKeyring;
+import org.argeo.api.security.Keyring;
 import org.argeo.cms.ArgeoNames;
 import org.argeo.cms.CmsException;
 import org.argeo.jcr.JcrUtils;
-import org.argeo.node.DataModelNamespace;
-import org.argeo.node.NodeConstants;
-import org.argeo.node.NodeDeployment;
-import org.argeo.node.NodeState;
-import org.argeo.node.security.CryptoKeyring;
-import org.argeo.node.security.Keyring;
 import org.argeo.osgi.useradmin.UserAdminConf;
 import org.argeo.util.LangUtils;
 import org.eclipse.equinox.http.jetty.JettyConfigurator;
@@ -62,11 +63,10 @@ public class CmsDeployment implements NodeDeployment {
 
        private DataModels dataModels;
        private DeployConfig deployConfig;
-       private HomeRepository homeRepository;
 
        private Long availableSince;
 
-       private final boolean cleanState;
+//     private final boolean cleanState;
 
        private NodeHttp nodeHttp;
 
@@ -79,14 +79,14 @@ public class CmsDeployment implements NodeDeployment {
        private boolean httpAvailable = false;
 
        public CmsDeployment() {
-               ServiceReference<NodeState> nodeStateSr = bc.getServiceReference(NodeState.class);
-               if (nodeStateSr == null)
-                       throw new CmsException("No node state available");
+//             ServiceReference<NodeState> nodeStateSr = bc.getServiceReference(NodeState.class);
+//             if (nodeStateSr == null)
+//                     throw new CmsException("No node state available");
 
-               NodeState nodeState = bc.getService(nodeStateSr);
-               cleanState = nodeState.isClean();
+//             NodeState nodeState = bc.getService(nodeStateSr);
+//             cleanState = nodeState.isClean();
 
-               nodeHttp = new NodeHttp(cleanState);
+               nodeHttp = new NodeHttp();
                dataModels = new DataModels(bc);
                initTrackers();
        }
@@ -126,17 +126,17 @@ public class CmsDeployment implements NodeDeployment {
                        @Override
                        public ConfigurationAdmin addingService(ServiceReference<ConfigurationAdmin> reference) {
                                ConfigurationAdmin configurationAdmin = bc.getService(reference);
-                               deployConfig = new DeployConfig(configurationAdmin, dataModels, cleanState);
+                               boolean isClean;
+                               try {
+                                       Configuration[] confs = configurationAdmin
+                                                       .listConfigurations("(service.factoryPid=" + NodeConstants.NODE_USER_ADMIN_PID + ")");
+                                       isClean = confs == null || confs.length == 0;
+                               } catch (Exception e) {
+                                       throw new CmsException("Cannot analize clean state", e);
+                               }
+                               deployConfig = new DeployConfig(configurationAdmin, dataModels, isClean);
                                httpExpected = deployConfig.getProps(KernelConstants.JETTY_FACTORY_PID, "default") != null;
                                try {
-                                       // Configuration[] configs = configurationAdmin
-                                       // .listConfigurations("(service.factoryPid=" +
-                                       // NodeConstants.NODE_REPOS_FACTORY_PID + ")");
-                                       // for (Configuration config : configs) {
-                                       // Object cn = config.getProperties().get(NodeConstants.CN);
-                                       // if (log.isDebugEnabled())
-                                       // log.debug("Standalone repo cn: " + cn);
-                                       // }
                                        Configuration[] configs = configurationAdmin
                                                        .listConfigurations("(service.factoryPid=" + NodeConstants.NODE_USER_ADMIN_PID + ")");
 
@@ -268,7 +268,7 @@ public class CmsDeployment implements NodeDeployment {
                }
 
                // home
-               prepareDataModel(NodeConstants.NODE, deployedNodeRepository);
+               prepareDataModel(NodeConstants.NODE_REPOSITORY, deployedNodeRepository);
        }
 
        private void prepareHomeRepository(RepositoryImpl deployedRepository) {
@@ -286,10 +286,10 @@ public class CmsDeployment implements NodeDeployment {
 
                // Publish home with the highest service ranking
                Hashtable<String, Object> regProps = new Hashtable<>();
-               regProps.put(NodeConstants.CN, NodeConstants.HOME);
+               regProps.put(NodeConstants.CN, NodeConstants.EGO_REPOSITORY);
                regProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
-               homeRepository = new HomeRepository(deployedRepository, false);
-               bc.registerService(Repository.class, homeRepository, regProps);
+               Repository egoRepository = new EgoRepository(deployedRepository, false);
+               bc.registerService(Repository.class, egoRepository, regProps);
 
                // Keyring only if Argeo extensions are available
                if (argeoDataModelExtensionsAvailable) {
@@ -297,7 +297,7 @@ public class CmsDeployment implements NodeDeployment {
 
                                @Override
                                public CallbackHandler addingService(ServiceReference<CallbackHandler> reference) {
-                                       NodeKeyRing nodeKeyring = new NodeKeyRing(homeRepository);
+                                       NodeKeyRing nodeKeyring = new NodeKeyRing(egoRepository);
                                        CallbackHandler callbackHandler = bc.getService(reference);
                                        nodeKeyring.setDefaultCallbackHandler(callbackHandler);
                                        bc.registerService(LangUtils.names(Keyring.class, CryptoKeyring.class, ManagedService.class),
@@ -318,7 +318,7 @@ public class CmsDeployment implements NodeDeployment {
                                BundleWiring wiring = bundle.adapt(BundleWiring.class);
                                if (wiring == null)
                                        continue bundles;
-                               if (NodeConstants.NODE.equals(cn))// process all data models
+                               if (NodeConstants.NODE_REPOSITORY.equals(cn))// process all data models
                                        processWiring(cn, adminSession, wiring, processed, false);
                                else {
                                        List<BundleCapability> capabilities = wiring.getCapabilities(CMS_DATA_MODEL_NAMESPACE);
@@ -396,7 +396,7 @@ public class CmsDeployment implements NodeDeployment {
                boolean publishLocalRepo;
                if (isStandalone && name.equals(cn))// includes the node itself
                        publishLocalRepo = true;
-               else if (!isStandalone && cn.equals(NodeConstants.NODE))
+               else if (!isStandalone && cn.equals(NodeConstants.NODE_REPOSITORY))
                        publishLocalRepo = true;
                else
                        publishLocalRepo = false;
@@ -442,7 +442,7 @@ public class CmsDeployment implements NodeDeployment {
                        RepositoryContext repoContext = bc.getService(reference);
                        String cn = (String) reference.getProperty(NodeConstants.CN);
                        if (cn != null) {
-                               if (cn.equals(NodeConstants.NODE)) {
+                               if (cn.equals(NodeConstants.NODE_REPOSITORY)) {
                                        prepareNodeRepository(repoContext.getRepository());
                                        // TODO separate home repository
                                        prepareHomeRepository(repoContext.getRepository());