Revert removal of execution flow paths
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 12 Nov 2012 10:11:39 +0000 (10:11 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 12 Nov 2012 10:11:39 +0000 (10:11 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5769 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/ExecutionFlowGenerator.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/FlowBeanDefinitionParser.java
runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java

index 9f2c9dbeabb5bf4c9717635f080f3ee1816153fa..20c3c7c4a28ab312a268f7d4ac3dfe7401f31b3e 100644 (file)
@@ -27,10 +27,12 @@ import org.argeo.slc.execution.ExecutionFlow;
 import org.argeo.slc.execution.ExecutionSpec;
 import org.argeo.slc.execution.ExecutionSpecAttribute;
 import org.springframework.beans.factory.BeanNameAware;
+import org.springframework.beans.factory.InitializingBean;
 import org.springframework.validation.MapBindingResult;
 
 /** Default implementation of an execution flow. */
-public class DefaultExecutionFlow implements ExecutionFlow, BeanNameAware {
+public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean,
+               BeanNameAware {
        private final static Log log = LogFactory
                        .getLog(DefaultExecutionFlow.class);
 
@@ -39,6 +41,8 @@ public class DefaultExecutionFlow implements ExecutionFlow, BeanNameAware {
        private Map<String, Object> parameters = new HashMap<String, Object>();
        private List<Runnable> executables = new ArrayList<Runnable>();
 
+       private String path;
+
        private Boolean failOnError = true;
 
        public DefaultExecutionFlow() {
@@ -132,6 +136,28 @@ public class DefaultExecutionFlow implements ExecutionFlow, BeanNameAware {
                runnable.run();
        }
 
+       public void afterPropertiesSet() throws Exception {
+               if (path == null) {
+                       if (name.charAt(0) == '/') {
+                               path = name.substring(0, name.lastIndexOf('/'));
+                       }
+               }
+
+               if (path != null) {
+                       for (Runnable executable : executables) {
+                               if (executable instanceof DefaultExecutionFlow) {
+                                       // so we don't need to have DefaultExecutionFlow
+                                       // implementing StructureAware
+                                       // FIXME: probably has side effects
+                                       DefaultExecutionFlow flow = (DefaultExecutionFlow) executable;
+                                       String newPath = path + '/' + flow.getName();
+                                       flow.setPath(newPath);
+                                       log.warn(newPath + " was forcibly set on " + flow);
+                               }
+                       }
+               }
+       }
+
        public void setBeanName(String name) {
                this.name = name;
        }
@@ -195,9 +221,12 @@ public class DefaultExecutionFlow implements ExecutionFlow, BeanNameAware {
                return name.hashCode();
        }
 
-       /** @deprecated does nothing */
-       @Deprecated
+       public String getPath() {
+               return path;
+       }
+
        public void setPath(String path) {
+               this.path = path;
        }
 
        public Boolean getFailOnError() {
index ce523a082ea2d0ed8ebad9d699579b980e0a059c..a5a9662158e0de5ba9cb536d474b4f492775f3e0 100644 (file)
@@ -164,6 +164,7 @@ public class DefaultExecutionFlowDescriptorConverter implements
                md.getExecutionFlows().addAll(set);
        }
 
+       @SuppressWarnings("deprecation")
        public ExecutionFlowDescriptor getExecutionFlowDescriptor(
                        ExecutionFlow executionFlow) {
                if (executionFlow.getName() == null)
@@ -211,10 +212,10 @@ public class DefaultExecutionFlowDescriptorConverter implements
 
                ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name, values,
                                executionSpec);
-//             if (executionFlow.getPath() != null)
-//                     efd.setPath(executionFlow.getPath());
-//             else
-//                     efd.setPath("");
+               if (executionFlow.getPath() != null)
+                       efd.setPath(executionFlow.getPath());
+               else
+                       efd.setPath("");
 
                // Takes description from spring
                BeanFactory bf = getBeanFactory();
index 9c1b7fda6398bf81f0797b1be71aa7a091e6bcfc..d7abc7d56f09f0344abd205779f23c2ccaac4e21 100644 (file)
@@ -124,7 +124,8 @@ public class ExecutionFlowGenerator implements BeanFactoryPostProcessor,
                mpv.addPropertyValue("runnableCalls", flowDescriptor.getRunnableCalls());\r
                mpv.addPropertyValue("sharedContextValuesMap", new RuntimeBeanReference(contextValuesBeanName));\r
                \r
-               mpv.addPropertyValue("name", flowDescriptor.getPath() + "/" + beanName);\r
+               mpv.addPropertyValue("name", beanName);\r
+               mpv.addPropertyValue("path", flowDescriptor.getPath());\r
 \r
                mpv.addPropertyValue("executionContext", new RuntimeBeanReference(executionContextBeanName));\r
                \r
index 23b05074840ef8b1ac9bc3eb0e0c397a0b96ccd0..7a1fc721902e7a5c9e1838d3df9ab86462227570 100644 (file)
@@ -42,13 +42,24 @@ public class FlowBeanDefinitionParser extends
                AbstractSingleBeanDefinitionParser {
        private Log log = LogFactory.getLog(FlowBeanDefinitionParser.class);
 
+       /** Whether the user has already be warned on path attribute usage. */
+       private Boolean warnedAboutPathAttribute = false;
+
        @SuppressWarnings("unchecked")
        @Override
        protected void doParse(Element element, ParserContext parserContext,
                        BeanDefinitionBuilder builder) {
                String path = element.getAttribute("path");
-               if (StringUtils.hasText(path))
-                       log.warn("The 'path' attribute is not used anymore to build flows");
+               if (StringUtils.hasText(path)) {
+                       builder.addPropertyValue("path", path);
+
+                       // warns user only once
+                       if (!warnedAboutPathAttribute)
+                               log.warn("The path=\"\" attribute is deprecated"
+                                               + " and will be removed in a later release."
+                                               + " Use <flow:flow name=\"/my/path/flowName\">.");
+                       warnedAboutPathAttribute = true;
+               }
 
                String spec = element.getAttribute("spec");
                if (StringUtils.hasText(spec))
index 387e5eac14f1592fb4793f05fae95fa3e2ec2fcc..f9e737ccfcd73842c788091da8084e28c1cdaa9f 100644 (file)
@@ -31,4 +31,10 @@ public interface ExecutionFlow extends Runnable {
         * interpreted by UIs as a hierarchy;
         */
        public String getName();
+
+       /**
+        * @deprecated will be removed in SLC 2.0, the path should be the part of
+        *             the name with '/'
+        */
+       public String getPath();
 }
index 541d366bf78b2b74fb27b3d422f77ccd4530a265..f63acb5c06faac9f5a21054014fccba7314816c0 100644 (file)
@@ -243,11 +243,6 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                        String relativePath, ExecutionFlowDescriptor efd)
                        throws RepositoryException {
                Node flowNode = null;
-               // if (relativePath.startsWith("/"))
-               // relativePath = relativePath.substring(1);
-               // if (relativePath.endsWith("/"))
-               // relativePath = relativePath.substring(0, relativePath.length() - 1);
-
                Iterator<String> names = Arrays.asList(relativePath.split("/"))
                                .iterator();
                // create intermediary paths
@@ -388,9 +383,12 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
         * UTILITIES
         */
        /** @return the relative path, never starts with '/' */
+       @SuppressWarnings("deprecation")
        protected String getExecutionFlowRelativePath(
                        ExecutionFlowDescriptor executionFlow) {
-               String relativePath = executionFlow.getName();
+               String relativePath = executionFlow.getPath() == null ? executionFlow
+                               .getName() : executionFlow.getPath() + '/'
+                               + executionFlow.getName();
                // we assume that it is more than one char long
                if (relativePath.charAt(0) == '/')
                        relativePath = relativePath.substring(1);
index f85df26aa1e2bce907ba94e75bd649e0323f080b..bd38e6ca83074a5409b1373ca2ef3df8faa17d12 100644 (file)
@@ -596,35 +596,33 @@ public class OsgiExecutionModulesManager extends
                }
        }
 
+       @SuppressWarnings("deprecation")
        protected ObjectName flowMBeanName(Module module,
                        ExecutionFlow executionFlow) {
                String executionModulesPrefix = "SLCExecutionModules";
-               // String path = executionFlow.getPath();
+               String path = executionFlow.getPath();
                String name = executionFlow.getName();
-               // if (path == null && name.indexOf('/') >= 0) {
-               // path = name.substring(0, name.lastIndexOf('/'));
-               // name = name.substring(name.lastIndexOf('/'));
-               // }
+               if (path == null && name.indexOf('/') >= 0) {
+                       path = name.substring(0, name.lastIndexOf('/'));
+                       name = name.substring(name.lastIndexOf('/'));
+               }
 
                StringBuffer buf = new StringBuffer(executionModulesPrefix + ":"
                                + "module=" + module.getName() + " [" + module.getVersion()
                                + "],");
 
-               // if (path != null && !path.equals("")) {
-               // int depth = 0;
-               // for (String token : path.split("/")) {
-               // if (!token.equals("")) {
-               // buf.append("path").append(depth).append('=');
-               // // in order to have directories first
-               // buf.append('/');
-               // buf.append(token).append(',');
-               // depth++;
-               // }
-               // }
-               // }
-
-               // FIXME deal with /
-
+               if (path != null && !path.equals("")) {
+                       int depth = 0;
+                       for (String token : path.split("/")) {
+                               if (!token.equals("")) {
+                                       buf.append("path").append(depth).append('=');
+                                       // in order to have directories first
+                                       buf.append('/');
+                                       buf.append(token).append(',');
+                                       depth++;
+                               }
+                       }
+               }
                buf.append("name=").append(name);
                try {
                        return new ObjectName(buf.toString());