]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java
Clean session management.
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / editors / ProcessEditor.java
index 027e7c626516ce627a17045ed98b22419caa39b3..59473c667321e56f722d2a17a62d727d705279cf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2012 Mathieu Baudier
+ * 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.
 package org.argeo.slc.client.ui.editors;
 
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
@@ -32,8 +33,6 @@ import org.argeo.slc.client.ui.ClientUiPlugin;
 import org.argeo.slc.client.ui.controllers.ProcessController;
 import org.argeo.slc.execution.ExecutionModulesManager;
 import org.argeo.slc.execution.ExecutionProcess;
-import org.argeo.slc.execution.ExecutionProcessNotifier;
-import org.argeo.slc.execution.ExecutionStep;
 import org.argeo.slc.jcr.SlcJcrUtils;
 import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
@@ -46,8 +45,7 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.forms.editor.FormEditor;
 
 /** Editor for an execution process. */
-public class ProcessEditor extends FormEditor implements
-               ExecutionProcessNotifier, SlcTypes, SlcNames {
+public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames {
        public final static String ID = ClientUiPlugin.ID + ".processEditor";
 
        private Session session;
@@ -55,12 +53,9 @@ public class ProcessEditor extends FormEditor implements
        private ProcessController processController;
 
        private ProcessBuilderPage builderPage;
-       //private ProcessLogPage logPage;
 
        private ExecutionModulesManager modulesManager;
 
-       //private Boolean switchToLog = false;
-
        @Override
        public void init(IEditorSite site, IEditorInput input)
                        throws PartInitException {
@@ -86,7 +81,8 @@ public class ProcessEditor extends FormEditor implements
        protected Node newProcessNode(ProcessEditorInput pei)
                        throws RepositoryException {
                String uuid = UUID.randomUUID().toString();
-               String processPath = SlcJcrUtils.createExecutionProcessPath(uuid);
+               String processPath = SlcJcrUtils.createExecutionProcessPath(session,
+                               uuid);
                Node processNode = JcrUtils.mkdirs(session, processPath, SLC_PROCESS);
                processNode.setProperty(SLC_UUID, uuid);
                processNode.setProperty(SLC_STATUS, ExecutionProcess.NEW);
@@ -114,6 +110,7 @@ public class ProcessEditor extends FormEditor implements
        @Override
        public void dispose() {
                JcrUtils.logoutQuietly(session);
+               super.dispose();
        }
 
        /** Actually runs the process. */
@@ -124,17 +121,37 @@ public class ProcessEditor extends FormEditor implements
                } catch (RepositoryException e) {
                        throw new SlcException("Cannot update status of " + processNode, e);
                }
+
+               // save
                doSave(null);
+
                try {
-                       // show log
-//                     if (switchToLog)
-//                             setActivePage(logPage.getId());
+                       // make sure modules are started for all nodes
+                       for (NodeIterator nit = processNode.getNode(SLC_FLOW).getNodes(); nit
+                                       .hasNext();) {
+                               Node flowNode = nit.nextNode();
+                               try {
+                                       String flowDefPath = flowNode.getNode(SLC_ADDRESS)
+                                                       .getProperty(Property.JCR_PATH).getString();
+                                       Node executionModuleNode = flowNode.getSession().getNode(
+                                                       SlcJcrUtils.modulePath(flowDefPath));
+                                       if (!executionModuleNode.getProperty(SLC_STARTED)
+                                                       .getBoolean())
+                                               ClientUiPlugin.startStopExecutionModule(modulesManager,
+                                                               executionModuleNode);
+                               } catch (Exception e) {
+                                       ErrorFeedback.show(
+                                                       "Cannot start execution module related to "
+                                                                       + flowNode, e);
+                               }
+                       }
 
+                       // Actually process
                        ExecutionProcess process = processController.process(processNode);
                        Map<String, String> properties = new HashMap<String, String>();
                        properties.put(ExecutionModulesManager.SLC_PROCESS_ID,
                                        process.getUuid());
-                       modulesManager.registerProcessNotifier(this, properties);
+                       // modulesManager.registerProcessNotifier(this, properties);
                } catch (Exception e) {
                        ErrorFeedback.show("Execution of " + processNode + " failed", e);
                }
@@ -164,7 +181,8 @@ public class ProcessEditor extends FormEditor implements
                try {
                        Session session = processNode.getSession();
                        String uuid = UUID.randomUUID().toString();
-                       String destPath = SlcJcrUtils.createExecutionProcessPath(uuid);
+                       String destPath = SlcJcrUtils.createExecutionProcessPath(session,
+                                       uuid);
                        Node newNode = JcrUtils.mkdirs(session, destPath,
                                        SlcTypes.SLC_PROCESS);
 
@@ -196,8 +214,6 @@ public class ProcessEditor extends FormEditor implements
                        builderPage = new ProcessBuilderPage(this, processNode);
                        addPage(builderPage);
                        firePropertyChange(PROP_DIRTY);
-//                     logPage = new ProcessLogPage(this, processNode);
-//                     addPage(logPage);
                } catch (PartInitException e) {
                        throw new SlcException("Cannot add pages", e);
                }
@@ -216,11 +232,15 @@ public class ProcessEditor extends FormEditor implements
                        editorDirtyStateChanged();
                } catch (RepositoryException e) {
                        throw new SlcException("Cannot save " + processNode, e);
-               } finally {
-                       JcrUtils.discardQuietly(session);
+                       // } finally {
+                       // JcrUtils.discardQuietly(session);
                }
        }
 
+       public void setEditorTitle(String title) {
+               setPartName(title);
+       }
+
        @Override
        public void doSaveAs() {
        }
@@ -230,19 +250,29 @@ public class ProcessEditor extends FormEditor implements
                return false;
        }
 
-       public void updateStatus(ExecutionProcess process, String oldStatus,
-                       String newStatus) {
-       }
-
-       public void addSteps(ExecutionProcess process, List<ExecutionStep> steps) {
-               // logPage.addSteps(steps);
-       }
+       // public void updateStatus(ExecutionProcess process, String oldStatus,
+       // String newStatus) {
+       // }
+       //
+       // public void addSteps(ExecutionProcess process, List<ExecutionStep> steps)
+       // {
+       // }
 
        /** Expects one session per editor. */
+       @Deprecated
        public void setSession(Session session) {
                this.session = session;
        }
 
+       public void setRepository(Repository repository) {
+               try {
+                       session = repository.login();
+               } catch (RepositoryException re) {
+                       throw new SlcException("Unable to log in Repository " + repository,
+                                       re);
+               }
+       }
+
        public void setProcessController(ProcessController processController) {
                this.processController = processController;
        }
@@ -250,5 +280,4 @@ public class ProcessEditor extends FormEditor implements
        public void setModulesManager(ExecutionModulesManager modulesManager) {
                this.modulesManager = modulesManager;
        }
-
 }