private static String[] getDirectories(String path) { String content = null; try { content = ConfFileUtils.URLContentsToString( new URL(path + "/index.conf")); } catch (Exception e) { // directory has no index.conf - do nothing } if (content == null) { return new String[0]; } return content.split("\n"); }
@Override public Object transform(Object expression, Map<String, Object> parameters) { logger.debug("About to execute mvel expression {} with parameters {}", expression, parameters); return MVELSafeHelper.getEvaluator().executeExpression(expression, parameters); }
@Override public OrganizationalEntity persistOrgEntity(OrganizationalEntity orgEntity) { check(); if (!StringUtils.isEmpty(orgEntity.getId())) { try { this.em.persist( orgEntity ); if( this.pessimisticLocking ) { this.em.flush(); return this.em.find(OrganizationalEntityImpl.class, orgEntity.getId(), LockModeType.PESSIMISTIC_WRITE ); } } catch (EntityExistsException e) { throw new RuntimeException("Organizational entity already exists with " + orgEntity + " id, please check that there is no group and user with same id"); } } return orgEntity; }
@Test public void testProcessWithBrokenItemDefinitionUri() throws Exception { InputStream inputBpmn = getClass().getResourceAsStream("/BPMN2-BrokenStructureRef.bpmn2"); XmlProcessDumper dumper = XmlProcessDumperFactory.getXmlProcessDumperFactoryService().newXmlProcessDumper(); Assert.assertNotNull(dumper); String processXml = new String(IoUtils.readBytesFromInputStream(inputBpmn), "UTF-8"); Assert.assertNotNull(processXml); org.kie.api.definition.process.Process proc = dumper.readProcess(processXml); Assert.assertNotNull(proc); Assert.assertEquals("BrokenStructureRef", proc.getId()); } }
public void generateTemplates(final String ruleTemplate, final String invokerTemplate, final ProcessBuildContext context, final String className, final Map vars, final Object invokerLookup, final BaseDescr descrLookup) { TemplateRegistry registry = getRuleTemplateRegistry(); context.getMethods().add((String) TemplateRuntime.execute(registry.getNamedTemplate(ruleTemplate), null, new MapVariableResolverFactory(vars), registry) ); registry = getInvokerTemplateRegistry(); final String invokerClassName = context.getPkg().getName() + "." + context.getProcessDescr().getClassName() + StringUtils.ucFirst(className) + "Invoker"; context.getInvokers().put(invokerClassName, (String)TemplateRuntime.execute(registry.getNamedTemplate(invokerTemplate), null, new MapVariableResolverFactory(vars), registry) ); context.addInvokerLookup(invokerClassName, invokerLookup); context.addDescrLookups(invokerClassName, descrLookup); }
protected User addUserFromCallbackOperation(String userId, TaskContext context) { User user = context.getPersistenceContext().findUser(userId); boolean userExists = user != null; if (!StringUtils.isEmpty(userId) && !userExists) { user = TaskModelProvider.getFactory().newUser(); ((InternalOrganizationalEntity) user).setId(userId); persistIfNotExists(user, context); } return user; }
@Test public void testRuleFlow() throws Exception { InputStream in = this.getClass().getResourceAsStream( "/org/jbpm/integrationtests/ruleflow.rfm" ); assertNotNull( in ); builder.addPackage( new PackageDescr( "com.sample" ) ); builder.addRuleFlow( new InputStreamReader( in ) ); InternalKnowledgePackage pkg = builder.getPackage("com.sample"); assertNotNull( pkg ); Map<String, Process> flows = pkg.getRuleFlows(); assertNotNull( flows ); assertEquals( 1, flows.size() ); assertTrue( flows.containsKey( "0" ) ); Process p = (Process) flows.get( "0" ); assertTrue( p instanceof WorkflowProcessImpl ); //now serialization InternalKnowledgePackage pkg2 = (InternalKnowledgePackage) DroolsStreamUtils.streamIn( DroolsStreamUtils.streamOut( pkg ) ); assertNotNull( pkg2 ); flows = pkg2.getRuleFlows(); assertNotNull( flows ); assertEquals( 1, flows.size() ); assertTrue( flows.containsKey( "0" ) ); p = (Process) flows.get( "0" ); assertTrue( p instanceof WorkflowProcessImpl ); }
private boolean evaluateCompletionCondition(String expression, Map<String, Object> tempVariables) { if (expression == null || expression.isEmpty()) { return false; } try { Object result = MVELSafeHelper.getEvaluator().eval(expression, new ForEachNodeInstanceResolverFactory(this, tempVariables)); if ( !(result instanceof Boolean) ) { throw new RuntimeException( "Completion condition expression must return boolean values: " + result + " for expression " + expression); } return ((Boolean) result).booleanValue(); } catch (Throwable t) { t.printStackTrace(); throw new IllegalArgumentException("Could not evaluate completion condition " + expression); } }
private static List<Map<String, Object>> getWorkDefinitionsForPath(String parentPath, String path, String file) { String content = null; try { content = ConfFileUtils.URLContentsToString(new URL(path)); } catch (Exception e) {
protected void addGroupFromCallbackOperation(String groupId, TaskContext context) { Group group = context.getPersistenceContext().findGroup(groupId); boolean groupExists = group != null; if (!StringUtils.isEmpty(groupId) && !groupExists) { group = TaskModelProvider.getFactory().newGroup(); ((InternalOrganizationalEntity) group).setId(groupId); persistIfNotExists(group, context); } }
Object variableValue = MVELSafeHelper.getEvaluator().eval(paramName, new NodeInstanceResolverFactory(this)); if (variableValue != null) { return variableValue;
private static RuntimeEnvironmentBuilder setupClasspathKmoduleBuilder( KieContainer kieContainer, String kbaseName, String ksessionName ) { if (StringUtils.isEmpty(kbaseName)) { KieBaseModel defaultKBaseModel = ((KieContainerImpl)kieContainer).getKieProject().getDefaultKieBaseModel(); if (defaultKBaseModel != null) { kbaseName = defaultKBaseModel.getName(); } else { kbaseName = DEFAULT_KBASE_NAME; } } InternalKieModule module = (InternalKieModule) ((KieContainerImpl)kieContainer).getKieModuleForKBase(kbaseName); if (module == null) { throw new IllegalStateException("Cannot find kbase with name " + kbaseName); } KieBase kbase = kieContainer.getKieBase(kbaseName); return getDefault() .knowledgeBase(kbase) .classLoader(kieContainer.getClassLoader()) .registerableItemsFactory(new KModuleRegisterableItemsFactory(kieContainer, ksessionName)); }
protected Map<String, Object> getSourceParameters(DataAssociation association) { Map<String, Object> parameters = new HashMap<String, Object>(); for (String sourceParam : association.getSources()) { Object parameterValue = null; VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, sourceParam); if (variableScopeInstance != null) { parameterValue = variableScopeInstance.getVariable(sourceParam); } else { try { parameterValue = MVELSafeHelper.getEvaluator().eval(sourceParam, new NodeInstanceResolverFactory(this)); } catch (Throwable t) { logger.warn("Could not find variable scope for variable {}", sourceParam); } } if (parameterValue != null) { parameters.put(association.getTarget(), parameterValue); } } return parameters; }
protected Map<String, Object> getSourceParameters(DataAssociation association) { Map<String, Object> parameters = new HashMap<String, Object>(); for (String sourceParam : association.getSources()) { Object parameterValue = null; VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, sourceParam); if (variableScopeInstance != null) { parameterValue = variableScopeInstance.getVariable(sourceParam); } else { try { parameterValue = MVELSafeHelper.getEvaluator().eval(sourceParam, new NodeInstanceResolverFactory(this)); } catch (Throwable t) { logger.warn("Could not find variable scope for variable {}", sourceParam); } } if (parameterValue != null) { parameters.put(association.getTarget(), parameterValue); } } return parameters; }
protected Map<String, Object> getSourceParameters(DataAssociation association) { Map<String, Object> parameters = new HashMap<String, Object>(); for (String sourceParam : association.getSources()) { Object parameterValue = null; VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, sourceParam); if (variableScopeInstance != null) { parameterValue = variableScopeInstance.getVariable(sourceParam); } else { try { parameterValue = MVELSafeHelper.getEvaluator().eval(sourceParam, new NodeInstanceResolverFactory(this)); } catch (Throwable t) { logger.warn("Could not find variable scope for variable {}", sourceParam); } } if (parameterValue != null) { parameters.put(association.getTarget(), parameterValue); } } return parameters; }
public static Object eval(String str, Map<String, Object> vars) { ParserConfiguration pconf = new ParserConfiguration(); pconf.addPackageImport("org.jbpm.services.task"); // pconf.addPackageImport("org.jbpm.services.task.service"); pconf.addPackageImport("org.jbpm.services.task.query"); pconf.addPackageImport("java.util"); for(String entry : getInputs().keySet()){ pconf.addImport(entry, getInputs().get(entry)); } ParserContext context = new ParserContext(pconf); Serializable s = MVEL.compileExpression(str.trim(), context); if( vars != null ) { return MVELSafeHelper.getEvaluator().executeExpression(s, vars); } else { return MVELSafeHelper.getEvaluator().executeExpression(s); } } public static String toString(Reader reader) throws IOException {
public static Object eval(String str, Map<String, Object> vars) { ParserConfiguration pconf = new ParserConfiguration(); pconf.addPackageImport("org.kie.internal.task.api.model"); pconf.addPackageImport("org.jbpm.services.task"); pconf.addPackageImport("org.jbpm.services.task.impl.model"); pconf.addPackageImport("org.jbpm.services.task.query"); pconf.addPackageImport("org.jbpm.services.task.internals.lifecycle"); pconf.addImport(Status.class); pconf.addImport(Allowed.class); pconf.addPackageImport("java.util"); ParserContext context = new ParserContext(pconf); Serializable s = MVEL.compileExpression(str.trim(), context); if (vars != null) { return MVELSafeHelper.getEvaluator().executeExpression(s, vars); } else { return MVELSafeHelper.getEvaluator().executeExpression(s); } }
public Object eval(String str, Map vars) { ParserContext context = new ParserContext(); context.addPackageImport("org.jbpm.task"); context.addPackageImport("org.jbpm.task.service"); context.addPackageImport("org.jbpm.task.query"); context.addPackageImport("java.util"); vars.put("now", new Date()); return MVELSafeHelper.getEvaluator().executeExpression(MVEL.compileExpression(str, context), vars); }
MVELSafeHelper.getEvaluator().executeExpression( this.expr, null, factory );