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); }
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); }
private String findAttachmentContentId(List<Attachment> attachments) { assertEquals(1, attachments.size()); return ((AttachmentEntity) attachments.get(0)).getContentId(); }
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); }
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); }
@SuppressWarnings("unchecked") public void deleteAttachmentsByTaskId(String taskId) { checkHistoryEnabled(); List<AttachmentEntity> attachments = getDbEntityManager().selectList("selectAttachmentsByTaskId", taskId); for (AttachmentEntity attachment: attachments) { String contentId = attachment.getContentId(); if (contentId!=null) { getByteArrayManager().deleteByteArrayById(contentId); } getDbEntityManager().delete(attachment); } }
@SuppressWarnings("unchecked") public void deleteAttachmentsByTaskId(String taskId) { checkHistoryEnabled(); List<AttachmentEntity> attachments = getDbEntityManager().selectList("selectAttachmentsByTaskId", taskId); for (AttachmentEntity attachment: attachments) { String contentId = attachment.getContentId(); if (contentId!=null) { getByteArrayManager().deleteByteArrayById(contentId); } getDbEntityManager().delete(attachment); } }
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; }
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; }
public Object execute(CommandContext commandContext) { AttachmentEntity attachment = (AttachmentEntity) commandContext .getAttachmentManager() .findAttachmentByTaskIdAndAttachmentId(taskId, attachmentId); ensureNotNull("No attachment exist for task id '" + taskId + " and attachmentId '" + attachmentId + "'.", "attachment", attachment); 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; }
public Object execute(CommandContext commandContext) { AttachmentEntity attachment = (AttachmentEntity) commandContext .getAttachmentManager() .findAttachmentByTaskIdAndAttachmentId(taskId, attachmentId); ensureNotNull("No attachment exist for task id '" + taskId + " and attachmentId '" + attachmentId + "'.", "attachment", attachment); 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; }
@Test public void shouldResolveByteArray_CreateAttachmentByTask() { // given testRule.deploy(CALLING_PROCESS); testRule.deploy(CALLED_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); String taskId = taskService.createTaskQuery().singleResult().getId(); // when AttachmentEntity attachment = (AttachmentEntity) taskService.createAttachment(null, taskId, null, null, null, new ByteArrayInputStream("hello world".getBytes())); ByteArrayEntity byteArray = findByteArrayById(attachment.getContentId()); // assume assertThat(byteArray, notNullValue()); // then assertThat(byteArray.getRootProcessInstanceId(), is(processInstance.getProcessInstanceId())); }
@Test public void testAttachmentContentBinaries() { // create and save task Task task = taskService.newTask(); taskService.saveTask(task); taskId = task.getId(); // when AttachmentEntity attachment = (AttachmentEntity) taskService.createAttachment("web page", taskId, "someprocessinstanceid", "weatherforcast", "temperatures and more", new ByteArrayInputStream("someContent".getBytes())); ByteArrayEntity byteArrayEntity = configuration.getCommandExecutorTxRequired().execute(new GetByteArrayCommand(attachment.getContentId())); checkBinary(byteArrayEntity); }
@Test public void shouldResolveByteArray_CreateAttachmentByProcessInstance() { // given testRule.deploy(CALLING_PROCESS); testRule.deploy(CALLED_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); String calledProcessInstanceId = runtimeService.createProcessInstanceQuery() .activityIdIn("userTask") .singleResult() .getId(); // when AttachmentEntity attachment = (AttachmentEntity) taskService.createAttachment(null, null, calledProcessInstanceId, null, null, new ByteArrayInputStream("hello world".getBytes())); ByteArrayEntity byteArray = findByteArrayById(attachment.getContentId()); // assume assertThat(byteArray, notNullValue()); // then assertThat(byteArray.getRootProcessInstanceId(), is(processInstance.getProcessInstanceId())); }
@Test public void shouldResolveByteArray_CreateAttachmentByTask() { // given ClockUtil.setCurrentTime(START_DATE); testRule.deploy(CALLING_PROCESS); testRule.deploy(CALLED_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); String taskId = taskService.createTaskQuery().singleResult().getId(); // when AttachmentEntity attachment = (AttachmentEntity) taskService.createAttachment(null, taskId, null, null, null, new ByteArrayInputStream("hello world".getBytes())); ByteArrayEntity byteArray = findByteArrayById(attachment.getContentId()); // assume assertThat(byteArray, notNullValue()); Date removalTime = addDays(START_DATE, 5); // then assertThat(byteArray.getRemovalTime(), is(removalTime)); }
@Test public void shouldResolveByteArray_CreateAttachmentByTask() { // given testRule.deploy(CALLING_PROCESS); testRule.deploy(CALLED_PROCESS); ClockUtil.setCurrentTime(START_DATE); runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); String taskId = taskService.createTaskQuery().singleResult().getId(); AttachmentEntity attachment = (AttachmentEntity) taskService.createAttachment(null, taskId, null, null, null, new ByteArrayInputStream("hello world".getBytes())); ByteArrayEntity byteArray = findByteArrayById(attachment.getContentId()); // assume assertThat(byteArray.getRemovalTime(), nullValue()); ClockUtil.setCurrentTime(END_DATE); // when taskService.complete(taskId); byteArray = findByteArrayById(attachment.getContentId()); Date removalTime = addDays(END_DATE, 5); // then assertThat(byteArray.getRemovalTime(), is(removalTime)); }
@Test public void shouldResolveByteArray_CreateAttachmentByProcessInstance() { // given ClockUtil.setCurrentTime(START_DATE); testRule.deploy(CALLING_PROCESS); testRule.deploy(CALLED_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); String calledProcessInstanceId = runtimeService.createProcessInstanceQuery() .activityIdIn("userTask") .singleResult() .getId(); // when AttachmentEntity attachment = (AttachmentEntity) taskService.createAttachment(null, null, calledProcessInstanceId, null, null, new ByteArrayInputStream("hello world".getBytes())); ByteArrayEntity byteArray = findByteArrayById(attachment.getContentId()); // assume assertThat(byteArray, notNullValue()); Date removalTime = addDays(START_DATE, 5); // then assertThat(byteArray.getRemovalTime(), is(removalTime)); }
@Test public void shouldResolveByteArray_CreateAttachmentByProcessInstance() { // given testRule.deploy(CALLING_PROCESS); testRule.deploy(CALLED_PROCESS); ClockUtil.setCurrentTime(START_DATE); runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY); String calledProcessInstanceId = runtimeService.createProcessInstanceQuery() .activityIdIn("userTask") .singleResult() .getId(); AttachmentEntity attachment = (AttachmentEntity) taskService.createAttachment(null, null, calledProcessInstanceId, null, null, new ByteArrayInputStream("hello world".getBytes())); ByteArrayEntity byteArray = findByteArrayById(attachment.getContentId()); // assume assertThat(byteArray.getRemovalTime(), nullValue()); ClockUtil.setCurrentTime(END_DATE); String taskId = taskService.createTaskQuery().singleResult().getId(); // when taskService.complete(taskId); byteArray = findByteArrayById(attachment.getContentId()); Date removalTime = addDays(END_DATE, 5); // then assertThat(byteArray.getRemovalTime(), is(removalTime)); }
@SuppressWarnings("unchecked") public void deleteAttachmentsByTaskId(String taskId) { checkHistoryEnabled(); List<AttachmentEntity> attachments = getDbEntityManager().selectList("selectAttachmentsByTaskId", taskId); for (AttachmentEntity attachment: attachments) { String contentId = attachment.getContentId(); if (contentId!=null) { getByteArrayManager().deleteByteArrayById(contentId); } getDbEntityManager().delete(attachment); } }
@Test public void testAttachmentContentBinaries() { // create and save task Task task = taskService.newTask(); taskService.saveTask(task); taskId = task.getId(); // when AttachmentEntity attachment = (AttachmentEntity) taskService.createAttachment("web page", taskId, "someprocessinstanceid", "weatherforcast", "temperatures and more", new ByteArrayInputStream("someContent".getBytes())); ByteArrayEntity byteArrayEntity = configuration.getCommandExecutorTxRequired().execute(new GetByteArrayCommand(attachment.getContentId())); checkBinary(byteArrayEntity); }