use of org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity in project camunda-bpm-platform by camunda.
the class UpdateProcessInstancesSuspendStateJobHandler method execute.
@Override
public void execute(BatchJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {
ByteArrayEntity configurationEntity = commandContext.getDbEntityManager().selectById(ByteArrayEntity.class, configuration.getConfigurationByteArrayId());
UpdateProcessInstancesSuspendStateBatchConfiguration batchConfiguration = readConfiguration(configurationEntity.getBytes());
boolean initialLegacyRestrictions = commandContext.isRestrictUserOperationLogToAuthenticatedUsers();
commandContext.disableUserOperationLog();
commandContext.setRestrictUserOperationLogToAuthenticatedUsers(true);
try {
if (batchConfiguration.getSuspended()) {
commandContext.getProcessEngineConfiguration().getRuntimeService().updateProcessInstanceSuspensionState().byProcessInstanceIds(batchConfiguration.getIds()).suspend();
} else {
commandContext.getProcessEngineConfiguration().getRuntimeService().updateProcessInstanceSuspensionState().byProcessInstanceIds(batchConfiguration.getIds()).activate();
}
} finally {
commandContext.enableUserOperationLog();
commandContext.setRestrictUserOperationLogToAuthenticatedUsers(initialLegacyRestrictions);
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity in project camunda-bpm-platform by camunda.
the class AbstractBatchJobHandler method createJobs.
@Override
public boolean createJobs(BatchEntity batch) {
CommandContext commandContext = Context.getCommandContext();
ByteArrayManager byteArrayManager = commandContext.getByteArrayManager();
JobManager jobManager = commandContext.getJobManager();
T configuration = readConfiguration(batch.getConfigurationBytes());
int batchJobsPerSeed = batch.getBatchJobsPerSeed();
int invocationsPerBatchJob = batch.getInvocationsPerBatchJob();
List<String> ids = configuration.getIds();
int numberOfItemsToProcess = Math.min(invocationsPerBatchJob * batchJobsPerSeed, ids.size());
// view of process instances to process
List<String> processIds = ids.subList(0, numberOfItemsToProcess);
int createdJobs = 0;
while (!processIds.isEmpty()) {
int lastIdIndex = Math.min(invocationsPerBatchJob, processIds.size());
// view of process instances for this job
List<String> idsForJob = processIds.subList(0, lastIdIndex);
T jobConfiguration = createJobConfiguration(configuration, idsForJob);
ByteArrayEntity configurationEntity = saveConfiguration(byteArrayManager, jobConfiguration);
JobEntity job = createBatchJob(batch, configurationEntity);
postProcessJob(configuration, job);
jobManager.insertAndHintJobExecutor(job);
idsForJob.clear();
createdJobs++;
}
// update created jobs for batch
batch.setJobsCreated(batch.getJobsCreated() + createdJobs);
// update batch configuration
batch.setConfigurationBytes(writeConfiguration(configuration));
return ids.isEmpty();
}
use of org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity in project camunda-bpm-platform by camunda.
the class AbstractBatchJobHandler method saveConfiguration.
protected ByteArrayEntity saveConfiguration(ByteArrayManager byteArrayManager, T jobConfiguration) {
ByteArrayEntity configurationEntity = new ByteArrayEntity();
configurationEntity.setBytes(writeConfiguration(jobConfiguration));
byteArrayManager.insert(configurationEntity);
return configurationEntity;
}
use of org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity in project camunda-bpm-platform by camunda.
the class RestartProcessInstancesJobHandler method execute.
@Override
public void execute(BatchJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {
ByteArrayEntity configurationEntity = commandContext.getDbEntityManager().selectById(ByteArrayEntity.class, configuration.getConfigurationByteArrayId());
RestartProcessInstancesBatchConfiguration batchConfiguration = readConfiguration(configurationEntity.getBytes());
boolean initialLegacyRestrictions = commandContext.isRestrictUserOperationLogToAuthenticatedUsers();
commandContext.disableUserOperationLog();
commandContext.setRestrictUserOperationLogToAuthenticatedUsers(true);
try {
RestartProcessInstanceBuilderImpl builder = (RestartProcessInstanceBuilderImpl) commandContext.getProcessEngineConfiguration().getRuntimeService().restartProcessInstances(batchConfiguration.getProcessDefinitionId()).processInstanceIds(batchConfiguration.getIds());
builder.setInstructions(batchConfiguration.getInstructions());
if (batchConfiguration.isInitialVariables()) {
builder.initialSetOfVariables();
}
if (batchConfiguration.isSkipCustomListeners()) {
builder.skipCustomListeners();
}
if (batchConfiguration.isWithoutBusinessKey()) {
builder.withoutBusinessKey();
}
if (batchConfiguration.isSkipIoMappings()) {
builder.skipIoMappings();
}
builder.execute(false);
} finally {
commandContext.enableUserOperationLog();
commandContext.setRestrictUserOperationLogToAuthenticatedUsers(initialLegacyRestrictions);
}
commandContext.getByteArrayManager().delete(configurationEntity);
}
use of org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity in project camunda-bpm-platform by camunda.
the class GetAttachmentContentCmd method execute.
public InputStream execute(CommandContext commandContext) {
DbEntityManager dbEntityManger = commandContext.getDbEntityManager();
AttachmentEntity attachment = dbEntityManger.selectById(AttachmentEntity.class, attachmentId);
String contentId = attachment.getContentId();
if (contentId == null) {
return null;
}
ByteArrayEntity byteArray = dbEntityManger.selectById(ByteArrayEntity.class, contentId);
byte[] bytes = byteArray.getBytes();
return new ByteArrayInputStream(bytes);
}
Aggregations