Execution attribute of type ref now supported (break data model)
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 22 Jan 2012 13:39:07 +0000 (13:39 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 22 Jan 2012 13:39:07 +0000 (13:39 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5002 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.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/PrimitiveSpecAttribute.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/RefSpecAttribute.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/execution/JcrProcessThread.java
runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd

index 28c2f69c611a6bd485256a70f055f1759a5cc287..0d4ae532acd476e1606c1bfc3331b7397086c225 100644 (file)
@@ -30,6 +30,7 @@ import org.argeo.slc.jcr.SlcTypes;
 import org.eclipse.jface.viewers.CellEditor;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
 import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
 import org.eclipse.jface.viewers.EditingSupport;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -73,6 +74,9 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
        // private final static Log log =
        // LogFactory.getLog(ProcessBuilderPage.class);
 
+       /** To be displayed in empty lists */
+       final static String NONE = "<none>";
+
        private Node processNode;
 
        private TreeViewer flowsViewer;
@@ -258,8 +262,7 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
                        } else if (i == 1) {
                                column.setLabelProvider(new ColumnLabelProvider() {
                                        public String getText(Object element) {
-                                               Object obj = getAttributeSpecValue((Node) element);
-                                               return obj != null ? obj.toString() : "";
+                                               return getAttributeSpecText((Node) element);
                                        }
                                });
                                column.setEditingSupport(new ValuesEditingSupport(viewer));
@@ -442,24 +445,65 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
        /*
         * UTILITIES
         */
-       protected static Object getAttributeSpecValue(Node specAttrNode) {
+       // 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 null;
+                                       return "";
                                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;
+                               return value.toString();
+                       } else if (specAttrNode.isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
+                               if (specAttrNode.hasProperty(SLC_VALUE)) {
+                                       int value = (int) specAttrNode.getProperty(SLC_VALUE)
+                                                       .getLong();
+                                       NodeIterator children = specAttrNode.getNodes();
+                                       int index = 0;
+                                       while (children.hasNext()) {
+                                               Node child = children.nextNode();
+                                               if (index == value)
+                                                       return child.getProperty(Property.JCR_TITLE)
+                                                                       .getString();
+                                               index++;
+                                       }
+                                       throw new SlcException("No child node with index " + value
+                                                       + " for spec attribute " + specAttrNode);
+                               } else
+                                       return "";
                        }
-                       return null;
+                       throw new SlcException("Unsupported type for spec attribute "
+                                       + specAttrNode);
                } catch (RepositoryException e) {
                        throw new SlcException("Cannot get value", e);
                }
-
        }
 
        /*
@@ -653,8 +697,21 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
                        try {
                                Node specAttrNode = (Node) element;
                                if (specAttrNode
-                                               .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE))
+                                               .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
                                        return new TextCellEditor(tableViewer.getTable());
+                               } else if (specAttrNode
+                                               .isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
+                                       NodeIterator children = specAttrNode.getNodes();
+                                       ArrayList<String> items = new ArrayList<String>();
+                                       while (children.hasNext()) {
+                                               Node child = children.nextNode();
+                                               if (child.isNodeType(NodeType.MIX_TITLE))
+                                                       items.add(child.getProperty(Property.JCR_TITLE)
+                                                                       .getString());
+                                       }
+                                       return new ComboBoxCellEditor(tableViewer.getTable(),
+                                                       items.toArray(new String[items.size()]));
+                               }
                                return null;
                        } catch (RepositoryException e) {
                                throw new SlcException("Cannot get celle editor", e);
@@ -668,24 +725,51 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
                                return !(specAttrNode.getProperty(SLC_IS_IMMUTABLE)
                                                .getBoolean() || specAttrNode.getProperty(
                                                SLC_IS_CONSTANT).getBoolean())
-                                               && specAttrNode
-                                                               .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE);
+                                               && isSupportedAttributeType(specAttrNode);
                        } catch (RepositoryException e) {
-                               throw new SlcException("Cannot check canEdit", e);
+                               throw new SlcException("Cannot check whether " + element
+                                               + " is editable", e);
                        }
                }
 
+               /**
+                * Supports {@link SlcTypes#SLC_PRIMITIVE_SPEC_ATTRIBUTE} and
+                * {@link SlcTypes#SLC_REF_SPEC_ATTRIBUTE}
+                */
+               protected boolean isSupportedAttributeType(Node specAttrNode)
+                               throws RepositoryException {
+                       return specAttrNode
+                                       .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)
+                                       || specAttrNode.isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE);
+               }
+
                @Override
                protected Object getValue(Object element) {
                        Node specAttrNode = (Node) element;
                        try {
-                               Object value = getAttributeSpecValue(specAttrNode);
-                               if (value == null)
-                                       throw new SlcException("Unsupported attribute " + element);
+                               // Object value = getAttributeSpecValue(specAttrNode);
+                               // if (value == null)
+                               // throw new SlcException("Unsupported attribute " + element);
                                if (specAttrNode
-                                               .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE))
+                                               .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) {
+                                       if (!specAttrNode.hasProperty(SLC_VALUE))
+                                               return NONE;
+                                       String type = specAttrNode.getProperty(SLC_TYPE)
+                                                       .getString();
+                                       // TODO optimize based on data type?
+                                       Object value = PrimitiveUtils.convert(type, specAttrNode
+                                                       .getProperty(SLC_VALUE).getString());
                                        return value.toString();
-                               return value;
+                               } else if (specAttrNode
+                                               .isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
+                                       if (!specAttrNode.hasProperty(SLC_VALUE))
+                                               return 0;
+                                       // return the index of the sub node as set by setValue()
+                                       // in the future we may manage references as well
+                                       return (int) specAttrNode.getProperty(SLC_VALUE).getLong();
+                               }
+                               throw new SlcException("Unsupported type for spec attribute "
+                                               + specAttrNode);
                        } catch (RepositoryException e) {
                                throw new SlcException("Cannot get value for " + element, e);
                        }
