use of org.activiti.engine.repository.ProcessDefinition in project herd by FINRAOS.
the class BaseJavaDelegateTest method testSetSecurityContext.
@Test
public void testSetSecurityContext() throws Exception {
// Set up expected values.
String jobDefinitionNamespace = "jobDefinitionNamespace";
String jobDefinitionName = "jobDefinitionName";
String processDefinitionId = "processDefinitionId";
String processDefinitionKey = String.format("%s.%s", jobDefinitionNamespace, jobDefinitionName);
String updatedBy = "updatedBy";
JobDefinitionEntity jobDefinitionEntity = new JobDefinitionEntity();
jobDefinitionEntity.setUpdatedBy(updatedBy);
// Mock dependency methods.
when(delegateExecution.getProcessDefinitionId()).thenReturn(processDefinitionId);
ProcessDefinition processDefinition = mock(ProcessDefinition.class);
when(processDefinition.getKey()).thenReturn(processDefinitionKey);
when(activitiService.getProcessDefinitionById(any())).thenReturn(processDefinition);
when(jobDefinitionDaoHelper.getJobDefinitionEntity(any(), any())).thenReturn(jobDefinitionEntity);
// Clear the security context.
SecurityContextHolder.clearContext();
// Execute test method.
baseJavaDelegate.setSecurityContext(delegateExecution);
// Verify dependencies were invoked correctly.
InOrder inOrder = inOrder(activitiService, jobDefinitionDaoHelper, userNamespaceAuthorizationHelper);
inOrder.verify(activitiService).getProcessDefinitionById(processDefinitionId);
inOrder.verify(jobDefinitionDaoHelper).getJobDefinitionEntity(jobDefinitionNamespace, jobDefinitionName);
inOrder.verify(userNamespaceAuthorizationHelper).buildNamespaceAuthorizations(applicationUserUserIdEq(updatedBy));
inOrder.verifyNoMoreInteractions();
verifyNoMoreInteractions(activitiService, jobDefinitionDaoHelper, userNamespaceAuthorizationHelper);
// Assert correct user is in the security context.
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
assertAuthenticationUserIdEquals(updatedBy, authentication);
}
use of org.activiti.engine.repository.ProcessDefinition in project herd by FINRAOS.
the class JobServiceGetJobsTest method testGetJobsGivenOneRunningJobAssertReturnCompletedJob.
@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenOneRunningJobAssertReturnCompletedJob() throws Exception {
String namespace = "namespace";
String jobName = "jobName";
JobStatusEnum jobStatus = JobStatusEnum.RUNNING;
long expectedNumberOfExceptions = 1234l;
Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList(namespace));
when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode(namespace);
when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
List<JobDefinitionEntity> jobDefinitionEntities = new ArrayList<>();
JobDefinitionEntity jobDefinitionEntity1 = new JobDefinitionEntity();
jobDefinitionEntity1.setActivitiId(namespace + "." + jobName + ":1" + ":1");
jobDefinitionEntities.add(jobDefinitionEntity1);
when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(jobDefinitionEntities);
ProcessDefinition processDefinition = mock(ProcessDefinition.class);
when(processDefinition.getId()).thenReturn("a.b:1:1");
when(processDefinition.getKey()).thenReturn("a.b");
when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList(processDefinition));
when(activitiService.getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(1l);
List<HistoricProcessInstance> historicProcessInstances = new ArrayList<>();
HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
historicProcessInstanceEntity1.setId("historicProcessInstanceEntity1.id");
historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:1");
historicProcessInstanceEntity1.setStartTime(new Date(1234));
historicProcessInstances.add(historicProcessInstanceEntity1);
when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
when(activitiService.getJobsWithExceptionCountByProcessInstanceId(any())).thenReturn(expectedNumberOfExceptions);
JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
assertEquals(1, jobSummaries.size());
JobSummary jobSummary = jobSummaries.get(0);
assertEquals(historicProcessInstanceEntity1.getId(), jobSummary.getId());
assertEquals("a", jobSummary.getNamespace());
assertEquals("b", jobSummary.getJobName());
assertEquals(JobStatusEnum.RUNNING, jobSummary.getStatus());
assertEquals(historicProcessInstanceEntity1.getStartTime().getTime(), jobSummary.getStartTime().toGregorianCalendar().getTimeInMillis());
assertNull(jobSummary.getEndTime());
assertEquals(expectedNumberOfExceptions, jobSummary.getTotalExceptions());
verify(activitiService).getJobsWithExceptionCountByProcessInstanceId(historicProcessInstanceEntity1.getId());
verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
}
use of org.activiti.engine.repository.ProcessDefinition in project herd by FINRAOS.
the class JobServiceGetJobsTest method testGetJobsWhenActivitiIdIsNotExpectedFormatAssertSuccess.
@SuppressWarnings("unchecked")
@Test
public void testGetJobsWhenActivitiIdIsNotExpectedFormatAssertSuccess() throws Exception {
String namespace = "namespace";
String jobName = "jobName";
String processDefinitionKey = String.format("%s.%s", namespace, jobName);
when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(new HashSet<>(asList(namespace)));
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode(namespace);
when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
JobDefinitionEntity jobDefinitionEntity = new JobDefinitionEntity();
jobDefinitionEntity.setNamespace(namespaceEntity);
jobDefinitionEntity.setName(jobName);
jobDefinitionEntity.setActivitiId("123456");
when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(asList(jobDefinitionEntity));
ProcessDefinition processDefinition = mock(ProcessDefinition.class);
when(processDefinition.getKey()).thenReturn(processDefinitionKey);
when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList(processDefinition));
jobServiceImpl.getJobs(namespace, jobName, AbstractServiceTest.NO_ACTIVITI_JOB_STATUS, NO_START_TIME, NO_END_TIME);
verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(any(), equalsCollection(asList(processDefinitionKey)), any(), any());
verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), equalsCollection(asList(processDefinitionKey)), any(), any());
}
use of org.activiti.engine.repository.ProcessDefinition in project carbon-business-process by wso2.
the class BPMNDataPublisher method configDataPublishing.
/**
* Configure for data publishing to DAS for analytics
*
* @param receiverURLSet Analytics receiver's url
* @param username Analytics server's username
* @param password Analytics server's password
* @param authURLSet Analytics Auth URL set
* @param type Bpmn Analytics Publisher Type
* @param asyncDataPublishingEnabled is async Data Publishing Enabled
* @param genericAnalyticsEnabled is generic Analytics Enabled
* @param kpiAnalyticsEnabled is KPI Analytics Enabled
* @throws DataEndpointAuthenticationException
* @throws DataEndpointAgentConfigurationException
* @throws TransportException
* @throws DataEndpointException
* @throws DataEndpointConfigurationException
*/
void configDataPublishing(String receiverURLSet, String username, String password, String authURLSet, String type, boolean asyncDataPublishingEnabled, boolean genericAnalyticsEnabled, boolean kpiAnalyticsEnabled) throws DataEndpointAuthenticationException, DataEndpointAgentConfigurationException, TransportException, DataEndpointException, DataEndpointConfigurationException {
if (receiverURLSet != null && username != null && password != null) {
// Configure data publisher to be used by all data publishing listeners
if (log.isDebugEnabled()) {
log.debug("Creating BPMN analytics data publisher with Receiver URL: " + receiverURLSet + ", Auth URL: " + authURLSet + " and Data publisher type: " + type);
}
dataPublisher = new DataPublisher(type, receiverURLSet, authURLSet, username, password);
BPMNAnalyticsHolder.getInstance().setAsyncDataPublishingEnabled(asyncDataPublishingEnabled);
BPMNEngineService engineService = BPMNAnalyticsHolder.getInstance().getBpmnEngineService();
// Attach data publishing listeners to all existing processes
if (log.isDebugEnabled()) {
log.debug("Attaching data publishing listeners to already deployed processes...");
}
RepositoryService repositoryService = engineService.getProcessEngine().getRepositoryService();
List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list();
for (ProcessDefinition processDefinition : processDefinitions) {
// Process definition returned by the query does not contain all details such as task definitions.
// And it is also not the actual process definition, but a copy of it, so attaching listners to
// them is useless. Therefore, we have to fetch the complete process definition from the repository
// again.
ProcessDefinition completeProcessDefinition = repositoryService.getProcessDefinition(processDefinition.getId());
if (completeProcessDefinition instanceof ProcessDefinitionEntity) {
ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) completeProcessDefinition;
if (genericAnalyticsEnabled) {
processDefinitionEntity.addExecutionListener(PvmEvent.EVENTNAME_END, new ProcessTerminationListener());
}
if (kpiAnalyticsEnabled) {
processDefinitionEntity.addExecutionListener(PvmEvent.EVENTNAME_END, new ProcessTerminationKPIListener());
}
Map<String, TaskDefinition> tasks = processDefinitionEntity.getTaskDefinitions();
List<ActivityImpl> activities = processDefinitionEntity.getActivities();
for (ActivityImpl activity : activities) {
if (activity.getProperty("type").toString().equalsIgnoreCase("usertask")) {
tasks.get(activity.getId()).addTaskListener(TaskListener.EVENTNAME_COMPLETE, new TaskCompletionListener());
}
// We are publishing analytics data of service tasks in process termination ATM.
// else if(activity.getProperty("type").toString().equalsIgnoreCase("servicetask")){
// activity.addExecutionListener(PvmEvent.EVENTNAME_END,new
// ServiceTaskCompletionListener());
// }
}
}
}
// Configure parse handlers, which attaches data publishing listeners to new processes
if (log.isDebugEnabled()) {
log.debug("Associating parse handlers for processes and tasks, so that data publishing listeners " + "will be attached to new processes.");
}
ProcessEngineConfigurationImpl engineConfig = (ProcessEngineConfigurationImpl) engineService.getProcessEngine().getProcessEngineConfiguration();
if (engineConfig.getPostBpmnParseHandlers() == null) {
engineConfig.setPostBpmnParseHandlers(new ArrayList<BpmnParseHandler>());
}
if (genericAnalyticsEnabled) {
engineConfig.getPostBpmnParseHandlers().add(new ProcessParseHandler());
engineConfig.getPostBpmnParseHandlers().add(new TaskParseHandler());
engineConfig.getBpmnDeployer().getBpmnParser().getBpmnParserHandlers().addHandler(new ProcessParseHandler());
engineConfig.getBpmnDeployer().getBpmnParser().getBpmnParserHandlers().addHandler(new TaskParseHandler());
}
if (kpiAnalyticsEnabled) {
engineConfig.getPostBpmnParseHandlers().add(new ProcessKPIParseHandler());
engineConfig.getBpmnDeployer().getBpmnParser().getBpmnParserHandlers().addHandler(new ProcessKPIParseHandler());
}
} else {
log.warn("Required fields for data publisher are not configured. Receiver URLs, username and password " + "are mandatory. Data publishing will not be enabled.");
}
}
use of org.activiti.engine.repository.ProcessDefinition in project carbon-business-process by wso2.
the class ProcessDefinitionService method activateProcessDefinition.
/**
* This method will activate the given process definition
*
* @param processDefinitionId Process definition id
* @param processDefinitionActionRequest Process definition activate request
* @return Successfully activated then HTTP Response Code 200
* If already activated then HTTP Response Code 409
* If process definition is not found then HTTP Response Code 404
*/
protected Response activateProcessDefinition(String processDefinitionId, ProcessDefinitionActionRequest processDefinitionActionRequest) {
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId);
if (processDefinition != null) {
if (!processDefinition.isSuspended()) {
return Response.status(HttpStatus.SC_CONFLICT).build();
}
repositoryService.activateProcessDefinitionById(processDefinition.getId(), processDefinitionActionRequest.isIncludeProcessInstances(), processDefinitionActionRequest.getDate());
return Response.ok().build();
}
return Response.status(HttpStatus.SC_NOT_FOUND).build();
}
Aggregations