use of org.jbpm.process.core.WorkDefinition in project drools-wb by kiegroup.
the class ConfigWorkDefinitionsLoader method loadWorkDefinitions.
public Map<String, WorkDefinition> loadWorkDefinitions() {
// Find all configured WIDs
final Map<String, WorkDefinition> workDefinitions = new HashMap<String, WorkDefinition>();
final List<ConfigGroup> configGroups = configurationService.getConfiguration(ConfigType.EDITOR);
if (configGroups == null || configGroups.isEmpty()) {
return workDefinitions;
}
// Load configured WIDs
final List<String> definitions = new ArrayList<String>();
for (ConfigGroup configGroup : configGroups) {
if (WorkItemsEditorService.WORK_ITEM_DEFINITION.equals(configGroup.getName())) {
for (ConfigItem configItem : configGroup.getItems()) {
definitions.add(configGroup.getConfigItemValue(configItem.getName()));
}
}
}
// Parse MVEL expressions into model
workDefinitions.putAll(WorkDefinitionsParser.parse(definitions));
return workDefinitions;
}
use of org.jbpm.process.core.WorkDefinition 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;
}
use of org.jbpm.process.core.WorkDefinition 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);
}
}
use of org.jbpm.process.core.WorkDefinition 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]);
}
Aggregations