Search in sources :

Example 11 with WorkDefinitionImpl

use of org.jbpm.process.workitem.WorkDefinitionImpl in project kie-wb-common by kiegroup.

the class WorkItemDefinitionParser method parseMVELWorkItemDefinition.

@SuppressWarnings("unchecked")
private static WorkDefinitionImpl parseMVELWorkItemDefinition(final Map<String, Object> workDefinitionMap, final Function<String, String> dataUriProvider, final String name) throws Exception {
    final WorkDefinitionImpl workDefinition = new WorkDefinitionImpl();
    // Name.
    workDefinition.setName(name);
    // Display name.
    set(workDefinitionMap, "displayName", workDefinition::setDisplayName);
    // Category.
    set(workDefinitionMap, "category", BPMNCategories.SERVICE_TASKS, workDefinition::setCategory);
    // Icon.
    set(workDefinitionMap, "icon", workDefinition::setIcon);
    // Icon data-uri.
    if (!isEmpty(workDefinition.getIcon())) {
        final String iconData = dataUriProvider.apply(workDefinition.getIcon());
        workDefinition.setIconEncoded(iconData);
    }
    // Custom editor.
    set(workDefinitionMap, "customEditor", workDefinition::setCustomEditor);
    // Parameters.
    setParameters(workDefinitionMap, "parameters", workDefinition::setParameters);
    // Results.
    setParameters(workDefinitionMap, "results", workDefinition::setResults);
    // Parameter values.
    final Map<String, Object> values = (Map<String, Object>) workDefinitionMap.get("parameterValues");
    if (null != values) {
        final Map<String, Object> parameterValues = new HashMap<>(values.size());
        values.entrySet().forEach(entry -> {
            final Object value = entry.getValue();
            final Function<Object, String> dataTypeFormatter = DATA_TYPE_FORMATTERS.get(value.getClass());
            if (null != dataTypeFormatter) {
                parameterValues.put(entry.getKey(), dataTypeFormatter.apply(value));
            } else {
                LOG.error("The work item's parameter type [" + value.getClass() + "] is not supported. Skipping this parameter.");
            }
        });
        workDefinition.setParameterValues(parameterValues);
    }
    // Default Handler.
    set(workDefinitionMap, "defaultHandler", "", workDefinition::setDefaultHandler);
    // Dependencies.
    setArray(workDefinitionMap, "dependencies", workDefinition::setDependencies);
    // Documentation.
    set(workDefinitionMap, "documentation", "", workDefinition::setDocumentation);
    // Version.
    set(workDefinitionMap, "version", "", workDefinition::setVersion);
    // Description.
    set(workDefinitionMap, "description", "", workDefinition::setDescription);
    // Maven dependencies.
    setArray(workDefinitionMap, "mavenDependencies", workDefinition::setMavenDependencies);
    return workDefinition;
}
Also used : WorkDefinitionImpl(org.jbpm.process.workitem.WorkDefinitionImpl) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with WorkDefinitionImpl

use of org.jbpm.process.workitem.WorkDefinitionImpl 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)

Example 13 with WorkDefinitionImpl

use of org.jbpm.process.workitem.WorkDefinitionImpl in project drools-wb by kiegroup.

the class WorkItemsEditorServiceImpl method loadWorkItemDefinitions.

@Override
public Set<PortableWorkDefinition> loadWorkItemDefinitions(final Path path) {
    final Map<String, WorkDefinition> workDefinitions = new HashMap<String, WorkDefinition>();
    try {
        // Load WorkItemDefinitions from VFS
        final Path projectRoot = moduleService.resolveModule(path).getRootPath();
        workDefinitions.putAll(resourceWorkDefinitionsLoader.loadWorkDefinitions(projectRoot));
        // Load WorkItemDefinitions from ConfigurationService
        workDefinitions.putAll(configWorkDefinitionsLoader.loadWorkDefinitions());
        // Copy the Work Items into Structures suitable for GWT
        final Set<PortableWorkDefinition> workItems = new HashSet<PortableWorkDefinition>();
        for (Map.Entry<String, WorkDefinition> entry : workDefinitions.entrySet()) {
            final PortableWorkDefinition wid = new PortableWorkDefinition();
            final WorkDefinitionImpl wd = (WorkDefinitionImpl) entry.getValue();
            wid.setName(wd.getName());
            wid.setDisplayName(wd.getDisplayName());
            wid.setParameters(convertWorkItemParameters(entry.getValue().getParameters()));
            wid.setResults(convertWorkItemParameters(entry.getValue().getResults()));
            workItems.add(wid);
        }
        return workItems;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) WorkDefinitionImpl(org.jbpm.process.workitem.WorkDefinitionImpl) HashMap(java.util.HashMap) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) WorkDefinition(org.jbpm.process.core.WorkDefinition) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) Map(java.util.Map) HashMap(java.util.HashMap) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) HashSet(java.util.HashSet)

