Search in sources :

Example 11 with ByteArrayEntity

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);
    }
}
Also used : ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)

Example 12 with ByteArrayEntity

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();
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) ByteArrayManager(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager)

Example 13 with ByteArrayEntity

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;
}
Also used : ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)

Example 14 with ByteArrayEntity

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);
}
Also used : ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)

Example 15 with ByteArrayEntity

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);
}
Also used : ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) AttachmentEntity(org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)

Aggregations

ByteArrayEntity (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)24 DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)3 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)3 AttachmentEntity (org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity)3 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 BatchConfiguration (org.camunda.bpm.engine.impl.batch.BatchConfiguration)2 SetRetriesBatchConfiguration (org.camunda.bpm.engine.impl.batch.SetRetriesBatchConfiguration)2 ByteArrayManager (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager)2 HistoricJobLogEventEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricJobLogEventEntity)2 IdentityInfoEntity (org.camunda.bpm.engine.impl.persistence.entity.IdentityInfoEntity)2 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)2 Date (java.util.Date)1 Batch (org.camunda.bpm.engine.batch.Batch)1 Picture (org.camunda.bpm.engine.identity.Picture)1 MigrationPlanExecutionBuilderImpl (org.camunda.bpm.engine.impl.migration.MigrationPlanExecutionBuilderImpl)1 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)1 HistoricVariableInstanceEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity)1 PropertyChange (org.camunda.bpm.engine.impl.persistence.entity.PropertyChange)1 MigrationPlanExecutionBuilder (org.camunda.bpm.engine.migration.MigrationPlanExecutionBuilder)1