Search in sources :

Example 1 with AttachmentEntity

use of org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity 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 AttachmentEntity

use of org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity 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 AttachmentEntity

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

the class SaveAttachmentCmd method execute.

public Object execute(CommandContext commandContext) {
    AttachmentEntity updateAttachment = commandContext.getDbEntityManager().selectById(AttachmentEntity.class, attachment.getId());
    updateAttachment.setName(attachment.getName());
    updateAttachment.setDescription(attachment.getDescription());
    return null;
}
Also used : AttachmentEntity(org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity)

Example 4 with AttachmentEntity

use of org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity 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)

Example 5 with AttachmentEntity

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

the class DeleteAttachmentCmd method execute.

public Object execute(CommandContext commandContext) {
    AttachmentEntity attachment = commandContext.getDbEntityManager().selectById(AttachmentEntity.class, attachmentId);
    commandContext.getDbEntityManager().delete(attachment);
    if (attachment.getContentId() != null) {
        commandContext.getByteArrayManager().deleteByteArrayById(attachment.getContentId());
    }
    if (attachment.getTaskId() != null) {
        TaskEntity task = commandContext.getTaskManager().findTaskById(attachment.getTaskId());
        PropertyChange propertyChange = new PropertyChange("name", null, attachment.getName());
        commandContext.getOperationLogManager().logAttachmentOperation(UserOperationLogEntry.OPERATION_TYPE_DELETE_ATTACHMENT, task, propertyChange);
    }
    return null;
}
Also used : TaskEntity(org.camunda.bpm.engine.impl.persistence.entity.TaskEntity) PropertyChange(org.camunda.bpm.engine.impl.persistence.entity.PropertyChange) AttachmentEntity(org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity)

Aggregations

AttachmentEntity (org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity)6 ByteArrayEntity (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)3 PropertyChange (org.camunda.bpm.engine.impl.persistence.entity.PropertyChange)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)2 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)2 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)1