Search in sources :

Example 1 with DataType

use of io.automatiko.engine.api.workflow.datatype.DataType in project automatiko-engine by automatiko-io.

the class DefinitionsHandler method setVariableDataType.

private void setVariableDataType(Variable variable, Map<String, ItemDefinition> itemDefinitions, ClassLoader cl) {
    // retrieve type from item definition
    String itemSubjectRef = (String) variable.getMetaData("ItemSubjectRef");
    if (UndefinedDataType.getInstance().equals(variable.getType()) && itemDefinitions != null && itemSubjectRef != null) {
        DataType dataType = new ObjectDataType();
        ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
        if (itemDefinition != null) {
            String structureRef = itemDefinition.getStructureRef();
            if ("java.lang.Boolean".equals(structureRef) || "Boolean".equals(structureRef)) {
                dataType = new BooleanDataType();
            } else if ("java.lang.Integer".equals(structureRef) || "Integer".equals(structureRef)) {
                dataType = new IntegerDataType();
            } else if ("java.lang.Float".equals(structureRef) || "Float".equals(structureRef)) {
                dataType = new FloatDataType();
            } else if ("java.lang.String".equals(structureRef) || "String".equals(structureRef)) {
                dataType = new StringDataType();
            } else if ("java.lang.Object".equals(structureRef) || "Object".equals(structureRef)) {
                // use FQCN of Object
                dataType = new ObjectDataType(java.lang.Object.class, structureRef);
            } else {
                dataType = new ObjectDataType(constructClass(structureRef, cl), structureRef);
            }
        }
        variable.setType(dataType);
    }
}
Also used : StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) FloatDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) DataType(io.automatiko.engine.api.workflow.datatype.DataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) FloatDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType) UndefinedDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.UndefinedDataType) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType)

Example 2 with DataType

use of io.automatiko.engine.api.workflow.datatype.DataType in project automatiko-engine by automatiko-io.

the class DataObjectHandler method start.

@SuppressWarnings("unchecked")
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final String id = attrs.getValue("id");
    final String name = attrs.getValue("name");
    final String itemSubjectRef = attrs.getValue("itemSubjectRef");
    Object parent = parser.getParent();
    if (parent instanceof ContextContainer) {
        ContextContainer contextContainer = (ContextContainer) parent;
        VariableScope variableScope = (VariableScope) contextContainer.getDefaultContext(VariableScope.VARIABLE_SCOPE);
        if (variableScope == null) {
            return null;
        }
        List variables = variableScope.getVariables();
        Variable variable = new Variable();
        variable.setMetaData("DataObject", "true");
        variable.setId(id);
        variable.setName(name);
        variable.setMetaData(id, variable.getName());
        if (localName.equals("dataInput")) {
            variable.setMetaData("DataInput", true);
        } else if (localName.equals("dataOutput")) {
            variable.setMetaData("DataOutput", true);
        }
        // retrieve type from item definition
        DataType dataType = new ObjectDataType();
        Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
        if (itemDefinitions != null) {
            ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
            if (itemDefinition != null) {
                String structureRef = itemDefinition.getStructureRef();
                if ("java.lang.Boolean".equals(structureRef) || "Boolean".equals(structureRef)) {
                    dataType = new BooleanDataType();
                } else if ("java.lang.Integer".equals(structureRef) || "Integer".equals(structureRef)) {
                    dataType = new IntegerDataType();
                } else if ("java.lang.Float".equals(structureRef) || "Float".equals(structureRef)) {
                    dataType = new FloatDataType();
                } else if ("java.lang.String".equals(structureRef) || "String".equals(structureRef)) {
                    dataType = new StringDataType();
                } else if ("java.lang.Object".equals(structureRef) || "Object".equals(structureRef)) {
                    // use FQCN of Object
                    dataType = new ObjectDataType(java.lang.Object.class, structureRef);
                } else {
                    dataType = new ObjectDataType(constructClass(structureRef, parser.getClassLoader()), structureRef);
                }
            }
        }
        variable.setType(dataType);
        variables.add(variable);
        return variable;
    }
    return new Variable();
}
Also used : FloatDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) DataType(io.automatiko.engine.api.workflow.datatype.DataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) FloatDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) List(java.util.List) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType) Map(java.util.Map) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 3 with DataType

use of io.automatiko.engine.api.workflow.datatype.DataType in project automatiko-engine by automatiko-io.

