X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fjcr%2Fexecution%2FJcrExecutionModulesListener.java;h=90b86f3d327549e76cb2693726795d102532e6c7;hb=ac38932aab09592c1ec0af26c26899536dff284f;hp=4d0c55cb0ed76e4f2915850e7e8945037a3112d5;hpb=0b7eb0b64c545d0362d126581816138b609a2026;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java index 4d0c55cb0..90b86f3d3 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java @@ -2,6 +2,7 @@ package org.argeo.slc.jcr.execution; import java.util.Arrays; import java.util.Iterator; +import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; @@ -20,6 +21,7 @@ import org.argeo.slc.core.execution.RefValueChoice; import org.argeo.slc.deploy.ModuleDescriptor; import org.argeo.slc.execution.ExecutionFlowDescriptor; import org.argeo.slc.execution.ExecutionModulesListener; +import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.execution.ExecutionSpec; import org.argeo.slc.execution.ExecutionSpecAttribute; import org.argeo.slc.jcr.SlcJcrUtils; @@ -32,10 +34,14 @@ import org.argeo.slc.jcr.SlcTypes; */ public class JcrExecutionModulesListener implements ExecutionModulesListener, SlcNames { + private final static String SLC_EXECUTION_MODRULES_PROPERTY = "slc.executionModules"; + private final static Log log = LogFactory .getLog(JcrExecutionModulesListener.class); private JcrAgent agent; + private ExecutionModulesManager modulesManager; + /** * We don't use a thread bound session because many different threads will * call this critical component and we don't want to login each time. We @@ -48,6 +54,45 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener, */ public void init() { clearAgent(); + if (modulesManager != null) { + List moduleDescriptors = modulesManager + .listModules(); + String executionModules = System + .getProperty(SLC_EXECUTION_MODRULES_PROPERTY); + if (executionModules != null) + try { + Node agentNode = session.getNode(agent.getNodePath()); + for (String executionModule : executionModules.split(",")) { + for (ModuleDescriptor moduleDescriptor : moduleDescriptors) { + String moduleNodeName = SlcJcrUtils + .getModuleNodeName(moduleDescriptor); + if (moduleDescriptor.getName().equals( + executionModule)) { + Node moduleNode = agentNode + .hasNode(moduleNodeName) ? agentNode + .getNode(moduleNodeName) : agentNode + .addNode(moduleNodeName); + moduleNode + .addMixin(SlcTypes.SLC_EXECUTION_MODULE); + moduleNode.setProperty(SLC_NAME, + moduleDescriptor.getName()); + moduleNode.setProperty(SLC_VERSION, + moduleDescriptor.getVersion()); + moduleNode.setProperty(Property.JCR_TITLE, + moduleDescriptor.getTitle()); + moduleNode.setProperty( + Property.JCR_DESCRIPTION, + moduleDescriptor.getDescription()); + moduleNode.setProperty(SLC_STARTED, false); + } + } + } + session.save(); + } catch (RepositoryException e) { + JcrUtils.discardQuietly(session); + throw new SlcException("Cannot initialize modules", e); + } + } } public void dispose() { @@ -86,6 +131,7 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener, moduleDescriptor.getTitle()); moduleNode.setProperty(Property.JCR_DESCRIPTION, moduleDescriptor.getDescription()); + moduleNode.setProperty(SLC_STARTED, true); session.save(); } catch (RepositoryException e) { JcrUtils.discardQuietly(session); @@ -99,10 +145,16 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener, try { String moduleName = SlcJcrUtils.getModuleNodeName(moduleDescriptor); Node agentNode = session.getNode(agent.getNodePath()); - if (agentNode.hasNode(moduleName)) - agentNode.getNode(moduleName).remove(); - agentNode.getSession().save(); + if (agentNode.hasNode(moduleName)) { + Node moduleNode = agentNode.getNode(moduleName); + for (NodeIterator nit = moduleNode.getNodes(); nit.hasNext();) { + nit.nextNode().remove(); + } + moduleNode.setProperty(SLC_STARTED, false); + } + session.save(); } catch (RepositoryException e) { + JcrUtils.discardQuietly(session); throw new SlcException("Cannot remove module " + moduleDescriptor, e); } @@ -272,4 +324,8 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener, this.session = session; } + public void setModulesManager(ExecutionModulesManager modulesManager) { + this.modulesManager = modulesManager; + } + }