Search in sources :

Example 1 with ByteArrayEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity in project camunda-bpm-platform by camunda.

the class GetTaskAttachmentContentCmd method execute.

public InputStream execute(CommandContext commandContext) {
    AttachmentEntity attachment = (AttachmentEntity) commandContext.getAttachmentManager().findAttachmentByTaskIdAndAttachmentId(taskId, attachmentId);
    if (attachment == null) {
        return null;
    }
    String contentId = attachment.getContentId();
    if (contentId == null) {
        return null;
    }
    ByteArrayEntity byteArray = commandContext.getDbEntityManager().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)

Example 2 with ByteArrayEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity in project camunda-bpm-platform by camunda.

the class CreateAttachmentCmd method execute.

@Override
public Attachment execute(CommandContext commandContext) {
    if (taskId != null) {
        task = commandContext.getTaskManager().findTaskById(taskId);
    } else {
        ensureNotNull("taskId or processInstanceId has to be provided", this.processInstanceId);
        List<ExecutionEntity> executionsByProcessInstanceId = commandContext.getExecutionManager().findExecutionsByProcessInstanceId(processInstanceId);
        ensureNumberOfElements("processInstances", executionsByProcessInstanceId, 1);
        processInstance = executionsByProcessInstanceId.get(0);
    }
    AttachmentEntity attachment = new AttachmentEntity();
    attachment.setName(attachmentName);
    attachment.setDescription(attachmentDescription);
    attachment.setType(attachmentType);
    attachment.setTaskId(taskId);
    attachment.setProcessInstanceId(processInstanceId);
    attachment.setUrl(url);
    DbEntityManager dbEntityManger = commandContext.getDbEntityManager();
    dbEntityManger.insert(attachment);
    if (content != null) {
        byte[] bytes = IoUtil.readInputStream(content, attachmentName);
        ByteArrayEntity byteArray = new ByteArrayEntity(bytes);
        dbEntityManger.insert(byteArray);
        attachment.setContentId(byteArray.getId());
    }
    PropertyChange propertyChange = new PropertyChange("name", null, attachmentName);
    if (task != null) {
        commandContext.getOperationLogManager().logAttachmentOperation(UserOperationLogEntry.OPERATION_TYPE_ADD_ATTACHMENT, task, propertyChange);
    } else if (processInstance != null) {
        commandContext.getOperationLogManager().logAttachmentOperation(UserOperationLogEntry.OPERATION_TYPE_ADD_ATTACHMENT, processInstance, propertyChange);
    }
    return attachment;
}
Also used : PropertyChange(org.camunda.bpm.engine.impl.persistence.entity.PropertyChange) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) AttachmentEntity(org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)

Example 3 with ByteArrayEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity in project camunda-bpm-platform by camunda.

the class DeleteProcessInstancesJobHandler method execute.

@Override
public void execute(BatchJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {
    ByteArrayEntity configurationEntity = commandContext.getDbEntityManager().selectById(ByteArrayEntity.class, configuration.getConfigurationByteArrayId());
    DeleteProcessInstanceBatchConfiguration batchConfiguration = readConfiguration(configurationEntity.getBytes());
    boolean initialLegacyRestrictions = commandContext.isRestrictUserOperationLogToAuthenticatedUsers();
    commandContext.disableUserOperationLog();
    commandContext.setRestrictUserOperationLogToAuthenticatedUsers(true);
    try {
        commandContext.getProcessEngineConfiguration().getRuntimeService().deleteProcessInstances(batchConfiguration.getIds(), batchConfiguration.deleteReason, batchConfiguration.isSkipCustomListeners(), true, batchConfiguration.isSkipSubprocesses());
    } finally {
        commandContext.enableUserOperationLog();
        commandContext.setRestrictUserOperationLogToAuthenticatedUsers(initialLegacyRestrictions);
    }
    commandContext.getByteArrayManager().delete(configurationEntity);
}
Also used : ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)

Example 4 with ByteArrayEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity in project camunda-bpm-platform by camunda.

the class SetExternalTaskRetriesJobHandler method execute.

@Override
public void execute(BatchJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {
    ByteArrayEntity configurationEntity = commandContext.getDbEntityManager().selectById(ByteArrayEntity.class, configuration.getConfigurationByteArrayId());
    SetRetriesBatchConfiguration batchConfiguration = readConfiguration(configurationEntity.getBytes());
    boolean initialLegacyRestrictions = commandContext.isRestrictUserOperationLogToAuthenticatedUsers();
    commandContext.disableUserOperationLog();
    commandContext.setRestrictUserOperationLogToAuthenticatedUsers(true);
    try {
        commandContext.getProcessEngineConfiguration().getExternalTaskService().setRetries(batchConfiguration.getIds(), batchConfiguration.getRetries());
    } finally {
        commandContext.enableUserOperationLog();
        commandContext.setRestrictUserOperationLogToAuthenticatedUsers(initialLegacyRestrictions);
    }
    commandContext.getByteArrayManager().delete(configurationEntity);
}
Also used : SetRetriesBatchConfiguration(org.camunda.bpm.engine.impl.batch.SetRetriesBatchConfiguration) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)

Example 5 with ByteArrayEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity in project camunda-bpm-platform by camunda.

the class DeleteHistoricProcessInstancesJobHandler method execute.

@Override
public void execute(BatchJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {
    ByteArrayEntity configurationEntity = commandContext.getDbEntityManager().selectById(ByteArrayEntity.class, configuration.getConfigurationByteArrayId());
    BatchConfiguration batchConfiguration = readConfiguration(configurationEntity.getBytes());
    boolean initialLegacyRestrictions = commandContext.isRestrictUserOperationLogToAuthenticatedUsers();
    commandContext.disableUserOperationLog();
    commandContext.setRestrictUserOperationLogToAuthenticatedUsers(true);
    try {
        commandContext.getProcessEngineConfiguration().getHistoryService().deleteHistoricProcessInstances(batchConfiguration.getIds());
    } finally {
        commandContext.enableUserOperationLog();
        commandContext.setRestrictUserOperationLogToAuthenticatedUsers(initialLegacyRestrictions);
    }
    commandContext.getByteArrayManager().delete(configurationEntity);
}
Also used : ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) BatchConfiguration(org.camunda.bpm.engine.impl.batch.BatchConfiguration)

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