public Environment getEnvironment() { return runtime.getKieSession().getEnvironment(); }
protected void setLogEnvironment(Context cntxt) { if( auditLogService != null ) { return; } if( ! (cntxt instanceof RegistryContext ) ) { throw new UnsupportedOperationException("This command must be executed by a " + KieSession.class.getSimpleName() + " instance!"); } this.auditLogService = new JPAAuditLogService( ((RegistryContext) cntxt).lookup( KieSession.class ).getEnvironment(), PersistenceStrategyType.KIE_SESSION); }
public JPAWorkingMemoryDbLogger(KieSession session) { Environment env = session.getEnvironment(); internalSetIsJTA(env); session.addEventListener(this); } /*
protected boolean isAutoClaim(KieSession session, WorkItem workItem, Task task) { String autoclaim = (String) session.getEnvironment().get("Autoclaim"); if(autoclaim != null && !Boolean.parseBoolean(autoclaim.trim())) { return false; } else { String swimlaneUser = (String) workItem.getParameter("SwimlaneActorId"); if (swimlaneUser != null && !"".equals(swimlaneUser) && task.getTaskData().getStatus() == Status.Ready) { return true; } } return false; }
protected void attachManager(RuntimeEngine runtime) { runtime.getKieSession().getEnvironment().set(EnvironmentName.RUNTIME_MANAGER, this); runtime.getKieSession().getEnvironment().set(EnvironmentName.DEPLOYMENT_ID, this.getIdentifier()); }
protected ContentData createTaskContentBasedOnWorkItemParams(KieSession session, WorkItem workItem) { ContentData content = null; Object contentObject = workItem.getParameter("Content"); if (contentObject == null) { contentObject = new HashMap<String, Object>(workItem.getParameters()); } if (contentObject != null) { Environment env = null; if(session != null){ env = session.getEnvironment(); } content = ContentMarshallerHelper.marshal(null, contentObject, env); } return content; }
@Override public AuditService getAuditService() { if (auditService == null) { boolean usePersistence = ((InternalRuntimeManager)manager).getEnvironment().usePersistence(); if (usePersistence) { auditService = new JPAAuditLogService(getKieSession().getEnvironment()); } else { throw new UnsupportedOperationException("AuditService was not configured, supported only with persistence"); } } return auditService; }
protected void addInterceptors(KieSession ksession) { PersistableRunner runner = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); runner.addInterceptor(new OptimisticLockRetryInterceptor()); // even though it's added always TransactionLockInterceptor is by default disabled so won't do anything runner.addInterceptor(new TransactionLockInterceptor(ksession.getEnvironment())); runner.addInterceptor(new ExecutionErrorHandlerInterceptor(ksession.getEnvironment())); }
protected Map<String, Object> getParametersMap(RuntimeEngine runtime) { RuntimeManager manager = ((RuntimeEngineImpl)runtime).getManager(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("ksession", runtime.getKieSession()); try { parameters.put("taskService", runtime.getTaskService()); } catch (UnsupportedOperationException e) { // in case task service was not configured } parameters.put("runtimeManager", manager); parameters.put("classLoader", getRuntimeManager().getEnvironment().getClassLoader()); parameters.put("entityManagerFactory", runtime.getKieSession().getEnvironment().get(EnvironmentName.ENTITY_MANAGER_FACTORY)); parameters.put("kieContainer", getRuntimeManager().getKieContainer()); return parameters; }
@Override public Void execute(org.kie.api.runtime.Context context) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); ksession.getEnvironment().set("Active", false); InternalProcessRuntime processRuntime = ((InternalKnowledgeRuntime) ksession).getProcessRuntime(); ((ProcessRuntimeImpl) processRuntime).removeProcessEventListeners(); return null; } });
@Override public KieSession initKieSession(Context<?> context, InternalRuntimeManager manager, RuntimeEngine engine) { RuntimeEngine inUse = local.get().get(identifier); if (inUse != null && ((RuntimeEngineImpl) inUse).internalGetKieSession() != null) { return inUse.getKieSession(); } KieSession ksession = factory.newKieSession(); ((RuntimeEngineImpl)engine).internalSetKieSession(ksession); registerDisposeCallback(engine, new DisposeSessionTransactionSynchronization(manager, engine), ksession.getEnvironment()); registerDisposeCallback(engine, new DestroySessionTransactionSynchronization(ksession), ksession.getEnvironment()); registerItems(engine); attachManager(engine); return ksession; }
@Override public Void execute(org.kie.api.runtime.Context context) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); ksession.getEnvironment().set("Active", true); InternalProcessRuntime processRuntime = ((InternalKnowledgeRuntime) ksession).getProcessRuntime(); ((ProcessRuntimeImpl) processRuntime).initProcessEventListeners(); ((ProcessRuntimeImpl) processRuntime).initStartTimers(); return null; } });
protected boolean canDestroy(RuntimeEngine runtime) { if (((RuntimeEngineImpl) runtime).isAfterCompletion()) { return false; } TransactionManager tm = getTransactionManager(runtime.getKieSession().getEnvironment()); if (tm.getStatus() == TransactionManager.STATUS_NO_TRANSACTION || tm.getStatus() == TransactionManager.STATUS_ACTIVE) { return true; } return false; }
protected boolean canDispose(RuntimeEngine runtime) { // avoid duplicated dispose if (((RuntimeEngineImpl)runtime).isDisposed()) { return false; } // if this method was called as part of afterCompletion allow to dispose if (((RuntimeEngineImpl)runtime).isAfterCompletion()) { return true; } try { // check tx status to disallow dispose when within active transaction TransactionManager tm = getTransactionManager(runtime.getKieSession().getEnvironment()); if (tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { return false; } } catch (SessionNotFoundException e) { // ignore it as it might be thrown for per process instance } return true; }
protected Environment getEnvironment(JobContext jobContext) { JobContext ctxorig = jobContext; if (ctxorig instanceof SelfRemovalJobContext) { ctxorig = ((SelfRemovalJobContext) ctxorig).getJobContext(); } // first attempt to get knowledge runtime's environment if job context is a process one if (ctxorig instanceof ProcessJobContext) { return ((ProcessJobContext) ctxorig).getKnowledgeRuntime().getEnvironment(); } else { // next if we have manager set use it to get ksession's environment of active RuntimeEngine // while running this there must be an active RuntimeEngine present if (manager != null) { RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(getProcessInstancId(ctxorig))); return engine.getKieSession().getEnvironment(); } else { // last resort use the runtime environment's environment template return environment.getEnvironment(); } } }
@Override public void afterProcessCompleted(ProcessCompletedEvent event) { mapper.removeMapping(new EnvironmentAwareProcessInstanceContext( event.getKieRuntime().getEnvironment(), event.getProcessInstance().getId()), managerId); factory.onDispose(runtime.getKieSession().getIdentifier()); registerDisposeCallback(runtime, new DestroySessionTransactionSynchronization(runtime.getKieSession()), runtime.getKieSession().getEnvironment()); }
@Test @RequirePersistence public void testCallActivityWithHistoryLog() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-CallActivity.bpmn2", "BPMN2-CallActivitySubProcess.bpmn2"); ksession = createKnowledgeSession(kbase); Map<String, Object> params = new HashMap<String, Object>(); params.put("x", "oldValue"); ProcessInstance processInstance = ksession.startProcess( "ParentProcess", params); assertProcessInstanceCompleted(processInstance); assertEquals("new value", ((WorkflowProcessInstance) processInstance).getVariable("y")); AuditLogService logService = new JPAAuditLogService(ksession.getEnvironment()); List<ProcessInstanceLog> subprocesses = logService.findSubProcessInstances(processInstance.getId()); assertNotNull(subprocesses); assertEquals(1, subprocesses.size()); logService.dispose(); }
@Before public void setUp() throws Exception { context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME); // load the process KieBase kbase = createKnowledgeBase(); // create a new session Environment env = createEnvironment(context); try { session = createKieSession(kbase, env); } catch (Exception ex) { ex.printStackTrace(); Assert.fail("Exception thrown while trying to create a session."); } // working memory logger AbstractAuditLogger dblogger = AuditLoggerFactory.newJPAInstance(session.getEnvironment()); assertNotNull(dblogger); assertTrue(dblogger instanceof JPAWorkingMemoryDbLogger); auditLogService = new JPAAuditLogService(env); session.addEventListener(dblogger); }
@Test @RequirePersistence public void testScriptTaskWithHistoryLog() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-ScriptTask.bpmn2"); ksession = createKnowledgeSession(kbase); ProcessInstance processInstance = ksession.startProcess("ScriptTask"); assertProcessInstanceCompleted(processInstance); AuditLogService logService = new JPAAuditLogService(ksession.getEnvironment()); List<NodeInstanceLog> logs = logService.findNodeInstances(processInstance.getId()); assertNotNull(logs); assertEquals(6, logs.size()); for (NodeInstanceLog log : logs) { assertNotNull(log.getDate()); } ProcessInstanceLog pilog = logService.findProcessInstance(processInstance.getId()); assertNotNull(pilog); assertNotNull(pilog.getEnd()); List<ProcessInstanceLog> pilogs = logService.findActiveProcessInstances(processInstance.getProcessId()); assertNotNull(pilogs); assertEquals(0, pilogs.size()); logService.dispose(); }
NodeInstanceFactoryRegistry.getInstance(ksession.getEnvironment()).register( mockNode.getClass(), factory );