From: Mathieu Baudier Date: Sun, 22 Jan 2012 13:39:07 +0000 (+0000) Subject: Execution attribute of type ref now supported (break data model) X-Git-Tag: argeo-slc-2.1.7~827 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=86fc845e533e99358ec3de7182ea0c01bcd1c432;p=gpl%2Fargeo-slc.git Execution attribute of type ref now supported (break data model) git-svn-id: https://svn.argeo.org/slc/trunk@5002 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java index 28c2f69c6..0d4ae532a 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java @@ -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 = ""; + 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 items = new ArrayList(); + 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); diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java index 9b3764b8a..7d06274b1 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java @@ -136,6 +136,7 @@ public class DefaultExecutionFlowDescriptorConverter implements refValue.getType()); } } else { + // default is to take the value as is convertedValues.put(key, value); } } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java index f9bf37e61..9e1ef2e40 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java @@ -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 : ""); + } + } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/RefSpecAttribute.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/RefSpecAttribute.java index 495f32322..c6c5b035d 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/RefSpecAttribute.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/RefSpecAttribute.java @@ -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 : ""); } } diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java index 793670e7c..51ea14e98 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java @@ -174,7 +174,7 @@ public class SlcJcrUtils implements SlcNames { + node, e); } } - + /** Prevents instantiation */ private SlcJcrUtils() { diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java index ce9aa1da3..4f7af507a 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java @@ -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 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 attrs = readExecutionSpecAttributes(realizedFlowNode); + + // explicitly retrieve values Map values = new HashMap(); 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) { diff --git a/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd b/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd index 3117a3f1a..4e8a4e688 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd +++ b/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd @@ -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)