Search in sources :

Example 1 with TransactionalCommandService

use of org.jbpm.shared.services.impl.TransactionalCommandService in project jbpm by kiegroup.

the class AbstractCaseServicesBaseTest method configureServices.

protected void configureServices() {
    buildDatasource();
    emf = EntityManagerFactoryManager.get().getOrCreate("org.jbpm.domain");
    identityProvider = new TestIdentityProvider();
    authorizationManager = new AuthorizationManagerImpl(identityProvider, new TransactionalCommandService(emf));
    // build definition service
    bpmn2Service = new BPMN2DataServiceImpl();
    DeploymentRolesManager deploymentRolesManager = new DeploymentRolesManager();
    queryService = new QueryServiceImpl();
    ((QueryServiceImpl) queryService).setIdentityProvider(identityProvider);
    ((QueryServiceImpl) queryService).setCommandService(new TransactionalCommandService(emf));
    ((QueryServiceImpl) queryService).init();
    // build deployment service
    deploymentService = new KModuleDeploymentService();
    ((KModuleDeploymentService) deploymentService).setBpmn2Service(bpmn2Service);
    ((KModuleDeploymentService) deploymentService).setEmf(emf);
    ((KModuleDeploymentService) deploymentService).setIdentityProvider(identityProvider);
    ((KModuleDeploymentService) deploymentService).setManagerFactory(new RuntimeManagerFactoryImpl());
    ((KModuleDeploymentService) deploymentService).setFormManagerService(new FormManagerServiceImpl());
    TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).getTaskService();
    // build runtime data service
    runtimeDataService = new RuntimeDataServiceImpl();
    ((RuntimeDataServiceImpl) runtimeDataService).setCommandService(new TransactionalCommandService(emf));
    ((RuntimeDataServiceImpl) runtimeDataService).setIdentityProvider(identityProvider);
    ((RuntimeDataServiceImpl) runtimeDataService).setTaskService(taskService);
    ((RuntimeDataServiceImpl) runtimeDataService).setDeploymentRolesManager(deploymentRolesManager);
    ((RuntimeDataServiceImpl) runtimeDataService).setTaskAuditService(TaskAuditServiceFactory.newTaskAuditServiceConfigurator().setTaskService(taskService).getTaskAuditService());
    ((KModuleDeploymentService) deploymentService).setRuntimeDataService(runtimeDataService);
    // build process service
    processService = new ProcessServiceImpl();
    ((ProcessServiceImpl) processService).setDataService(runtimeDataService);
    ((ProcessServiceImpl) processService).setDeploymentService(deploymentService);
    // build user task service
    userTaskService = new UserTaskServiceImpl();
    ((UserTaskServiceImpl) userTaskService).setDataService(runtimeDataService);
    ((UserTaskServiceImpl) userTaskService).setDeploymentService(deploymentService);
    // build case id generator
    caseIdGenerator = new TableCaseIdGenerator(new TransactionalCommandService(emf));
    // build case runtime data service
    caseRuntimeDataService = new CaseRuntimeDataServiceImpl();
    ((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setCaseIdGenerator(caseIdGenerator);
    ((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setRuntimeDataService(runtimeDataService);
    ((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setCommandService(new TransactionalCommandService(emf));
    ((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setIdentityProvider(identityProvider);
    ((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setDeploymentRolesManager(deploymentRolesManager);
    // build case service
    caseService = new CaseServiceImpl();
    ((CaseServiceImpl) caseService).setCaseIdGenerator(caseIdGenerator);
    ((CaseServiceImpl) caseService).setCaseRuntimeDataService(caseRuntimeDataService);
    ((CaseServiceImpl) caseService).setProcessService(processService);
    ((CaseServiceImpl) caseService).setDeploymentService(deploymentService);
    ((CaseServiceImpl) caseService).setRuntimeDataService(runtimeDataService);
    ((CaseServiceImpl) caseService).setCommandService(new TransactionalCommandService(emf));
    ((CaseServiceImpl) caseService).setAuthorizationManager(authorizationManager);
    ((CaseServiceImpl) caseService).setIdentityProvider(identityProvider);
    CaseConfigurationDeploymentListener configurationListener = new CaseConfigurationDeploymentListener(identityProvider);
    // set runtime data service as listener on deployment service
    ((KModuleDeploymentService) deploymentService).addListener((RuntimeDataServiceImpl) runtimeDataService);
    ((KModuleDeploymentService) deploymentService).addListener((BPMN2DataServiceImpl) bpmn2Service);
    ((KModuleDeploymentService) deploymentService).addListener((QueryServiceImpl) queryService);
    ((KModuleDeploymentService) deploymentService).addListener((CaseRuntimeDataServiceImpl) caseRuntimeDataService);
    ((KModuleDeploymentService) deploymentService).addListener(configurationListener);
}
Also used : FormManagerServiceImpl(org.jbpm.kie.services.impl.FormManagerServiceImpl) BPMN2DataServiceImpl(org.jbpm.kie.services.impl.bpmn2.BPMN2DataServiceImpl) RuntimeManagerFactoryImpl(org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl) CaseConfigurationDeploymentListener(org.jbpm.casemgmt.impl.event.CaseConfigurationDeploymentListener) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) UserTaskServiceImpl(org.jbpm.kie.services.impl.UserTaskServiceImpl) TableCaseIdGenerator(org.jbpm.casemgmt.impl.generator.TableCaseIdGenerator) DeploymentRolesManager(org.jbpm.kie.services.impl.security.DeploymentRolesManager) KModuleDeploymentService(org.jbpm.kie.services.impl.KModuleDeploymentService) ProcessServiceImpl(org.jbpm.kie.services.impl.ProcessServiceImpl) RuntimeDataServiceImpl(org.jbpm.kie.services.impl.RuntimeDataServiceImpl) CaseRuntimeDataServiceImpl(org.jbpm.casemgmt.impl.CaseRuntimeDataServiceImpl) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) CaseServiceImpl(org.jbpm.casemgmt.impl.CaseServiceImpl) CaseRuntimeDataServiceImpl(org.jbpm.casemgmt.impl.CaseRuntimeDataServiceImpl) QueryServiceImpl(org.jbpm.kie.services.impl.query.QueryServiceImpl) AuthorizationManagerImpl(org.jbpm.casemgmt.impl.AuthorizationManagerImpl)

Example 2 with TransactionalCommandService

use of org.jbpm.shared.services.impl.TransactionalCommandService in project jbpm by kiegroup.

the class JPAExecutorServiceProducer method produceStoreService.

@Produces
public ExecutorStoreService produceStoreService() {
    ExecutorStoreService storeService = new JPAExecutorStoreService(true);
    TransactionalCommandService commandService = new TransactionalCommandService(emf);
    ((JPAExecutorStoreService) storeService).setCommandService(commandService);
    ((JPAExecutorStoreService) storeService).setEmf(emf);
    return storeService;
}
Also used : ExecutorStoreService(org.kie.api.executor.ExecutorStoreService) JPAExecutorStoreService(org.jbpm.executor.impl.jpa.JPAExecutorStoreService) JPAExecutorStoreService(org.jbpm.executor.impl.jpa.JPAExecutorStoreService) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) Produces(javax.enterprise.inject.Produces)

Example 3 with TransactionalCommandService

use of org.jbpm.shared.services.impl.TransactionalCommandService in project jbpm by kiegroup.

the class JPAExecutorServiceProducer method produceAdminService.

@Produces
public ExecutorAdminService produceAdminService() {
    ExecutorAdminService adminService = new ExecutorRequestAdminServiceImpl();
    TransactionalCommandService commandService = new TransactionalCommandService(emf);
    ((ExecutorRequestAdminServiceImpl) adminService).setCommandService(commandService);
    return adminService;
}
Also used : ExecutorAdminService(org.kie.api.executor.ExecutorAdminService) ExecutorRequestAdminServiceImpl(org.jbpm.executor.impl.jpa.ExecutorRequestAdminServiceImpl) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) Produces(javax.enterprise.inject.Produces)

Example 4 with TransactionalCommandService

use of org.jbpm.shared.services.impl.TransactionalCommandService in project jbpm by kiegroup.

the class ExecutionErrorCleanupCommand method execute.

@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
    SimpleDateFormat formatToUse = DATE_FORMAT;
    String dataFormat = (String) ctx.getData("DateFormat");
    if (dataFormat != null) {
        formatToUse = new SimpleDateFormat(dataFormat);
    }
    ExecutionResults executionResults = new ExecutionResults();
    String emfName = (String) ctx.getData("EmfName");
    if (emfName == null) {
        emfName = "org.jbpm.domain";
    }
    String singleRun = (String) ctx.getData("SingleRun");
    if ("true".equalsIgnoreCase(singleRun)) {
        // disable rescheduling
        this.nextScheduleTimeAdd = -1;
    }
    String nextRun = (String) ctx.getData("NextRun");
    if (nextRun != null) {
        nextScheduleTimeAdd = DateTimeUtils.parseDateAsDuration(nextRun);
    }
    // get hold of persistence and create instance of audit service
    EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(emfName);
    // collect parameters
    String olderThan = (String) ctx.getData("OlderThan");
    String olderThanPeriod = (String) ctx.getData("OlderThanPeriod");
    String forProcess = (String) ctx.getData("ForProcess");
    String forProcessInstance = (String) ctx.getData("ForProcessInstance");
    String forDeployment = (String) ctx.getData("ForDeployment");
    if (olderThanPeriod != null) {
        long olderThanDuration = DateTimeUtils.parseDateAsDuration(olderThanPeriod);
        Date olderThanDate = new Date(System.currentTimeMillis() - olderThanDuration);
        olderThan = formatToUse.format(olderThanDate);
    }
    Map<String, Object> parameters = new HashMap<>();
    StringBuilder cleanUpErrorsQuery = new StringBuilder();
    cleanUpErrorsQuery.append("delete from ExecutionErrorInfo where processInstanceId in " + "(select processInstanceId from ProcessInstanceLog where status in (2,3))");
    if (olderThan != null && !olderThan.isEmpty()) {
        cleanUpErrorsQuery.append(" and errorDate < :olderThan");
        parameters.put("olderThan", formatToUse.parse(olderThan));
    }
    if (forProcess != null && !forProcess.isEmpty()) {
        cleanUpErrorsQuery.append(" and processId = :forProcess");
        parameters.put("forProcess", forProcess);
    }
    if (forProcessInstance != null && !forProcessInstance.isEmpty()) {
        cleanUpErrorsQuery.append(" and processInstanceId = :forProcessInstance");
        parameters.put("forProcessInstance", Long.parseLong(forProcessInstance));
    }
    if (forDeployment != null && !forDeployment.isEmpty()) {
        cleanUpErrorsQuery.append(" and deploymentId = :forDeployment");
        parameters.put("forDeployment", forDeployment);
    }
    TransactionalCommandService commandService = new TransactionalCommandService(emf);
    int deletedErrors = commandService.execute(new UpdateStringCommand(cleanUpErrorsQuery.toString(), parameters));
    logger.debug("Number of Execution errors deleted {}", deletedErrors);
    executionResults.setData("ErrorsDeleted", deletedErrors);
    return executionResults;
}
Also used : HashMap(java.util.HashMap) ExecutionResults(org.kie.api.executor.ExecutionResults) Date(java.util.Date) UpdateStringCommand(org.jbpm.shared.services.impl.commands.UpdateStringCommand) EntityManagerFactory(javax.persistence.EntityManagerFactory) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with TransactionalCommandService

use of org.jbpm.shared.services.impl.TransactionalCommandService in project jbpm by kiegroup.

the class DeploymentServiceWithSyncTest method configureDeploymentSync.

protected void configureDeploymentSync() {
    assertNotNull(deploymentService);
    store = new DeploymentStore();
    if (commandService == null) {
        commandService = new TransactionalCommandService(emf);
    }
    store.setCommandService(commandService);
    DeploymentSynchronizer sync = new DeploymentSynchronizer();
    sync.setDeploymentService(deploymentService);
    sync.setDeploymentStore(store);
    invoker = new DeploymentSyncInvoker(sync, 1L, 1L, TimeUnit.SECONDS);
    invoker.start();
}
Also used : DeploymentStore(org.jbpm.kie.services.impl.store.DeploymentStore) DeploymentSyncInvoker(org.jbpm.kie.services.impl.store.DeploymentSyncInvoker) DeploymentSynchronizer(org.jbpm.kie.services.impl.store.DeploymentSynchronizer) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService)

Aggregations

TransactionalCommandService (org.jbpm.shared.services.impl.TransactionalCommandService)14 Produces (javax.enterprise.inject.Produces)4 DeploymentStore (org.jbpm.kie.services.impl.store.DeploymentStore)3 Before (org.junit.Before)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)2 FormManagerServiceImpl (org.jbpm.kie.services.impl.FormManagerServiceImpl)2 KModuleDeploymentService (org.jbpm.kie.services.impl.KModuleDeploymentService)2 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)2 ProcessServiceImpl (org.jbpm.kie.services.impl.ProcessServiceImpl)2 RuntimeDataServiceImpl (org.jbpm.kie.services.impl.RuntimeDataServiceImpl)2 UserTaskServiceImpl (org.jbpm.kie.services.impl.UserTaskServiceImpl)2 BPMN2DataServiceImpl (org.jbpm.kie.services.impl.bpmn2.BPMN2DataServiceImpl)2 QueryServiceImpl (org.jbpm.kie.services.impl.query.QueryServiceImpl)2 DeploymentSyncInvoker (org.jbpm.kie.services.impl.store.DeploymentSyncInvoker)2