@@ -703,6 +787,12 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
                                                        type, value);
                                        valuesViewer.refresh();
                                        formPart.markDirty();
+                               } else if (specAttrNode
+                                               .isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
+                                       specAttrNode.setProperty(SLC_VALUE,
+                                                       ((Integer) value).longValue());
+                                       valuesViewer.refresh();
+                                       formPart.markDirty();
                                }
                        } catch (RepositoryException e) {
                                throw new SlcException("Cannot get celle editor", e);
index 9b3764b8af08550affccd9b777277136d0957a31..7d06274b1c90dffc36383a21052c6550411aa989 100644 (file)
@@ -136,6 +136,7 @@ public class DefaultExecutionFlowDescriptorConverter implements
                                                                refValue.getType());
                                        }
                                } else {
+                                       // default is to take the value as is
                                        convertedValues.put(key, value);
                                }
                        }
index f9bf37e6169d41706fbb29ba9eede6fc3ca743a0..9e1ef2e40d39ae6cb424efacc1b53c0cd2fe3fdb 100644 (file)
@@ -56,4 +56,11 @@ public class PrimitiveSpecAttribute extends AbstractSpecAttribute implements
                this.type = type;
 
        }
+
+       @Override
+       public String toString() {
+               return "Primitive spec attribute [" + type + "]"
+                               + (value != null ? "=" + value : "");
+       }
+
 }
index 495f323223b390fc4e260b3a7a955ce856e19e04..c6c5b035d08f601c77647f15d673d6fa5e13acb8 100644 (file)
@@ -68,7 +68,8 @@ public class RefSpecAttribute extends AbstractSpecAttribute implements
 
        @Override
        public String toString() {
-               return "Ref spec attribute [" + targetClass + "]";
+               return "Ref spec attribute [" + targetClass + "]"
+                               + (value != null ? "=" + value : "");
        }
 
 }
index 793670e7c1b1b235db6c5fc703cd09072250fa8b..51ea14e98d0d0a24b790da8e70a7d1168fb6d665 100644 (file)
@@ -174,7 +174,7 @@ public class SlcJcrUtils implements SlcNames {
                                        + node, e);
                }
        }
