Calling service layer instead of Camunda Rest API?

@Himanshu_Singh You can find examples here:

@Service
public class CamundaApiService {

	@Autowired
	private IdentityService identityService;

	@Autowired
	private RepositoryService repositoryService;

	@Autowired
	private TaskService taskService;

	@Autowired
	private FilterService filterService;

	@Autowired
	private ManagementService managementService;

	@Autowired
	private RuntimeService runtimeService;

	public void getFailedJobs(DelegateExecution execution) {

		// Only select jobs that failed due to an exception at an activity with the
		// given id.
		long jobCount = execution.getProcessEngineServices().getManagementService().createJobQuery()
				.failedActivityId("failedActivityId").count();

		// Only select incidents which were created due to a failure at an activity with
		// the given id.
		long incidentCount = execution.getProcessEngineServices().getRuntimeService().createIncidentQuery()
				.failedActivityId("failedActivityId").count();
		
		DbEntityManager dbEntityManager = Context.getCommandContext().getDbEntityManager();
		dbEntityManager.createJobQuery().processDefinitionKey("processDefinitionKey").active().count();
	}

	public void createUnassignedTaskFilter(String processDefinitionKey) {
		TaskQuery taskQuery = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey).taskUnassigned();
		Filter newFilter = new FilterEntity(ResourceTypes.RUNTIME.getName());
		newFilter = newFilter.setName("unassigneTaskFilter").setQuery(taskQuery);
		Filter savedFilter = filterService.saveFilter(newFilter);
		log.info("Unassigned task filter created: {}", savedFilter.getName());
	}

	public void completeTask(String taskId, Map<String, Object> processVariables) {
		taskService.complete(taskId, processVariables);

	}

	public void deleteProcessDefinitionById(String processDefinitionId) {
		repositoryService.deleteProcessDefinition(processDefinitionId, true, true, true);
	}

	public void deleteProcessDefinitionByKey(String processDefinitionKey, Optional<Integer> version) {
		ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery()
				.processDefinitionKey(processDefinitionKey);
		processDefinitionQuery = version.isPresent() ? processDefinitionQuery.processDefinitionVersion(version.get())
				: processDefinitionQuery.latestVersion();
		ProcessDefinition processDefinition = processDefinitionQuery.singleResult();
		repositoryService.deleteProcessDefinition(processDefinition.getId(), true, true, true);
	}

	public void correlateMessage(String businessKey, Object kafkaMessagePayload) {
		VariableMap processVariables = Variables.createVariables().putValue("orderId", 271381983).putValue("name",
				"notebook");
		runtimeService.correlateMessage("PROCESS_KAFKA_MESSAGE",
				businessKey, processVariables);
	}

	// parse bpmn process model and extract taskDefinitionKeys to query active tasks
	// for a swimlane
	public void getTaskItemsForLanes(String processDefinitionKey, String[] taskDefinitionKeys) {
		List<Task> taskList = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey)
				.taskDefinitionKeyIn(taskDefinitionKeys).active().list();
		taskList.forEach(task -> task.setAssignee("adminUser"));
	}

	public String getLoggedInUserId() {
		return identityService.getCurrentAuthentication().getUserId();
	}

	public UserDto getUserDetails() {
		User user = identityService.createUserQuery().userId(getLoggedInUserId()).singleResult();
		log.info("Logged in userid: {}, first name: {}", user.getId(), user.getFirstName());
		return UserDto.fromUser(user, false);
	}

}

2 Likes