]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionProcess.java
Fix bug 28 (https://www.argeo.org/bugzilla/show_bug.cgi?id=28)
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.jcr / src / main / java / org / argeo / slc / jcr / execution / JcrExecutionProcess.java
index b2fa33395b51d8bf8a586acbfb39642eb88d3267..e9a3b6380fd803dcc478b9a7e6375fe3f8eb91d1 100644 (file)
@@ -1,10 +1,28 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.argeo.slc.jcr.execution;
 
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 import java.util.List;
 
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 
 import org.apache.commons.logging.Log;
@@ -13,12 +31,13 @@ import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.execution.ExecutionProcess;
 import org.argeo.slc.execution.ExecutionStep;
+import org.argeo.slc.execution.RealizedFlow;
 import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
 
 /** Execution process implementation based on a JCR node. */
 public class JcrExecutionProcess implements ExecutionProcess, SlcNames {
-       private Log log = LogFactory.getLog(JcrExecutionProcess.class);
+       private final static Log log = LogFactory.getLog(JcrExecutionProcess.class);
        private final Node node;
 
        private Long nextLogLine = 1l;
@@ -27,7 +46,7 @@ public class JcrExecutionProcess implements ExecutionProcess, SlcNames {
                this.node = node;
        }
 
-       public String getUuid() {
+       public synchronized String getUuid() {
                try {
                        return node.getProperty(SLC_UUID).getString();
                } catch (RepositoryException e) {
@@ -35,7 +54,7 @@ public class JcrExecutionProcess implements ExecutionProcess, SlcNames {
                }
        }
 
-       public String getStatus() {
+       public synchronized String getStatus() {
                try {
                        return node.getProperty(SLC_STATUS).getString();
                } catch (RepositoryException e) {
@@ -47,7 +66,7 @@ public class JcrExecutionProcess implements ExecutionProcess, SlcNames {
                }
        }
 
-       public void setStatus(String status) {
+       public synchronized void setStatus(String status) {
                try {
                        node.setProperty(SLC_STATUS, status);
                        // last modified properties needs to be manually updated
@@ -85,9 +104,14 @@ public class JcrExecutionProcess implements ExecutionProcess, SlcNames {
                                        // skip
                                        continue steps;
 
-                               String relPath = SLC_LOG + '/' + step.getThread() + '/'
+                               String relPath = SLC_LOG + '/'
+                                               + step.getThread().replace('/', '_') + '/'
                                                + step.getLocation().replace('.', '/');
                                String path = node.getPath() + '/' + relPath;
+                               // clean special character
+                               // TODO factorize in JcrUtils
+                               path = path.replace('@', '_');
+
                                Node location = JcrUtils.mkdirs(node.getSession(), path);
                                Node logEntry = location.addNode(Long.toString(nextLogLine),
                                                type);
@@ -106,14 +130,50 @@ public class JcrExecutionProcess implements ExecutionProcess, SlcNames {
                        JcrUtils.updateLastModified(node);
 
                        node.getSession().save();
-               } catch (RepositoryException e) {
+               } catch (Exception e) {
                        JcrUtils.discardUnderlyingSessionQuietly(node);
                        e.printStackTrace();
                }
        }
 
-       public Node getNode() {
-               return node;
+       // public Node getNode() {
+       // return node;
+       // }
+
+       public List<RealizedFlow> getRealizedFlows() {
+               try {
+                       List<RealizedFlow> realizedFlows = new ArrayList<RealizedFlow>();
+                       Node rootRealizedFlowNode = node.getNode(SLC_FLOW);
+                       // we just manage one level for the time being
+                       NodeIterator nit = rootRealizedFlowNode.getNodes(SLC_FLOW);
+                       while (nit.hasNext()) {
+                               Node realizedFlowNode = nit.nextNode();
+                               RealizedFlow realizedFlow = new JcrRealizedFlow(
+                                               realizedFlowNode);
+                               if (realizedFlow != null)
+                                       realizedFlows.add(realizedFlow);
+                       }
+                       return realizedFlows;
+               } catch (RepositoryException e) {
+                       throw new SlcException("Cannot get realized flows", e);
+               }
+       }
+
+       public String getNodePath() {
+               try {
+                       return node.getPath();
+               } catch (RepositoryException e) {
+                       throw new SlcException("Cannot get process node path for " + node,
+                                       e);
+               }
        }
 
+       public Repository getRepository() {
+               try {
+                       return node.getSession().getRepository();
+               } catch (RepositoryException e) {
+                       throw new SlcException("Cannot get process JCR repository for "
+                                       + node, e);
+               }
+       }
 }