Search in sources :

Example 1 with DataType

use of org.jbpm.process.core.datatype.DataType in project drools-wb by kiegroup.

the class WorkItemsEditorServiceImpl method convertWorkItemParameters.

private Set<PortableParameterDefinition> convertWorkItemParameters(final Set<ParameterDefinition> parameters) {
    final Set<PortableParameterDefinition> pps = new HashSet<PortableParameterDefinition>();
    for (ParameterDefinition pd : parameters) {
        final DataType pdt = pd.getType();
        PortableParameterDefinition ppd = null;
        if (pdt instanceof BooleanDataType) {
            ppd = new PortableBooleanParameterDefinition();
        } else if (pdt instanceof FloatDataType) {
            ppd = new PortableFloatParameterDefinition();
        } else if (pdt instanceof IntegerDataType) {
            ppd = new PortableIntegerParameterDefinition();
        } else if (pdt instanceof ObjectDataType) {
            ppd = new PortableObjectParameterDefinition();
            final PortableObjectParameterDefinition oppd = (PortableObjectParameterDefinition) ppd;
            final ObjectDataType odt = (ObjectDataType) pdt;
            oppd.setClassName(odt.getClassName());
        } else if (pd.getType() instanceof StringDataType) {
            ppd = new PortableStringParameterDefinition();
        }
        if (ppd != null) {
            ppd.setName(pd.getName());
            pps.add(ppd);
        }
    }
    return pps;
}
Also used : PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) FloatDataType(org.jbpm.process.core.datatype.impl.type.FloatDataType) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) PortableObjectParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableObjectParameterDefinition) PortableParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) DataType(org.jbpm.process.core.datatype.DataType) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) FloatDataType(org.jbpm.process.core.datatype.impl.type.FloatDataType) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType) HashSet(java.util.HashSet) PortableObjectParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableObjectParameterDefinition) ParameterDefinition(org.jbpm.process.core.ParameterDefinition) PortableParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition)

Example 2 with DataType

use of org.jbpm.process.core.datatype.DataType in project drools-wb by kiegroup.

the class WorkDefinitionsParser method parse.

/**
 * Parse a MVEL String into WorkDefinitions
 * @param workItemDefinitions
 * @return
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Map<String, WorkDefinition> parse(final List<String> workItemDefinitions) {
    final Map<String, WorkDefinition> workDefinitions = new HashMap<String, WorkDefinition>();
    // Add Data-type imports, in-case they are missing from definition
    final ParserContext context = new ParserContext();
    // Compile expression and convert String
    for (String workItemDefinition : workItemDefinitions) {
        final List<Map<String, Object>> workDefinitionsMap = (List<Map<String, Object>>) WidMVELEvaluator.eval(workItemDefinition);
        // Populate model
        if (workDefinitionsMap != null) {
            for (Map<String, Object> workDefinitionMap : workDefinitionsMap) {
                if (workDefinitionMap != null) {
                    final WorkDefinitionImpl workDefinition = new WorkDefinitionImpl();
                    workDefinition.setName((String) workDefinitionMap.get("name"));
                    workDefinition.setDisplayName((String) workDefinitionMap.get("displayName"));
                    workDefinition.setIcon((String) workDefinitionMap.get("icon"));
                    workDefinition.setCustomEditor((String) workDefinitionMap.get("customEditor"));
                    final Set<ParameterDefinition> parameters = new HashSet<ParameterDefinition>();
                    if (workDefinitionMap.get("parameters") != null) {
                        final Map<String, DataType> parameterMap = (Map<String, DataType>) workDefinitionMap.get("parameters");
                        if (parameterMap != null) {
                            for (Map.Entry<String, DataType> entry : parameterMap.entrySet()) {
                                parameters.add(new ParameterDefinitionImpl(entry.getKey(), entry.getValue()));
                            }
                        }
                        workDefinition.setParameters(parameters);
                    }
                    if (workDefinitionMap.get("parameterValues") != null) {
                        workDefinition.setParameterValues((Map<String, Object>) workDefinitionMap.get("parameterValues"));
                    }
                    if (workDefinitionMap.get("results") != null) {
                        final Set<ParameterDefinition> results = new HashSet<ParameterDefinition>();
                        final Map<String, DataType> resultMap = (Map<String, DataType>) workDefinitionMap.get("results");
                        if (resultMap != null) {
                            for (Map.Entry<String, DataType> entry : resultMap.entrySet()) {
                                results.add(new ParameterDefinitionImpl(entry.getKey(), entry.getValue()));
                            }
                        }
                        workDefinition.setResults(results);
                    }
                    if (workDefinitionMap.get("defaultHandler") != null) {
                        workDefinition.setDefaultHandler((String) workDefinitionMap.get("defaultHandler"));
                    }
                    if (workDefinitionMap.get("dependencies") != null) {
                        workDefinition.setDependencies(((List<String>) workDefinitionMap.get("dependencies")).toArray(new String[0]));
                    }
                    if (workDefinitionMap.get("documentation") != null) {
                        workDefinition.setDocumentation((String) workDefinitionMap.get("documentation"));
                    }
                    if (workDefinitionMap.get("version") != null) {
                        workDefinition.setVersion((String) workDefinitionMap.get("version"));
                    }
                    if (workDefinitionMap.get("description") != null) {
                        workDefinition.setDescription((String) workDefinitionMap.get("description"));
                    }
                    if (workDefinitionMap.get("mavenDependencies") != null) {
                        workDefinition.setMavenDependencies(((List<String>) workDefinitionMap.get("mavenDependencies")).toArray(new String[0]));
                    }
                    workDefinitions.put(workDefinition.getName(), workDefinition);
                }
            }
        }
    }
    return workDefinitions;
}
Also used : WorkDefinitionImpl(org.jbpm.process.workitem.WorkDefinitionImpl) HashMap(java.util.HashMap) ParameterDefinitionImpl(org.jbpm.process.core.impl.ParameterDefinitionImpl) WorkDefinition(org.jbpm.process.core.WorkDefinition) DataType(org.jbpm.process.core.datatype.DataType) List(java.util.List) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap) ParameterDefinition(org.jbpm.process.core.ParameterDefinition) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 ParameterDefinition (org.jbpm.process.core.ParameterDefinition)2 DataType (org.jbpm.process.core.datatype.DataType)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 PortableBooleanParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition)1 PortableFloatParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition)1 PortableIntegerParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition)1 PortableObjectParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableObjectParameterDefinition)1 PortableParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableParameterDefinition)1 PortableStringParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition)1 WorkDefinition (org.jbpm.process.core.WorkDefinition)1 BooleanDataType (org.jbpm.process.core.datatype.impl.type.BooleanDataType)1 FloatDataType (org.jbpm.process.core.datatype.impl.type.FloatDataType)1 IntegerDataType (org.jbpm.process.core.datatype.impl.type.IntegerDataType)1 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)1 StringDataType (org.jbpm.process.core.datatype.impl.type.StringDataType)1 ParameterDefinitionImpl (org.jbpm.process.core.impl.ParameterDefinitionImpl)1 WorkDefinitionImpl (org.jbpm.process.workitem.WorkDefinitionImpl)1