Example 14 with WorkDefinitionImpl

use of org.jbpm.process.workitem.WorkDefinitionImpl in project drools-wb by kiegroup.

the class WorkDefinitionsParserTest method testValidWorkitemDefinition.

@Test
public void testValidWorkitemDefinition() throws Exception {
    List<String> defStrings = new ArrayList<>();
    defStrings.add(loadFile("validWorkItemDefinition.wid"));
    Map<String, WorkDefinition> defs = WorkDefinitionsParser.parse(defStrings);
    assertNotNull(defs);
    assertEquals(1, defs.size());
    WorkDefinitionImpl myTaskDef = (WorkDefinitionImpl) defs.get("MyTask");
    assertNotNull(myTaskDef);
    assertEquals("MyTask", myTaskDef.getName());
    assertNotNull(myTaskDef.getParameter("MyFirstParam"));
    assertNotNull(myTaskDef.getParameter("MySecondParam"));
    assertNotNull(myTaskDef.getParameter("MyThirdParam"));
    assertNotNull(myTaskDef.getParameterValues());
    assertEquals(2, myTaskDef.getParameterValues().size());
    Map<String, Object> paramValues = myTaskDef.getParameterValues();
    assertTrue(paramValues.containsKey("MyFirstParam"));
    assertTrue(paramValues.containsKey("MySecondParam"));
    assertNotNull(myTaskDef.getVersion());
    assertEquals("1.0", myTaskDef.getVersion());
    assertNotNull(myTaskDef.getDocumentation());
    assertEquals("documentation for sample workitem", myTaskDef.getDocumentation());
    assertNotNull(myTaskDef.getDescription());
    assertEquals("this is a sample workitem", myTaskDef.getDescription());
    assertNotNull(myTaskDef.getMavenDependencies());
    assertEquals(1, myTaskDef.getMavenDependencies().length);
    assertEquals("org.jboss:somemodule:3.2", myTaskDef.getMavenDependencies()[0]);
}
Also used : WorkDefinitionImpl(org.jbpm.process.workitem.WorkDefinitionImpl) ArrayList(java.util.ArrayList) WorkDefinition(org.jbpm.process.core.WorkDefinition) Test(org.junit.Test)

Example 15 with WorkDefinitionImpl

use of org.jbpm.process.workitem.WorkDefinitionImpl in project jbpm-work-items by kiegroup.

the class JPAWorkitemIntegrationTest method testWorkitemValidity.

@Test
public void testWorkitemValidity() {
    String repoPath = "file://" + System.getProperty("builddir") + "/" + System.getProperty("artifactId") + "-" + System.getProperty("version") + "/repository";
    Map<String, WorkDefinitionImpl> repoResults = new WorkItemRepository().getWorkDefinitions(repoPath, null, System.getProperty("artifactId"));
    assertNotNull(repoResults);
    assertEquals(1, repoResults.size());
    assertTrue(repoResults.containsKey("JPA"));
}
Also used : WorkDefinitionImpl(org.jbpm.process.workitem.WorkDefinitionImpl) WorkItemRepository(org.jbpm.process.workitem.WorkItemRepository) Test(org.junit.Test)

Aggregations

WorkDefinitionImpl (org.jbpm.process.workitem.WorkDefinitionImpl)27 Test (org.junit.Test)23 WorkItemRepository (org.jbpm.process.workitem.WorkItemRepository)21 HashMap (java.util.HashMap)4 Map (java.util.Map)4 WorkDefinition (org.jbpm.process.core.WorkDefinition)3 HashSet (java.util.HashSet)2 List (java.util.List)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 PortableWorkDefinition (org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition)1 ParameterDefinition (org.jbpm.process.core.ParameterDefinition)1 DataType (org.jbpm.process.core.datatype.DataType)1 ParameterDefinitionImpl (org.jbpm.process.core.impl.ParameterDefinitionImpl)1 ParserContext (org.mvel2.ParserContext)1 Path (org.uberfire.backend.vfs.Path)1 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)1