Search in sources :

Example 1 with QueryService

use of org.jbpm.services.api.query.QueryService in project jbpm by kiegroup.

the class QueryRunCommand method execute.

public ExecutionResults execute(CommandContext ctx) {
    BeanManager manager = CDIUtils.lookUpBeanManager(ctx);
    String clazz = QueryService.class.getName();
    try {
        QueryService cdiBean = (QueryService) CDIUtils.createBean(Class.forName(clazz), manager);
        logger.info("CDI bean created {}", cdiBean);
        String mapperClass = (String) ctx.getData("mapper");
        if (mapperClass == null) {
            mapperClass = "org.jbpm.kie.services.impl.query.mapper.ProcessInstanceQueryMapper";
        }
        Method m = Class.forName(mapperClass).getMethod("get", new Class[0]);
        QueryResultMapper<?> mapper = (QueryResultMapper<?>) m.invoke(null, new Object[0]);
        Object queryR = cdiBean.query((String) ctx.getData("query"), mapper, new QueryContext());
        logger.info("Result of the query is " + queryR);
    } catch (Exception e) {
        logger.error("Error while creating CDI bean from jbpm executor", e);
    }
    logger.info("Command executed on executor with data {}", ctx.getData());
    ExecutionResults executionResults = new ExecutionResults();
    return executionResults;
}
Also used : QueryResultMapper(org.jbpm.services.api.query.QueryResultMapper) QueryService(org.jbpm.services.api.query.QueryService) ExecutionResults(org.kie.api.executor.ExecutionResults) Method(java.lang.reflect.Method) QueryContext(org.kie.api.runtime.query.QueryContext) BeanManager(javax.enterprise.inject.spi.BeanManager)

Aggregations

Method (java.lang.reflect.Method)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 QueryResultMapper (org.jbpm.services.api.query.QueryResultMapper)1 QueryService (org.jbpm.services.api.query.QueryService)1 ExecutionResults (org.kie.api.executor.ExecutionResults)1 QueryContext (org.kie.api.runtime.query.QueryContext)1