Add password spec type
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 26 Oct 2012 16:15:40 +0000 (16:15 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 26 Oct 2012 16:15:40 +0000 (16:15 +0000)
Improve SLC Execution UI

git-svn-id: https://svn.argeo.org/slc/trunk@5659 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

12 files changed:
plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/ClientUiPlugin.java
plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java
plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java
plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrExecutionModulesView.java
plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrProcessListView.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/PrimitiveAccessor.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/PrimitiveUtils.java
runtime/org.argeo.slc.core/src/main/resources/org/argeo/slc/core/execution/xml/slc-flow-1.2.xsd
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrConstants.java
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrResultUtils.java
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java

index 9d794fb2652859ef21742f4516e7a13a4f9ac961..e7d1c616c5a1407e3ab177bbd6258989c01108bc 100644 (file)
  */
 package org.argeo.slc.client.ui;
 
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.argeo.slc.BasicNameVersion;
+import org.argeo.slc.NameVersion;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.deploy.ModulesManager;
+import org.argeo.slc.jcr.SlcNames;
+import org.argeo.slc.jcr.SlcTypes;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 
 /** The activator class controls the plug-in life cycle */
-public class ClientUiPlugin extends AbstractUIPlugin {
+public class ClientUiPlugin extends AbstractUIPlugin implements SlcNames {
        public static final String ID = "org.argeo.slc.client.ui";
        private static ClientUiPlugin plugin;
 
@@ -47,4 +60,54 @@ public class ClientUiPlugin extends AbstractUIPlugin {
        public static ImageDescriptor getImageDescriptor(String path) {
                return imageDescriptorFromPlugin(ID, path);
        }
+
+       /** Start execution module if it was stopped and vice-versa */
+       public static void startStopExecutionModule(
+                       final ModulesManager modulesManager, Node node) {
+               try {
+                       if (!node.isNodeType(SlcTypes.SLC_EXECUTION_MODULE))
+                               throw new SlcException(node + " is not an execution module");
+
+                       String name = node.getProperty(SLC_NAME).getString();
+                       String version = node.getProperty(SLC_VERSION).getString();
+                       final NameVersion nameVersion = new BasicNameVersion(name, version);
+                       Boolean started = node.getProperty(SLC_STARTED).getBoolean();
+
+                       Job job;
+                       if (started) {
+                               job = new Job("Stop " + nameVersion) {
+                                       protected IStatus run(IProgressMonitor monitor) {
+                                               monitor.beginTask("Stop " + nameVersion, 1);
+                                               modulesManager.stop(nameVersion);
+                                               monitor.worked(1);
+                                               return Status.OK_STATUS;
+                                       }
+
+                                       protected void canceling() {
+                                               getThread().interrupt();
+                                               super.canceling();
+                                       }
+                               };
+                       } else {
+                               job = new Job("Start " + nameVersion) {
+                                       protected IStatus run(IProgressMonitor monitor) {
+                                               monitor.beginTask("Start " + nameVersion, 1);
+                                               modulesManager.start(nameVersion);
+                                               monitor.worked(1);
+                                               return Status.OK_STATUS;
+                                       }
+
+                                       protected void canceling() {
+                                               getThread().interrupt();
+                                               super.canceling();
+                                       }
+                               };
+                       }
+                       job.setUser(true);
+                       job.schedule();
+               } catch (RepositoryException e) {
+                       throw new SlcException("Cannot start " + node, e);
+               }
+
+       }
 }
index 6e30a48e16d3683a8ea04555fad7e3545129038b..31b5d30b8eb0d961ace4c7348c5c7459c0f3ca1d 100644 (file)
@@ -33,11 +33,15 @@ import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 
 import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.ErrorFeedback;
 import org.argeo.eclipse.ui.jcr.AsyncUiEventListener;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.SlcException;
+import org.argeo.slc.client.ui.ClientUiPlugin;
 import org.argeo.slc.client.ui.SlcImages;
+import org.argeo.slc.core.execution.PrimitiveAccessor;
 import org.argeo.slc.core.execution.PrimitiveUtils;
+import org.argeo.slc.execution.ExecutionModulesManager;
 import org.argeo.slc.execution.ExecutionProcess;
 import org.argeo.slc.jcr.SlcJcrUtils;
 import org.argeo.slc.jcr.SlcNames;
@@ -86,13 +90,12 @@ import org.eclipse.ui.forms.widgets.ScrolledForm;
 /** Definition of the process. */
 public class ProcessBuilderPage extends FormPage implements SlcNames {
        public final static String ID = "processBuilderPage";
-       // private final static Log log =
-       // LogFactory.getLog(ProcessBuilderPage.class);
 
        /** To be displayed in empty lists */
        final static String NONE = "<none>";
 
        private Node processNode;
+       private final ExecutionModulesManager modulesManager;
 
        private TreeViewer flowsViewer;
        private TableViewer valuesViewer;
@@ -104,9 +107,11 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
        private AbstractFormPart formPart;
        private EventListener statusObserver;
 
-       public ProcessBuilderPage(ProcessEditor editor, Node processNode) {
+       public ProcessBuilderPage(ProcessEditor editor, Node processNode,
+                       ExecutionModulesManager modulesManager) {
                super(editor, ID, "Definition");
                this.processNode = processNode;
+               this.modulesManager = modulesManager;
        }
 
        @Override
@@ -461,39 +466,14 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
        /*
         * UTILITIES
         */
-       // protected static Object getAttributeSpecValue(Node specAttrNode) {
-       // try {
-       // if (specAttrNode.isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
-       // if (!specAttrNode.hasProperty(SLC_VALUE))
-       // return null;
-       // String type = specAttrNode.getProperty(SLC_TYPE).getString();
-       // // TODO optimize based on data type?
-       // Object value = PrimitiveUtils.convert(type, specAttrNode
-       // .getProperty(SLC_VALUE).getString());
-       // // log.debug(specAttrNode + ", type=" + type + ", value=" +
-       // // value);
-       // return value;
-       // } else if (specAttrNode.isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
-       // if (specAttrNode.hasNode(SLC_VALUE)) {
-       // // return the index of the sub node
-       // // in the future we may manage reference as well
-       // return specAttrNode.getProperty(SLC_VALUE).getLong();
-       // } else
-       // return null;
-       // }
-       // return null;
-       // } catch (RepositoryException e) {
-       // throw new SlcException("Cannot get value", e);
-       // }
-       //
-       // }
-
        protected static String getAttributeSpecText(Node specAttrNode) {
                try {
                        if (specAttrNode.isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
                                if (!specAttrNode.hasProperty(SLC_VALUE))
                                        return "";
                                String type = specAttrNode.getProperty(SLC_TYPE).getString();
+                               if (PrimitiveAccessor.TYPE_PASSWORD.equals(type))
+                                       return "****************";
                                Object value = PrimitiveUtils.convert(type, specAttrNode
                                                .getProperty(SLC_VALUE).getString());
                                return value.toString();
@@ -525,7 +505,7 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
        /*
         * FLOWS SUBCLASSES
         */
-       static class FlowsContentProvider implements ITreeContentProvider {
+       class FlowsContentProvider implements ITreeContentProvider {
                public Object[] getElements(Object obj) {
                        if (!(obj instanceof Node))
                                return new Object[0];
@@ -534,11 +514,29 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
                                Node node = (Node) obj;
                                List<Node> children = new ArrayList<Node>();
                                for (NodeIterator nit = node.getNode(SLC_FLOW).getNodes(); nit
-                                               .hasNext();)
-                                       children.add(nit.nextNode());
+                                               .hasNext();) {
+                                       Node flowNode = nit.nextNode();
+                                       children.add(flowNode);
+                                       try {
+                                               // make sure modules are started for all nodes
+                                               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);
+                                       }
+
+                               }
                                return children.toArray();
                        } catch (RepositoryException e) {
-                               throw new SlcException("Cannot list children of " + obj, e);
+                               throw new SlcException("Cannot list flows of " + obj, e);
                        }
                }
 
@@ -718,7 +716,14 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
                                Node specAttrNode = (Node) element;
                                if (specAttrNode
                                                .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
-                                       return new TextCellEditor(tableViewer.getTable());
+                                       String type = specAttrNode.getProperty(SLC_TYPE)
+                                                       .getString();
+                                       if (PrimitiveAccessor.TYPE_PASSWORD.equals(type)) {
+                                               return new TextCellEditor(tableViewer.getTable(),
+                                                               SWT.PASSWORD);
+                                       } else {
+                                               return new TextCellEditor(tableViewer.getTable());
+                                       }
                                } else if (specAttrNode
                                                .isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
                                        NodeIterator children = specAttrNode.getNodes();
@@ -767,9 +772,6 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
                protected Object getValue(Object element) {
                        Node specAttrNode = (Node) element;
                        try {
-                               // Object value = getAttributeSpecValue(specAttrNode);
-                               // if (value == null)
-                               // throw new SlcException("Unsupported attribute " + element);
                                if (specAttrNode
                                                .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
                                        if (!specAttrNode.hasProperty(SLC_VALUE))
index 027e7c626516ce627a17045ed98b22419caa39b3..71ca6b88d43416442a618a815652841018ebf8d9 100644 (file)
@@ -55,12 +55,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 +83,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);
@@ -126,10 +124,6 @@ public class ProcessEditor extends FormEditor implements
                }
                doSave(null);
                try {
-                       // show log
-//                     if (switchToLog)
-//                             setActivePage(logPage.getId());
-
                        ExecutionProcess process = processController.process(processNode);
                        Map<String, String> properties = new HashMap<String, String>();
                        properties.put(ExecutionModulesManager.SLC_PROCESS_ID,
@@ -164,7 +158,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);
 
@@ -193,11 +188,10 @@ public class ProcessEditor extends FormEditor implements
        @Override
        protected void addPages() {
                try {
-                       builderPage = new ProcessBuilderPage(this, processNode);
+                       builderPage = new ProcessBuilderPage(this, processNode,
+                                       modulesManager);
                        addPage(builderPage);
                        firePropertyChange(PROP_DIRTY);
-//                     logPage = new ProcessLogPage(this, processNode);
-//                     addPage(logPage);
                } catch (PartInitException e) {
                        throw new SlcException("Cannot add pages", e);
                }
@@ -235,7 +229,6 @@ public class ProcessEditor extends FormEditor implements
        }
 
        public void addSteps(ExecutionProcess process, List<ExecutionStep> steps) {
-               // logPage.addSteps(steps);
        }
 
        /** Expects one session per editor. */
index f8cfab4c905fc3ed2b8edc08f8561ef156773c47..45d74f6eaf556057fec8529dae1e70632dc7a7e5 100644 (file)
@@ -41,9 +41,8 @@ import org.argeo.eclipse.ui.jcr.DefaultNodeLabelProvider;
 import org.argeo.eclipse.ui.jcr.NodeElementComparer;
 import org.argeo.eclipse.ui.jcr.SimpleNodeContentProvider;
 import org.argeo.eclipse.ui.specific.EclipseUiSpecificUtils;
-import org.argeo.slc.BasicNameVersion;
-import org.argeo.slc.NameVersion;
 import org.argeo.slc.SlcException;
+import org.argeo.slc.client.ui.ClientUiPlugin;
 import org.argeo.slc.client.ui.SlcImages;
 import org.argeo.slc.client.ui.editors.ProcessEditor;
 import org.argeo.slc.client.ui.editors.ProcessEditorInput;
@@ -51,10 +50,6 @@ import org.argeo.slc.execution.ExecutionModulesManager;
 import org.argeo.slc.jcr.SlcJcrConstants;
 import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
@@ -140,20 +135,6 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes,
                                        new String[] { SlcJcrConstants.VM_AGENT_FACTORY_PATH });
                }
 
-               // @Override
-               // protected Object[] getChildren(Node node) throws RepositoryException
-               // {
-               // if (node.isNodeType(SlcTypes.SLC_AGENT_FACTORY)) {
-               // List<AgentNodesWrapper> wrappers = new
-               // ArrayList<AgentNodesWrapper>();
-               // for (NodeIterator nit = node.getNodes(); nit.hasNext();) {
-               // wrappers.add(new AgentNodesWrapper(nit.nextNode()));
-               // }
-               // return wrappers.toArray();
-               // }
-               // return super.getChildren(node);
-               // }
-
                @Override
                protected Object[] sort(Object parent, Object[] children) {
                        Object[] sorted = new Object[children.length];
@@ -229,28 +210,6 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes,
 
        }
 
-       // /** Wraps the execution modules of an agent. */
-       // static class AgentNodesWrapper extends NodesWrapper {
-       //
-       // public AgentNodesWrapper(Node node) {
-       // super(node);
-       // }
-       //
-       // protected List<WrappedNode> getWrappedNodes()
-       // throws RepositoryException {
-       // List<WrappedNode> children = new ArrayList<WrappedNode>();
-       // Node executionModules = getNode();
-       // for (NodeIterator nit = executionModules.getNodes(); nit.hasNext();) {
-       // for (NodeIterator nitVersions = nit.nextNode().getNodes(); nitVersions
-       // .hasNext();) {
-       // children.add(new WrappedNode(this, nitVersions.nextNode()));
-       // }
-       // }
-       // return children;
-       // }
-       //
-       // }
-
        class VmAgentObserver extends AsyncUiEventListener {
 
                public VmAgentObserver(Display display) {
@@ -274,13 +233,6 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes,
                                }
                        }
 
-                       // try {
-                       // Node vmAgentNode = session
-                       // .getNode(SlcJcrConstants.VM_AGENT_FACTORY_PATH);
-                       // viewer.refresh(vmAgentNode);
-                       // } catch (RepositoryException e) {
-                       // log.warn("Cannot process event : " + e);
-                       // }
                        // TODO: optimize based on event
                        viewer.refresh();
                }
@@ -354,46 +306,8 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes,
                                if (obj instanceof Node) {
                                        Node node = (Node) obj;
                                        if (node.isNodeType(SLC_EXECUTION_MODULE)) {
-                                               String name = node.getProperty(SLC_NAME).getString();
-                                               String version = node.getProperty(SLC_VERSION)
-                                                               .getString();
-                                               final NameVersion nameVersion = new BasicNameVersion(
-                                                               name, version);
-                                               Boolean started = node.getProperty(SLC_STARTED)
-                                                               .getBoolean();
-
-                                               Job job;
-                                               if (started) {
-                                                       job = new Job("Stop " + nameVersion) {
-                                                               protected IStatus run(IProgressMonitor monitor) {
-                                                                       monitor.beginTask("Stop " + nameVersion, 1);
-                                                                       modulesManager.stop(nameVersion);
-                                                                       monitor.worked(1);
-                                                                       return Status.OK_STATUS;
-                                                               }
-
-                                                               protected void canceling() {
-                                                                       getThread().interrupt();
-                                                                       super.canceling();
-                                                               }
-                                                       };
-                                               } else {
-                                                       job = new Job("Start " + nameVersion) {
-                                                               protected IStatus run(IProgressMonitor monitor) {
-                                                                       monitor.beginTask("Start " + nameVersion, 1);
-                                                                       modulesManager.start(nameVersion);
-                                                                       monitor.worked(1);
-                                                                       return Status.OK_STATUS;
-                                                               }
-
-                                                               protected void canceling() {
-                                                                       getThread().interrupt();
-                                                                       super.canceling();
-                                                               }
-                                                       };
-                                               }
-                                               job.setUser(true);
-                                               job.schedule();
+                                               ClientUiPlugin.startStopExecutionModule(modulesManager,
+                                                               node);
                                        } else {
                                                String path = node.getPath();
                                                // TODO factorize with editor
@@ -413,8 +327,6 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes,
                                                        paths.add(nit.nextNode().getPath());
                                                }
 
-                                               // List<String> paths = new ArrayList<String>();
-                                               // paths.add(node.getPath());
                                                IWorkbenchPage activePage = PlatformUI.getWorkbench()
                                                                .getActiveWorkbenchWindow().getActivePage();
                                                activePage.openEditor(new ProcessEditorInput(
index ac8b5e8adfc587b4da264f8a2b36a057b63c6cf2..b022dc85b312dec9da6871376eb3697260d56ec2 100644 (file)
@@ -37,7 +37,7 @@ import org.argeo.slc.client.ui.SlcImages;
 import org.argeo.slc.client.ui.editors.ProcessEditor;
 import org.argeo.slc.client.ui.editors.ProcessEditorInput;
 import org.argeo.slc.execution.ExecutionProcess;
-import org.argeo.slc.jcr.SlcJcrConstants;
+import org.argeo.slc.jcr.SlcJcrUtils;
 import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
@@ -92,8 +92,8 @@ public class JcrProcessListView extends ViewPart {
                        observationManager.addEventListener(processesObserver,
                                        Event.NODE_ADDED | Event.NODE_REMOVED
                                                        | Event.PROPERTY_CHANGED,
-                                       SlcJcrConstants.PROCESSES_BASE_PATH, true, null, null,
-                                       false);
+                                       SlcJcrUtils.getSlcProcessesBasePath(session), true, null,
+                                       null, false);
                } catch (RepositoryException e) {
                        throw new SlcException("Cannot register listeners", e);
                }
index 149b9a916dc73415e7b466de08e6dd469369bcc6..58704d580e3b2562c7df7f52b6315f775e8f4433 100644 (file)
@@ -18,6 +18,11 @@ package org.argeo.slc.core.execution;
 /** Abstraction of access to primitive values */
 public interface PrimitiveAccessor {
        public final static String TYPE_STRING = "string";
+       /**
+        * As of Argeo 1, passwords are NOT stored encrypted, just hidden in the UI,
+        * but stored in plain text in JCR. Use keyring instead.
+        */
+       public final static String TYPE_PASSWORD = "password";
        public final static String TYPE_INTEGER = "integer";
        public final static String TYPE_LONG = "long";
        public final static String TYPE_FLOAT = "float";
index 00a27dd1a9668dc59b4cf33cb37f3ce38a30ffd2..757e41ad5252115d733ed137f24c13c568790060 100644 (file)
@@ -50,6 +50,8 @@ public class PrimitiveUtils {
        public static Class<?> typeAsClass(String type) {
                if (PrimitiveAccessor.TYPE_STRING.equals(type))
                        return String.class;
+               else if (PrimitiveAccessor.TYPE_PASSWORD.equals(type))
+                       return char[].class;
                else if (PrimitiveAccessor.TYPE_INTEGER.equals(type))
                        return Integer.class;
                else if (PrimitiveAccessor.TYPE_LONG.equals(type))
@@ -68,6 +70,8 @@ public class PrimitiveUtils {
        public static String classAsType(Class<?> clss) {
                if (String.class.isAssignableFrom(clss))
                        return PrimitiveAccessor.TYPE_STRING;
+               else if (char[].class.isAssignableFrom(clss))
+                       return PrimitiveAccessor.TYPE_PASSWORD;
                else if (Integer.class.isAssignableFrom(clss))
                        return PrimitiveAccessor.TYPE_INTEGER;
                else if (Long.class.isAssignableFrom(clss))
@@ -82,9 +86,12 @@ public class PrimitiveUtils {
                        return null;
        }
 
+       /** Parse string as an object. Passwords are returned as String.*/
        public static Object convert(String type, String str) {
                if (PrimitiveAccessor.TYPE_STRING.equals(type)) {
                        return str;
+               } else if (PrimitiveAccessor.TYPE_PASSWORD.equals(type)) {
+                       return str;
                } else if (PrimitiveAccessor.TYPE_INTEGER.equals(type)) {
                        return (Integer.parseInt(str));
                } else if (PrimitiveAccessor.TYPE_LONG.equals(type)) {
index 308c38f21f70c19d6bc45248418f413e5e643f69..a70798f2d6956516e96514833e816c8b89f70024 100644 (file)
                                        <xsd:simpleType>
                                                <xsd:restriction base="xsd:string">
                                                        <xsd:enumeration value="string" />
+                                                       <xsd:enumeration value="password" />
                                                        <xsd:enumeration value="integer" />
                                                        <xsd:enumeration value="long" />
                                                        <xsd:enumeration value="float" />
index 4cf955c1d87f23bd5c4e97efa84bbac0d4a76c20..1beec7a2af957e3dfffeaf2c3a7d0d576e88991b 100644 (file)
@@ -18,17 +18,9 @@ package org.argeo.slc.jcr;
 /** JCR related constants used across SLC */
 public interface SlcJcrConstants {
        public final static String PROPERTY_PATH = "argeo.slc.jcr.path";
-       public final static String SLC_BASE_PATH = "/slc:system";
-       public final static String PROCESSES_BASE_PATH = SLC_BASE_PATH
-                       + "/slc:processes";
+       
+       public final static String SLC_BASE_PATH = "/" + SlcNames.SLC_SYSTEM;
        public final static String AGENTS_BASE_PATH = SLC_BASE_PATH + "/slc:agents";
-       // public final static String RESULTS_BASE_PATH = SLC_BASE_PATH
-       // + "/slc:results";
        public final static String VM_AGENT_FACTORY_PATH = AGENTS_BASE_PATH
                        + "/slc:vm";
-       
-       /*
-        * SLC SPECIFIC JCR PATHS
-        */
-       public final static String SLC_MYRESULT_BASEPATH = "slc:myResults";
 }
index edc2d001180cf4db5cb9ba5061580b5d30bd7615..ba54c1378c26e601457a34dafa13a54d7e5f077d 100644 (file)
@@ -20,7 +20,6 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.nodetype.NodeType;
 
-import org.argeo.ArgeoException;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.jcr.UserJcrUtils;
 import org.argeo.slc.SlcException;
@@ -36,11 +35,14 @@ public class SlcJcrResultUtils {
         */
        public static String getSlcResultsBasePath(Session session) {
                try {
-
-                       return UserJcrUtils.getUserHome(session).getPath() + "/"
+                       Node userHome = UserJcrUtils.getUserHome(session);
+                       if (userHome == null)
+                               throw new SlcException("No user home available for "
+                                               + session.getUserID());
+                       return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
                                        + SlcNames.SLC_RESULTS;
                } catch (RepositoryException re) {
-                       throw new ArgeoException(
+                       throw new SlcException(
                                        "Unexpected error while getting Slc Results Base Path.", re);
                }
        }
@@ -51,10 +53,14 @@ public class SlcJcrResultUtils {
         */
        public static String getMyResultsBasePath(Session session) {
                try {
-                       return UserJcrUtils.getUserHome(session).getPath() + "/"
-                                       + SlcJcrConstants.SLC_MYRESULT_BASEPATH;
+                       Node userHome = UserJcrUtils.getUserHome(session);
+                       if (userHome == null)
+                               throw new SlcException("No user home available for "
+                                               + session.getUserID());
+                       return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
+                                       + SlcNames.SLC_MY_RESULTS;
                } catch (RepositoryException re) {
-                       throw new ArgeoException(
+                       throw new SlcException(
                                        "Unexpected error while getting Slc Results Base Path.", re);
                }
        }
@@ -85,7 +91,7 @@ public class SlcJcrResultUtils {
                                return myResParNode;
                        }
                } catch (RepositoryException re) {
-                       throw new ArgeoException(
+                       throw new SlcException(
                                        "Unexpected error while creating user MyResult base node.",
                                        re);
                }
@@ -121,7 +127,7 @@ public class SlcJcrResultUtils {
                        session.save();
                        return rfNode;
                } catch (RepositoryException re) {
-                       throw new ArgeoException(
+                       throw new SlcException(
                                        "Unexpected error while creating Result Folder node.", re);
                }
        }
index af7385000ffdb76e715ad0b4c28a84d6319b4764..e0e52c0d517d4c071d50188f8ad6118ae1c99fe3 100644 (file)
@@ -76,12 +76,27 @@ public class SlcJcrUtils implements SlcNames {
        }
 
        /** Create a new execution process path based on the current time */
-       public static String createExecutionProcessPath(String uuid) {
+       public static String createExecutionProcessPath(Session session, String uuid) {
                Calendar now = new GregorianCalendar();
-               return SlcJcrConstants.PROCESSES_BASE_PATH + '/'
+               return getSlcProcessesBasePath(session) + '/'
                                + JcrUtils.dateAsPath(now, true) + uuid;
        }
 
+       /** GEt the base for the user processeses. */
+       public static String getSlcProcessesBasePath(Session session) {
+               try {
+                       Node userHome = UserJcrUtils.getUserHome(session);
+                       if (userHome == null)
+                               throw new SlcException("No user home available for "
+                                               + session.getUserID());
+                       return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/'
+                                       + SlcNames.SLC_PROCESSES;
+               } catch (RepositoryException re) {
+                       throw new SlcException(
+                                       "Unexpected error while getting Slc Results Base Path.", re);
+               }
+       }
+
        /**
         * Create a new execution result path in the user home based on the current
         * time
@@ -89,11 +104,7 @@ public class SlcJcrUtils implements SlcNames {
        public static String createResultPath(Session session, String uuid)
                        throws RepositoryException {
                Calendar now = new GregorianCalendar();
-               Node userHome = UserJcrUtils.getUserHome(session);
-               if (userHome == null)
-                       throw new SlcException("No user home available for "
-                                       + session.getUserID());
-               return userHome.getPath() + '/' + SlcNames.SLC_RESULTS + '/'
+               return SlcJcrResultUtils.getSlcResultsBasePath(session) + '/'
                                + JcrUtils.dateAsPath(now, true) + uuid;
        }
 
@@ -116,10 +127,14 @@ public class SlcJcrUtils implements SlcNames {
                if (value instanceof CharSequence)
                        value = PrimitiveUtils.convert(type,
                                        ((CharSequence) value).toString());
+               if (value instanceof char[])
+                       value = new String((char[]) value);
 
                try {
                        if (type.equals(PrimitiveAccessor.TYPE_STRING))
                                node.setProperty(propertyName, value.toString());
+                       else if (type.equals(PrimitiveAccessor.TYPE_PASSWORD))
+                               node.setProperty(propertyName, value.toString());
                        else if (type.equals(PrimitiveAccessor.TYPE_INTEGER))
                                node.setProperty(propertyName, (long) ((Integer) value));
                        else if (type.equals(PrimitiveAccessor.TYPE_LONG))
index 70319037f20ddf220f780a539b5d83125a98e274..6a310373854f7a068fde235483b48e9968228cee 100644 (file)
@@ -15,7 +15,6 @@
  */
 package org.argeo.slc.jcr;
 
-
 /** JCR names used by SLC */
 public interface SlcNames {
        public final static String SLC_ = "slc:";
@@ -42,8 +41,13 @@ public interface SlcNames {
        public final static String SLC_IS_CONSTANT = "slc:isConstant";
        public final static String SLC_IS_HIDDEN = "slc:isHidden";
 
-       // result
+       // base directories
+       public final static String SLC_SYSTEM = "slc:system";
        public final static String SLC_RESULTS = "slc:results";
+       public final static String SLC_MY_RESULTS = "slc:myResults";
+       public final static String SLC_PROCESSES = "slc:processes";
+
+       // result
        public final static String SLC_SUCCESS = "slc:success";
        public final static String SLC_MESSAGE = "slc:message";
        public final static String SLC_TAG = "slc:tag";
@@ -54,7 +58,7 @@ public interface SlcNames {
        // diff result
        public final static String SLC_SUMMARY = "slc:summary";
        public final static String SLC_ISSUES = "slc:issues";
-       
+
        /*
         * REPO
         */