Search in sources :

Example 1 with ByteArrayEntity

use of org.activiti.engine.impl.persistence.entity.ByteArrayEntity 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 ByteArrayEntity

use of org.activiti.engine.impl.persistence.entity.ByteArrayEntity 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)

Aggregations

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