the class DataStoreHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    DataStore store = new DataStore();
    store.setId(attrs.getValue("id"));
    store.setName(attrs.getValue("name"));
    final String itemSubjectRef = attrs.getValue("itemSubjectRef");
    store.setItemSubjectRef(itemSubjectRef);
    Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
    // retrieve type from item definition
    // FIXME we bypass namespace resolving here. That's not a good idea when we
    // start having several documents, with imports.
    String localItemSubjectRef = itemSubjectRef.substring(itemSubjectRef.indexOf(":") + 1);
    DataType dataType = new ObjectDataType();
    if (itemDefinitions != null) {
        ItemDefinition itemDefinition = itemDefinitions.get(localItemSubjectRef);
        if (itemDefinition != null) {
            dataType = new ObjectDataType(constructClass(itemDefinition.getStructureRef(), parser.getClassLoader()), itemDefinition.getStructureRef());
        }
    }
    store.setType(dataType);
    Definitions parent = (Definitions) parser.getParent();
    List<DataStore> dataStores = parent.getDataStores();
    if (dataStores == null) {
        dataStores = new ArrayList<DataStore>();
        parent.setDataStores(dataStores);
    }
    dataStores.add(store);
    return store;
}
Also used : DataStore(io.automatiko.engine.workflow.bpmn2.core.DataStore) Definitions(io.automatiko.engine.workflow.bpmn2.core.Definitions) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) DataType(io.automatiko.engine.api.workflow.datatype.DataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) Map(java.util.Map)

Example 4 with DataType

use of io.automatiko.engine.api.workflow.datatype.DataType in project automatiko-engine by automatiko-io.

the class TypeHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    TypeObject typeable = (TypeObject) parser.getParent();
    String name = attrs.getValue("name");
    emptyAttributeCheck(localName, "name", name, parser);
    DataType dataType = null;
    try {
        dataType = (DataType) Class.forName(name).newInstance();
        // TODO make this pluggable so datatypes can read in other properties as well
        if (dataType instanceof ObjectDataType) {
            String className = attrs.getValue("className");
            if (className == null) {
                className = "java.lang.Object";
            }
            ((ObjectDataType) dataType).setClassName(className);
        }
    } catch (ClassNotFoundException e) {
        throw new SAXParseException("Could not find datatype " + name, parser.getLocator());
    } catch (InstantiationException e) {
        throw new SAXParseException("Could not instantiate datatype " + name, parser.getLocator());
    } catch (IllegalAccessException e) {
        throw new SAXParseException("Could not access datatype " + name, parser.getLocator());
    }
    typeable.setType(dataType);
    return dataType;
}
Also used : SAXParseException(org.xml.sax.SAXParseException) TypeObject(io.automatiko.engine.workflow.base.core.TypeObject) DataType(io.automatiko.engine.api.workflow.datatype.DataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)

Example 5 with DataType

use of io.automatiko.engine.api.workflow.datatype.DataType in project automatiko-engine by automatiko-io.

