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);
}
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;
}
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;
}
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);
}
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;
}
Aggregations