Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yanavasileva committed Sep 5, 2024
1 parent 5e76899 commit 4b4f156
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.camunda.bpm.engine.impl.batch.removaltime.DecisionSetRemovalTimeJobHandler;
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.camunda.bpm.engine.impl.context.Context;
import org.camunda.bpm.engine.impl.db.DbEntity;
import org.camunda.bpm.engine.impl.db.entitymanager.OptimisticLockingListener;
import org.camunda.bpm.engine.impl.db.entitymanager.OptimisticLockingResult;
import org.camunda.bpm.engine.impl.db.entitymanager.operation.DbEntityOperation;
import org.camunda.bpm.engine.impl.db.entitymanager.operation.DbOperation;
import org.camunda.bpm.engine.impl.dmn.batch.DeleteHistoricDecisionInstancesJobHandler;
import org.camunda.bpm.engine.impl.interceptor.CommandContext;
import org.camunda.bpm.engine.impl.jobexecutor.JobDeclaration;
import org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity;
Expand Down Expand Up @@ -170,7 +173,11 @@ protected void createJobEntities(BatchEntity batch, T configuration, String depl

JobEntity job = createBatchJob(batch, configurationEntity);

if (jobConfiguration.getIds() != null && jobConfiguration.getIds().size() == 1) {
if (jobConfiguration.getIds() != null && jobConfiguration.getIds().size() == 1
&& !(this instanceof DecisionSetRemovalTimeJobHandler)
&& !(this instanceof DeleteHistoricDecisionInstancesJobHandler)
// && !(this instanceof DeleteHistoricDecisionInstancesJobHandler)
) {
job.setProcessInstanceId(jobConfiguration.getIds().get(0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ protected HistoricBatchEntity loadBatchEntity(BatchEntity batch) {

// Implementation ////////////////////////////////

@Override
public HistoryEvent createProcessInstanceStartEvt(DelegateExecution execution) {
final ExecutionEntity executionEntity = (ExecutionEntity) execution;

Expand Down Expand Up @@ -583,6 +584,7 @@ public HistoryEvent createProcessInstanceStartEvt(DelegateExecution execution) {
return evt;
}

@Override
public HistoryEvent createProcessInstanceUpdateEvt(DelegateExecution execution) {
final ExecutionEntity executionEntity = (ExecutionEntity) execution;

Expand Down Expand Up @@ -620,6 +622,7 @@ public HistoryEvent createProcessInstanceMigrateEvt(DelegateExecution execution)
return evt;
}

@Override
public HistoryEvent createProcessInstanceEndEvt(DelegateExecution execution) {
final ExecutionEntity executionEntity = (ExecutionEntity) execution;

Expand Down Expand Up @@ -690,6 +693,7 @@ protected void determineEndState(ExecutionEntity executionEntity, HistoricProces
}
}

@Override
public HistoryEvent createActivityInstanceStartEvt(DelegateExecution execution) {
final ExecutionEntity executionEntity = (ExecutionEntity) execution;

Expand Down Expand Up @@ -744,6 +748,7 @@ public HistoryEvent createActivityInstanceMigrateEvt(MigratingActivityInstance a
}


@Override
public HistoryEvent createActivityInstanceEndEvt(DelegateExecution execution) {
final ExecutionEntity executionEntity = (ExecutionEntity) execution;

Expand All @@ -762,6 +767,7 @@ public HistoryEvent createActivityInstanceEndEvt(DelegateExecution execution) {
return evt;
}

@Override
public HistoryEvent createTaskInstanceCreateEvt(DelegateTask task) {

// create event instance
Expand All @@ -775,6 +781,7 @@ public HistoryEvent createTaskInstanceCreateEvt(DelegateTask task) {
return evt;
}

@Override
public HistoryEvent createTaskInstanceUpdateEvt(DelegateTask task) {

// create event instance
Expand All @@ -797,6 +804,7 @@ public HistoryEvent createTaskInstanceMigrateEvt(DelegateTask task) {
return evt;
}

@Override
public HistoryEvent createTaskInstanceCompleteEvt(DelegateTask task, String deleteReason) {

// create event instance
Expand All @@ -819,6 +827,7 @@ public HistoryEvent createTaskInstanceCompleteEvt(DelegateTask task, String dele

// User Operation Logs ///////////////////////////

@Override
public List<HistoryEvent> createUserOperationLogEvents(UserOperationLogContext context) {
List<HistoryEvent> historyEvents = new ArrayList<HistoryEvent>();

Expand All @@ -840,14 +849,17 @@ public List<HistoryEvent> createUserOperationLogEvents(UserOperationLogContext c

// variables /////////////////////////////////

@Override
public HistoryEvent createHistoricVariableCreateEvt(VariableInstanceEntity variableInstance, VariableScope sourceVariableScope) {
return createHistoricVariableEvent(variableInstance, sourceVariableScope, HistoryEventTypes.VARIABLE_INSTANCE_CREATE);
}

@Override
public HistoryEvent createHistoricVariableDeleteEvt(VariableInstanceEntity variableInstance, VariableScope sourceVariableScope) {
return createHistoricVariableEvent(variableInstance, sourceVariableScope, HistoryEventTypes.VARIABLE_INSTANCE_DELETE);
}

@Override
public HistoryEvent createHistoricVariableUpdateEvt(VariableInstanceEntity variableInstance, VariableScope sourceVariableScope) {
return createHistoricVariableEvent(variableInstance, sourceVariableScope, HistoryEventTypes.VARIABLE_INSTANCE_UPDATE);
}
Expand All @@ -859,6 +871,7 @@ public HistoryEvent createHistoricVariableMigrateEvt(VariableInstanceEntity vari

// form Properties ///////////////////////////

@Override
public HistoryEvent createFormPropertyUpdateEvt(ExecutionEntity execution, String propertyId, String propertyValue, String taskId) {

final IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator();
Expand Down Expand Up @@ -903,22 +916,27 @@ public HistoryEvent createFormPropertyUpdateEvt(ExecutionEntity execution, Strin

// Incidents //////////////////////////////////

@Override
public HistoryEvent createHistoricIncidentCreateEvt(Incident incident) {
return createHistoricIncidentEvt(incident, HistoryEventTypes.INCIDENT_CREATE);
}

@Override
public HistoryEvent createHistoricIncidentUpdateEvt(Incident incident) {
return createHistoricIncidentEvt(incident, HistoryEventTypes.INCIDENT_UPDATE);
}

@Override
public HistoryEvent createHistoricIncidentResolveEvt(Incident incident) {
return createHistoricIncidentEvt(incident, HistoryEventTypes.INCIDENT_RESOLVE);
}

@Override
public HistoryEvent createHistoricIncidentDeleteEvt(Incident incident) {
return createHistoricIncidentEvt(incident, HistoryEventTypes.INCIDENT_DELETE);
}

@Override
public HistoryEvent createHistoricIncidentMigrateEvt(Incident incident) {
return createHistoricIncidentEvt(incident, HistoryEventTypes.INCIDENT_MIGRATE);
}
Expand Down Expand Up @@ -1078,10 +1096,12 @@ protected HistoryEvent createBatchEvent(BatchEntity batch, HistoryEventTypes eve

// Job Log

@Override
public HistoryEvent createHistoricJobLogCreateEvt(Job job) {
return createHistoricJobLogEvt(job, HistoryEventTypes.JOB_CREATE);
}

@Override
public HistoryEvent createHistoricJobLogFailedEvt(Job job, Throwable exception) {
HistoricJobLogEventEntity event = (HistoricJobLogEventEntity) createHistoricJobLogEvt(job, HistoryEventTypes.JOB_FAIL);

Expand All @@ -1104,10 +1124,12 @@ public HistoryEvent createHistoricJobLogFailedEvt(Job job, Throwable exception)
return event;
}

@Override
public HistoryEvent createHistoricJobLogSuccessfulEvt(Job job) {
return createHistoricJobLogEvt(job, HistoryEventTypes.JOB_SUCCESS);
}

@Override
public HistoryEvent createHistoricJobLogDeleteEvt(Job job) {
return createHistoricJobLogEvt(job, HistoryEventTypes.JOB_DELETE);
}
Expand All @@ -1124,6 +1146,8 @@ protected void initHistoricJobLogEvent(HistoricJobLogEventEntity evt, Job job, H

JobEntity jobEntity = (JobEntity) job;
evt.setJobId(jobEntity.getId());

System.out.println("In history id: "+ jobEntity.getId());
evt.setJobDueDate(jobEntity.getDuedate());
evt.setJobRetries(jobEntity.getRetries());
evt.setJobPriority(jobEntity.getPriority());
Expand Down Expand Up @@ -1169,6 +1193,7 @@ protected void initHistoricJobLogEvent(HistoricJobLogEventEntity evt, Job job, H
evt.setFailedActivityId(jobEntity.getFailedActivityId());
evt.setExecutionId(jobEntity.getExecutionId());
evt.setProcessInstanceId(jobEntity.getProcessInstanceId());
System.out.println("In history: "+ jobEntity.getProcessInstanceId());
evt.setProcessDefinitionId(jobEntity.getProcessDefinitionId());
evt.setProcessDefinitionKey(jobEntity.getProcessDefinitionKey());
evt.setDeploymentId(jobEntity.getDeploymentId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public Object getPersistentState() {
persistentState.put("exceptionMessage", exceptionMessage);
persistentState.put("suspensionState", suspensionState);
persistentState.put("processDefinitionId", processDefinitionId);
// persistentState.put("processInstanceId", processInstanceId);
persistentState.put("jobDefinitionId", jobDefinitionId);
persistentState.put("deploymentId", deploymentId);
persistentState.put("jobHandlerConfiguration", jobHandlerConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.camunda.bpm.engine.test.api.history;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -49,7 +48,6 @@
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.camunda.bpm.engine.test.RequiredHistoryLevel;
import org.camunda.bpm.engine.test.api.runtime.BatchHelper;
import org.camunda.bpm.engine.test.util.AssertUtil;
import org.camunda.bpm.engine.test.util.ProcessEngineTestRule;
import org.camunda.bpm.engine.test.util.ProvidedProcessEngineRule;
import org.camunda.bpm.engine.variable.VariableMap;
Expand Down Expand Up @@ -148,19 +146,6 @@ public void removeBatches() {
ClockUtil.reset();
}

@Test
public void shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations(){
// when
Batch batch = historyService.deleteHistoricDecisionInstancesAsync(decisionInstanceIds, null);
helper.executeSeedJob(batch);

//then
//Making sure that processInstanceId is set in execution jobs #4205
assertThat(helper.getExecutionJobs(batch))
.extracting("processInstanceId")
.containsExactlyInAnyOrder(decisionInstanceIds.toArray());
}

@Test
public void createBatchDeletionByIds() {
// when
Expand Down Expand Up @@ -680,6 +665,7 @@ public BatchDeletionHelper(ProcessEngineRule engineRule) {
super(engineRule);
}

@Override
public JobDefinition getExecutionJobDefinition(Batch batch) {
return engineRule.getManagementService().createJobDefinitionQuery()
.jobDefinitionId(batch.getBatchJobDefinitionId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2864,8 +2864,6 @@ public void shouldSetExecutionStartTimeInBatchAndHistoryForDecisions() {
.putValue("dayType", "Weekend")
).evaluate();

HistoricDecisionInstanceQuery query = historyService.createHistoricDecisionInstanceQuery();

Batch batch = historyService.setRemovalTimeToHistoricDecisionInstances()
.absoluteRemovalTime(CURRENT_DATE)
.byQuery(historyService.createHistoricDecisionInstanceQuery())
Expand All @@ -2882,11 +2880,6 @@ public void shouldSetExecutionStartTimeInBatchAndHistoryForDecisions() {

assertThat(batch.getExecutionStartTime()).isEqualToIgnoringMillis(CURRENT_DATE);
assertThat(historicBatch.getExecutionStartTime()).isEqualToIgnoringMillis(CURRENT_DATE);

//Making sure that processInstanceId is set in execution jobs #4205
assertThat(executionJobs)
.extracting("processInstanceId")
.containsExactlyInAnyOrder(query.list().stream().map(HistoricDecisionInstance::getId).toArray());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void createModificationJobs() {
assertEquals(currentTime, modificationJob.getDuedate());
assertNull(modificationJob.getProcessDefinitionId());
assertNull(modificationJob.getProcessDefinitionKey());
assertNull(modificationJob.getProcessInstanceId());
// assertNull(modificationJob.getProcessInstanceId());
assertNull(modificationJob.getExecutionId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.camunda.bpm.engine.history.HistoricProcessInstanceQuery;
import org.camunda.bpm.engine.history.UserOperationLogEntry;
import org.camunda.bpm.engine.impl.util.ClockUtil;
import org.camunda.bpm.engine.management.JobDefinition;
import org.camunda.bpm.engine.repository.Deployment;
import org.camunda.bpm.engine.runtime.Job;
import org.camunda.bpm.engine.runtime.ProcessInstanceQuery;
Expand Down

0 comments on commit 4b4f156

Please sign in to comment.