Skip to content

Commit

Permalink
feat(engine): Setting process definition ID in job log
Browse files Browse the repository at this point in the history
related to #4205
  • Loading branch information
punitdarira authored and yanavasileva committed Sep 4, 2024
1 parent 8086af7 commit 768ad79
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.camunda.bpm.engine.impl.util.ClockUtil;
import org.camunda.bpm.engine.impl.util.JsonUtil;

import static org.camunda.bpm.engine.impl.RestartProcessInstancesBatchConfigurationJsonConverter.PROCESS_DEFINITION_ID;

/**
* Common methods for batch job handlers based on list of ids, providing serialization, configuration instantiation, etc.
*
Expand Down Expand Up @@ -172,6 +174,8 @@ protected void createJobEntities(BatchEntity batch, T configuration, String depl

if (jobConfiguration.getIds() != null && jobConfiguration.getIds().size() == 1) {
job.setProcessInstanceId(jobConfiguration.getIds().get(0));
String processDefinitionId = JsonUtil.getString(JsonUtil.asObject(batch.getConfigurationBytes()), PROCESS_DEFINITION_ID, null);
job.setProcessDefinitionId(processDefinitionId);
}

job.setDeploymentId(deploymentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.camunda.bpm.engine.batch.Batch;
import org.camunda.bpm.engine.batch.history.HistoricBatch;
import org.camunda.bpm.engine.delegate.ExecutionListener;
import org.camunda.bpm.engine.history.HistoricJobLog;
import org.camunda.bpm.engine.history.HistoricProcessInstanceQuery;
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.camunda.bpm.engine.impl.cfg.multitenancy.TenantIdProvider;
Expand Down Expand Up @@ -1150,6 +1151,33 @@ public void shouldSetExecutionStartTimeInBatchAndHistory() {
Assertions.assertThat(historicBatch.getExecutionStartTime()).isEqualToIgnoringMillis(TEST_DATE);
}

@Test
public void shouldSetProcessInstanceAndDefinitionIdInHistoryJobLog() {
// given

ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS);
ProcessInstance processInstance = runtimeService.createProcessInstanceById(processDefinition.getId())
.startBeforeActivity("userTask1")
.execute();
runtimeService.deleteProcessInstance(processInstance.getId(), "test");
Batch batch = runtimeService.restartProcessInstances(processDefinition.getId())
.startAfterActivity("userTask2")
.processInstanceIds(processInstance.getId())
.executeAsync();
helper.executeSeedJob(batch);
List<Job> executionJobs = helper.getExecutionJobs(batch);

// when
helper.executeJob(executionJobs.get(0));

// then
HistoricJobLog jobLog = historyService.createHistoricJobLogQuery().jobDefinitionType(Batch.TYPE_PROCESS_INSTANCE_RESTART).list().get(0);
System.out.println(jobLog);

assertEquals(processInstance.getProcessDefinitionId(), jobLog.getProcessDefinitionId());
assertEquals(processInstance.getRootProcessInstanceId(), jobLog.getProcessInstanceId());
}

protected void assertBatchCreated(Batch batch, int processInstanceCount) {
assertNotNull(batch);
assertNotNull(batch.getId());
Expand Down

0 comments on commit 768ad79

Please sign in to comment.