@PostConstruct public void init() { // make sure it has tx manager as it runs as background thread - no request scope available if (!((JbpmServicesPersistenceManagerImpl) pm).hasTransactionManager()) { ((JbpmServicesPersistenceManagerImpl) pm) .setTransactionManager(new JbpmJTATransactionManager()); } long now = System.currentTimeMillis(); List<DeadlineSummaryImpl> resultList = (List<DeadlineSummaryImpl>) pm.queryInTransaction("UnescalatedStartDeadlines"); for (DeadlineSummaryImpl summary : resultList) { long delay = summary.getDate().getTime() - now; schedule(summary.getTaskId(), summary.getDeadlineId(), delay, DeadlineType.START); } resultList = (List<DeadlineSummaryImpl>) pm.queryInTransaction("UnescalatedEndDeadlines"); for (DeadlineSummaryImpl summary : resultList) { long delay = summary.getDate().getTime() - now; schedule(summary.getTaskId(), summary.getDeadlineId(), delay, DeadlineType.END); } }
@Before public void setUp() throws Exception { ds = new PoolingDataSource(); ds.setUniqueName("jdbc/testDS1"); // NON XA CONFIGS ds.setClassName("org.h2.jdbcx.JdbcDataSource"); ds.setMaxPoolSize(3); ds.setAllowLocalTransactions(true); ds.getDriverProperties().put("user", "sa"); ds.getDriverProperties().put("password", "sasa"); ds.getDriverProperties().put("URL", "jdbc:h2:mem:mydb"); ds.init(); IOService ioService = new IOServiceNio2WrapperImpl(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.domain"); EntityManager em = emf.createEntityManager(); Logger logger = LogManager.getLogManager().getLogger(""); JbpmServicesTransactionManager jbpmJTATransactionManager = new JbpmJTATransactionManager(); JbpmServicesPersistenceManager pm = new JbpmServicesPersistenceManagerImpl(); ((JbpmServicesPersistenceManagerImpl) pm).setEm(em); ((JbpmServicesPersistenceManagerImpl) pm).setTransactionManager(jbpmJTATransactionManager); this.fs = new TestVFSFileServiceImpl(); fs.init(); MVELWorkItemHandlerProducer workItemProducer = new MVELWorkItemHandlerProducer(); workItemProducer.setFs(fs); TestIdentityProvider identityProvider = new TestIdentityProvider(); ServicesAwareAuditEventBuilder auditEventBuilder = new ServicesAwareAuditEventBuilder(); auditEventBuilder.setIdentityProvider(identityProvider); adminDataService = new KnowledgeAdminDataServiceImpl(); ((KnowledgeAdminDataServiceImpl) adminDataService).setPm(pm); bpmn2Service = new BPMN2DataServiceImpl(); ProcessDescriptionRepository repo = new ProcessDescriptionRepository(); ((BPMN2DataServiceImpl) bpmn2Service).setRepository(repo); BPMN2DataServiceSemanticModule semanticModule = new BPMN2DataServiceSemanticModule(); ProcessGetInformationHandler processHandler = new ProcessGetInformationHandler(); processHandler.setRepository(repo); semanticModule.setProcessHandler(processHandler); ProcessGetInputHandler inputHandler = new ProcessGetInputHandler(); inputHandler.setRepository(repo); semanticModule.setProcessInputHandler(inputHandler); GetReusableSubProcessesHandler subProcessHandler = new GetReusableSubProcessesHandler(); subProcessHandler.setRepository(repo); semanticModule.setReusableSubprocessHandler(subProcessHandler); HumanTaskGetInformationHandler taskHandler = new HumanTaskGetInformationHandler(); taskHandler.setRepository(repo); semanticModule.setTaskHandler(taskHandler); semanticModule.init(); ((BPMN2DataServiceImpl) bpmn2Service).setSemanticModule(semanticModule); ((BPMN2DataServiceImpl) bpmn2Service).init(); HumanTaskServiceFactory.setEntityManagerFactory(emf); HumanTaskServiceFactory.setJbpmServicesTransactionManager(jbpmJTATransactionManager); taskService = HumanTaskServiceFactory.newTaskService(); deploymentService = new VFSDeploymentService(); ((VFSDeploymentService) deploymentService).setBpmn2Service(bpmn2Service); ((VFSDeploymentService) deploymentService).setEmf(emf); ((VFSDeploymentService) deploymentService).setFs(fs); ((VFSDeploymentService) deploymentService).setIdentityProvider(identityProvider); ((VFSDeploymentService) deploymentService).setManagerFactory(new RuntimeManagerFactoryImpl()); ((VFSDeploymentService) deploymentService).setPm(pm); }
private void executeEscalatedDeadline(long taskId, long deadlineId, DeadlineType type) { // make sure it has tx manager as it runs as background thread - no request scope available if (!((JbpmServicesPersistenceManagerImpl) pm).hasTransactionManager()) { ((JbpmServicesPersistenceManagerImpl) pm) .setTransactionManager(new JbpmJTATransactionManager()); } TaskImpl task = (TaskImpl) pm.find(TaskImpl.class, taskId); Deadline deadline = (DeadlineImpl) pm.find(DeadlineImpl.class, deadlineId); TaskData taskData = task.getTaskData(); if (taskData != null) { // check if task is still in valid status if (type.isValidStatus(taskData.getStatus())) { Map<String, Object> variables = null; ContentImpl content = (ContentImpl) pm.find(ContentImpl.class, taskData.getDocumentContentId()); if (content != null) { Object objectFromBytes = ContentMarshallerHelper.unmarshall( content.getContent(), getEnvironment(), getClassLoader()); if (objectFromBytes instanceof Map) { variables = (Map) objectFromBytes; } else { variables = new HashMap<String, Object>(); variables.put("content", objectFromBytes); } } else { variables = Collections.emptyMap(); } if (deadline == null || deadline.getEscalations() == null) { return; } for (Escalation escalation : deadline.getEscalations()) { // we won't impl constraints for now // escalation.getConstraints() // run reassignment first to allow notification to be send to new potential owners if (!escalation.getReassignments().isEmpty()) { // get first and ignore the rest. Reassignment reassignment = escalation.getReassignments().get(0); task.getTaskData().setStatus(Status.Ready); List potentialOwners = new ArrayList(reassignment.getPotentialOwners()); task.getPeopleAssignments().setPotentialOwners(potentialOwners); task.getTaskData().setActualOwner(null); } for (Notification notification : escalation.getNotifications()) { if (notification.getNotificationType() == NotificationType.Email) { logger.log(Level.INFO, " ### Sending an Email"); notificationEvents.fire(new NotificationEvent(notification, task, variables)); } } } } } deadline.setEscalated(true); }