Search in sources :

Example 1 with AttachmentEntity

use of org.activiti.engine.impl.persistence.entity.AttachmentEntity in project Activiti by Activiti.

the class GetAttachmentContentCmd method execute.

public InputStream execute(CommandContext commandContext) {
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    AttachmentEntity attachment = dbSqlSession.selectById(AttachmentEntity.class, attachmentId);
    String contentId = attachment.getContentId();
    if (contentId == null) {
        return null;
    }
    ByteArrayEntity byteArray = dbSqlSession.selectById(ByteArrayEntity.class, contentId);
    byte[] bytes = byteArray.getBytes();
    return new ByteArrayInputStream(bytes);
}
Also used : ByteArrayEntity(org.activiti.engine.impl.persistence.entity.ByteArrayEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) AttachmentEntity(org.activiti.engine.impl.persistence.entity.AttachmentEntity) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 2 with AttachmentEntity

use of org.activiti.engine.impl.persistence.entity.AttachmentEntity in project Activiti by Activiti.

the class CreateAttachmentCmd method execute.

public Attachment execute(CommandContext commandContext) {
    verifyParameters(commandContext);
    AttachmentEntity attachment = new AttachmentEntity();
    attachment.setName(attachmentName);
    attachment.setDescription(attachmentDescription);
    attachment.setType(attachmentType);
    attachment.setTaskId(taskId);
    attachment.setProcessInstanceId(processInstanceId);
    attachment.setUrl(url);
    attachment.setUserId(Authentication.getAuthenticatedUserId());
    attachment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.insert(attachment);
    if (content != null) {
        byte[] bytes = IoUtil.readInputStream(content, attachmentName);
        ByteArrayEntity byteArray = ByteArrayEntity.createAndInsert(bytes);
        attachment.setContentId(byteArray.getId());
        attachment.setContent(byteArray);
    }
    commandContext.getHistoryManager().createAttachmentComment(taskId, processInstanceId, attachmentName, true);
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        // Forced to fetch the process-instance to associate the right process definition
        String processDefinitionId = null;
        if (attachment.getProcessInstanceId() != null) {
            ExecutionEntity process = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
            if (process != null) {
                processDefinitionId = process.getProcessDefinitionId();
            }
        }
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, attachment, processInstanceId, processInstanceId, processDefinitionId));
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, attachment, processInstanceId, processInstanceId, processDefinitionId));
    }
    return attachment;
}
Also used : ByteArrayEntity(org.activiti.engine.impl.persistence.entity.ByteArrayEntity) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) AttachmentEntity(org.activiti.engine.impl.persistence.entity.AttachmentEntity) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 3 with AttachmentEntity

use of org.activiti.engine.impl.persistence.entity.AttachmentEntity in project Activiti by Activiti.

the class DeleteAttachmentCmd method execute.

public Object execute(CommandContext commandContext) {
    AttachmentEntity attachment = commandContext.getDbSqlSession().selectById(AttachmentEntity.class, attachmentId);
    commandContext.getDbSqlSession().delete(attachment);
    if (attachment.getContentId() != null) {
        commandContext.getByteArrayEntityManager().deleteByteArrayById(attachment.getContentId());
    }
    if (attachment.getTaskId() != null) {
        commandContext.getHistoryManager().createAttachmentComment(attachment.getTaskId(), attachment.getProcessInstanceId(), attachment.getName(), false);
    }
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        // Forced to fetch the process-instance to associate the right process definition
        String processDefinitionId = null;
        String processInstanceId = attachment.getProcessInstanceId();
        if (attachment.getProcessInstanceId() != null) {
            ExecutionEntity process = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
            if (process != null) {
                processDefinitionId = process.getProcessDefinitionId();
            }
        }
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, attachment, processInstanceId, processInstanceId, processDefinitionId));
    }
    return null;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) AttachmentEntity(org.activiti.engine.impl.persistence.entity.AttachmentEntity)

Example 4 with AttachmentEntity

use of org.activiti.engine.impl.persistence.entity.AttachmentEntity in project Activiti by Activiti.

the class SaveAttachmentCmd method execute.

public Object execute(CommandContext commandContext) {
    AttachmentEntity updateAttachment = commandContext.getDbSqlSession().selectById(AttachmentEntity.class, attachment.getId());
    updateAttachment.setName(attachment.getName());
    updateAttachment.setDescription(attachment.getDescription());
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        // Forced to fetch the process-instance to associate the right process definition
        String processDefinitionId = null;
        String processInstanceId = updateAttachment.getProcessInstanceId();
        if (updateAttachment.getProcessInstanceId() != null) {
            ExecutionEntity process = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
            if (process != null) {
                processDefinitionId = process.getProcessDefinitionId();
            }
        }
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, attachment, processInstanceId, processInstanceId, processDefinitionId));
    }
    return null;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) AttachmentEntity(org.activiti.engine.impl.persistence.entity.AttachmentEntity)

Aggregations

AttachmentEntity (org.activiti.engine.impl.persistence.entity.AttachmentEntity)4 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)3 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)2 ByteArrayEntity (org.activiti.engine.impl.persistence.entity.ByteArrayEntity)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1