-
+       
        /** Prevents instantiation */
        private SlcJcrUtils() {
 
index ce9aa1da391f9cd425f9540be0d43714dc57ce88..4f7af507a6ae3ae8163cf096782d5a68c67e6857 100644 (file)
@@ -14,6 +14,7 @@ import org.argeo.slc.core.execution.DefaultExecutionSpec;
 import org.argeo.slc.core.execution.PrimitiveSpecAttribute;
 import org.argeo.slc.core.execution.PrimitiveUtils;
 import org.argeo.slc.core.execution.ProcessThread;
+import org.argeo.slc.core.execution.RefSpecAttribute;
 import org.argeo.slc.execution.ExecutionFlowDescriptor;
 import org.argeo.slc.execution.ExecutionModulesManager;
 import org.argeo.slc.execution.ExecutionProcess;
@@ -94,38 +95,26 @@ public class JcrProcessThread extends ProcessThread implements SlcNames {
                        realizedFlow.setModuleVersion(executionModuleVersion);
 
                        // retrieve execution spec
-                       DefaultExecutionSpec executionSpec = null;
+                       DefaultExecutionSpec executionSpec = new DefaultExecutionSpec();
+                       Map<String, ExecutionSpecAttribute> attrs = readExecutionSpecAttributes(realizedFlowNode);
+                       executionSpec.setAttributes(attrs);
+
+                       // set execution spec name
                        if (flowNode.hasProperty(SlcNames.SLC_SPEC)) {
                                Node executionSpecNode = flowNode.getProperty(SLC_SPEC)
                                                .getNode();
-                               executionSpec = new DefaultExecutionSpec();
                                executionSpec.setBeanName(executionSpecNode.getProperty(
                                                SLC_NAME).getString());
-                               executionSpec
-                                               .setAttributes(readExecutionSpecAttributes(executionSpecNode));
                        }
-                       // TODO: will with original attr
-                       Map<String, ExecutionSpecAttribute> attrs = readExecutionSpecAttributes(realizedFlowNode);
+
+                       // explicitly retrieve values
                        Map<String, Object> values = new HashMap<String, Object>();
                        for (String attrName : attrs.keySet()) {
-//                             if (flowNode.hasNode(attrName)) {
-//                                     // we assume this is a primitive
-//                                     // since ref are not yet implemented
-//                                     Node valueNode = flowNode.getNode(attrName);
-//                                     String type = valueNode.getProperty(SLC_TYPE).getString();
-//                                     String valueStr = valueNode.getProperty(SLC_VALUE)
-//                                                     .getString();
-//                                     Object value = PrimitiveUtils.convert(type, valueStr);
-//                                     values.put(attrName, value);
-//                             } else {
-                                       ExecutionSpecAttribute attr = attrs.get(attrName);
-                                       Object value = attr.getValue();
-                                       values.put(attrName, value);
-//                             }
+                               ExecutionSpecAttribute attr = attrs.get(attrName);
+                               Object value = attr.getValue();
+                               values.put(attrName, value);
                        }
 
-                       // if(executionSpec!=null)
-                       // executionSpec.setAttributes(attrs);
                        ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(flowName,
                                        values, executionSpec);
                        realizedFlow.setFlowDescriptor(efd);
@@ -157,8 +146,28 @@ public class JcrProcessThread extends ProcessThread implements SlcNames {
                                        PrimitiveSpecAttribute specAttr = new PrimitiveSpecAttribute(
                                                        type, value);
                                        attrs.put(specAttrNode.getName(), specAttr);
+                               } else if (specAttrNode
+                                               .isNodeType(SlcTypes.SLC_REF_SPEC_ATTRIBUTE)) {
+                                       if (!specAttrNode.hasProperty(SLC_VALUE)) {
+                                               continue;
+                                       }
+                                       Integer value = (int) specAttrNode.getProperty(SLC_VALUE)
+                                                       .getLong();
+                                       RefSpecAttribute specAttr = new RefSpecAttribute();
+                                       NodeIterator children = specAttrNode.getNodes();
+                                       int index = 0;
+                                       String id = null;
+                                       while (children.hasNext()) {
+                                               Node child = children.nextNode();
+                                               if (index == value)
+                                                       id = child.getName();
+                                               index++;
+                                       }
+                                       specAttr.setValue(id);
+                                       attrs.put(specAttrNode.getName(), specAttr);
                                }
-
+                               // throw new SlcException("Unsupported spec attribute "
+                               // + specAttrNode);
                        }
                        return attrs;
                } catch (RepositoryException e) {
index 3117a3f1a5a349510d1c036c316a9495bb0c86ef..4e8a4e68889d5d4e1484658b65fa9aa147e1c218 100644 (file)
@@ -38,10 +38,11 @@ mixin
 - slc:value (UNDEFINED)
 
 [slc:refSpecAttribute] > slc:executionSpecAttribute
+orderable
 mixin
 // typically a class name
 - slc:type (STRING)
-+ slc:value
+- slc:value (UNDEFINED)
 + * (mix:title)
 
 [slc:executionFlow] > nt:unstructured, mix:title
@@ -53,6 +54,7 @@ mixin
 
 // PROCESS
 [slc:process] > nt:unstructured, mix:created, mix:lastModified
+orderable
 - slc:uuid (STRING) ! m
 - slc:status (STRING) m
 + slc:flow (slc:realizedFlow)
@@ -78,6 +80,7 @@ abstract
 [slc:logError] > slc:logWarning
 
 [slc:realizedFlow] > nt:base
+orderable
 mixin
 // the name of the flow
 // - slc:flow (STRING)