the class WorkItemNodeInstance method triggerCompleted.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void triggerCompleted(WorkItem workItem) {
    this.workItem = workItem;
    WorkItemNode workItemNode = getWorkItemNode();
    if (workItemNode != null && workItem.getState() == WorkItem.ABORTED) {
        cancel();
        continueToNextNode(io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE, workItemNode);
        return;
    } else if (workItemNode != null && workItem.getState() == WorkItem.COMPLETED) {
        validateWorkItemResultVariable(getProcessInstance().getProcessName(), workItemNode.getOutAssociations(), workItem);
        for (Iterator<DataAssociation> iterator = getWorkItemNode().getOutAssociations().iterator(); iterator.hasNext(); ) {
            DataAssociation association = iterator.next();
            if (association.getTransformation() != null) {
                Transformation transformation = association.getTransformation();
                DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
                if (transformer != null) {
                    Map<String, Object> dataSet = new HashMap<String, Object>();
                    if (getNodeInstanceContainer() instanceof CompositeContextNodeInstance) {
                        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) getNodeInstanceContainer()).getContextInstance(VariableScope.VARIABLE_SCOPE);
                        if (variableScopeInstance != null) {
                            dataSet.putAll(variableScopeInstance.getVariables());
                        }
                    }
                    dataSet.putAll(workItem.getParameters());
                    dataSet.putAll(workItem.getResults());
                    Object parameterValue = transformer.transform(transformation.getCompiledExpression(), dataSet);
                    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VARIABLE_SCOPE, association.getTarget());
                    if (variableScopeInstance != null && parameterValue != null) {
                        variableScopeInstance.getVariableScope().validateVariable(getProcessInstance().getProcessName(), association.getTarget(), parameterValue);
                        variableScopeInstance.setVariable(this, association.getTarget(), parameterValue);
                    } else {
                        logger.warn("Could not find variable scope for variable {}", association.getTarget());
                        logger.warn("when trying to complete Work Item {}", workItem.getName());
                        logger.warn("Continuing without setting variable.");
                    }
                    if (parameterValue != null) {
                        ((WorkItemImpl) workItem).setParameter(association.getTarget(), parameterValue);
                    }
                }
            } else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VARIABLE_SCOPE, association.getTarget());
                if (variableScopeInstance != null) {
                    Object value = workItem.getResult(association.getSources().get(0));
                    if (value == null) {
                        try {
                            ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
                            value = evaluator.evaluate(association.getSources().get(0), new WorkItemResolverFactory(workItem));
                        } catch (Throwable t) {
                        // do nothing
                        }
                    }
                    Variable varDef = variableScopeInstance.getVariableScope().findVariable(association.getTarget());
                    DataType dataType = varDef.getType();
                    // exclude java.lang.Object as it is considered unknown type
                    if (!dataType.getStringType().endsWith("java.lang.Object") && !dataType.getStringType().endsWith("Object") && value instanceof String) {
                        value = dataType.readValue((String) value);
                    } else {
                        variableScopeInstance.getVariableScope().validateVariable(getProcessInstance().getProcessName(), association.getTarget(), value);
                    }
                    variableScopeInstance.setVariable(this, association.getTarget(), value);
                } else {
                    String output = association.getSources().get(0);
                    String target = association.getTarget();
                    Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(target);
                    if (matcher.find()) {
                        String paramName = matcher.group(1);
                        String expression = VariableUtil.transformDotNotation(paramName, output);
                        NodeInstanceResolverFactory resolver = new NodeInstanceResolverFactory(this);
                        resolver.addExtraParameters(workItem.getResults());
                        Serializable compiled = MVEL.compileExpression(expression);
                        MVEL.executeExpression(compiled, resolver);
                        String varName = VariableUtil.nameFromDotNotation(paramName);
                        variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VARIABLE_SCOPE, varName);
                        variableScopeInstance.setVariable(this, varName, variableScopeInstance.getVariable(varName));
                    } else {
                        logger.warn("Could not find variable scope for variable {}", association.getTarget());
                        logger.warn("when trying to complete Work Item {}", workItem.getName());
                        logger.warn("Continuing without setting variable.");
                    }
                }
            } else {
                try {
                    association.getAssignments().forEach(this::handleAssignment);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
    // handle dynamic nodes
    if (getNode() == null) {
        setMetaData("NodeType", workItem.getName());
        mapDynamicOutputData(workItem.getResults());
    }
    triggerCompleted();
}
Also used : Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) Serializable(java.io.Serializable) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) Matcher(java.util.regex.Matcher) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) ProcessWorkItemHandlerException(io.automatiko.engine.api.runtime.process.ProcessWorkItemHandlerException) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) WorkItemResolverFactory(io.automatiko.engine.workflow.process.instance.impl.WorkItemResolverFactory) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Iterator(java.util.Iterator) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) DataType(io.automatiko.engine.api.workflow.datatype.DataType) NamedDataType(io.automatiko.engine.api.workflow.NamedDataType) GroupedNamedDataType(io.automatiko.engine.api.workflow.GroupedNamedDataType) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

DataType (io.automatiko.engine.api.workflow.datatype.DataType)12 ObjectDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)6 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)5 ItemDefinition (io.automatiko.engine.workflow.bpmn2.core.ItemDefinition)5 Map (java.util.Map)5 BooleanDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType)4 FloatDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType)4 IntegerDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType)4 StringDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType)4 VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)4 DataAssociation (io.automatiko.engine.workflow.process.core.node.DataAssociation)4 NodeInstanceResolverFactory (io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory)4 Serializable (java.io.Serializable)4 HashMap (java.util.HashMap)4 Matcher (java.util.regex.Matcher)4 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)3 ExpressionEvaluator (io.automatiko.engine.api.expression.ExpressionEvaluator)2 DataTransformer (io.automatiko.engine.api.runtime.process.DataTransformer)2 NamedDataType (io.automatiko.engine.api.workflow.NamedDataType)2 EventTransformer (io.automatiko.engine.workflow.base.core.event.EventTransformer)2