use of pro.taskana.Attachment in project taskana by Taskana.
the class TaskAttachmentTest method testRemoveAttachment.
@Test
public void testRemoveAttachment() {
// Testing normal way
Attachment attachment1 = createAttachment("ID1", "taskId1");
Attachment attachment2 = createAttachment("ID2", "taskId1");
cut.addAttachment(attachment1);
cut.addAttachment(attachment2);
Attachment actual = cut.removeAttachment(attachment2.getId());
assertThat(cut.getAttachments().size(), equalTo(1));
assertThat(actual, equalTo(attachment2));
}
use of pro.taskana.Attachment in project taskana by Taskana.
the class TaskServiceImpl method getTask.
@Override
public Task getTask(String id) throws TaskNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to getTaskById(id = {})", id);
TaskImpl resultTask = null;
try {
taskanaEngine.openConnection();
resultTask = taskMapper.findById(id);
if (resultTask != null) {
WorkbasketQueryImpl query = (WorkbasketQueryImpl) workbasketService.createWorkbasketQuery();
query.setUsedToAugmentTasks(true);
String workbasketId = resultTask.getWorkbasketSummary().getId();
List<WorkbasketSummary> workbaskets = query.idIn(workbasketId).list();
if (workbaskets.isEmpty()) {
String currentUser = CurrentUserContext.getUserid();
LOGGER.error("The current user {} has no read permission for workbasket {}.", currentUser, workbasketId);
throw new NotAuthorizedException("The current user " + currentUser + " has no read permission for workbasket " + workbasketId);
} else {
resultTask.setWorkbasketSummary(workbaskets.get(0));
}
List<AttachmentImpl> attachmentImpls = attachmentMapper.findAttachmentsByTaskId(resultTask.getId());
if (attachmentImpls == null) {
attachmentImpls = new ArrayList<>();
}
List<ClassificationSummary> classifications;
try {
classifications = findClassificationForTaskImplAndAttachments(resultTask, attachmentImpls);
} catch (NotAuthorizedException e1) {
LOGGER.error("ClassificationQuery unexpectedly returned NotauthorizedException. Throwing SystemException ");
throw new SystemException("ClassificationQuery unexpectedly returned NotauthorizedException.");
}
List<Attachment> attachments = addClassificationSummariesToAttachments(resultTask, attachmentImpls, classifications);
resultTask.setAttachments(attachments);
String classificationId = resultTask.getClassificationSummary().getId();
ClassificationSummary classification = classifications.stream().filter(c -> c.getId().equals(classificationId)).findFirst().orElse(null);
if (classification == null) {
LOGGER.error("Could not find a Classification for task {} ", resultTask);
throw new SystemException("Could not find a Classification for task " + resultTask.getId());
}
resultTask.setClassificationSummary(classification);
return resultTask;
} else {
LOGGER.warn("Method getTaskById() didn't find task with id {}. Throwing TaskNotFoundException", id);
throw new TaskNotFoundException(id, "Task with id " + id + " was not found");
}
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from getTaskById(). Returning result {} ", resultTask);
}
}
use of pro.taskana.Attachment in project taskana by Taskana.
the class TaskServiceImpl method classificationChanged.
BulkOperationResults<String, Exception> classificationChanged(String taskId, String classificationId) throws TaskNotFoundException, NotAuthorizedException, ClassificationNotFoundException {
LOGGER.debug("entry to classificationChanged(taskId = {} , classificationId = {} )", taskId, classificationId);
TaskImpl task = null;
BulkOperationResults<String, Exception> bulkLog = new BulkOperationResults<>();
try {
taskanaEngine.openConnection();
if (taskId == null || taskId.isEmpty() || classificationId == null || classificationId.isEmpty()) {
return bulkLog;
}
task = taskMapper.findById(taskId);
List<AttachmentImpl> attachmentImpls = attachmentMapper.findAttachmentsByTaskId(task.getId());
if (attachmentImpls == null) {
attachmentImpls = new ArrayList<>();
}
List<Attachment> attachments = augmentAttachmentsByClassification(attachmentImpls, bulkLog);
task.setAttachments(attachments);
Classification classification = classificationService.getClassification(classificationId);
task.setClassificationSummary(classification.asSummary());
PrioDurationHolder prioDurationFromAttachments = handleAttachmentsOnClassificationUpdate(task);
updateClassificationRelatedProperties(task, task, prioDurationFromAttachments);
task.setModified(Instant.now());
taskMapper.update(task);
return bulkLog;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from deleteTask(). ");
}
}
use of pro.taskana.Attachment in project taskana by Taskana.
the class TaskServiceImpl method handleAttachmentsOnClassificationUpdate.
private PrioDurationHolder handleAttachmentsOnClassificationUpdate(Task task) {
Duration minDuration = MAX_DURATION;
int maxPrio = Integer.MIN_VALUE;
// Iterator for removing invalid current values directly. OldAttachments can be ignored.
Iterator<Attachment> i = task.getAttachments().iterator();
while (i.hasNext()) {
Attachment attachment = i.next();
if (attachment != null) {
ClassificationSummary classification = attachment.getClassificationSummary();
if (classification != null) {
PrioDurationHolder newPrioDuration = getNewPrioDuration(maxPrio, minDuration, classification.getPriority(), classification.getServiceLevel());
maxPrio = newPrioDuration.getPrio();
minDuration = newPrioDuration.getDuration();
}
}
}
if (minDuration != null && MAX_DURATION.equals(minDuration)) {
minDuration = null;
}
return new PrioDurationHolder(minDuration, maxPrio);
}
use of pro.taskana.Attachment in project taskana by Taskana.
the class TaskServiceImpl method standardSettings.
private void standardSettings(TaskImpl task, Classification classification, PrioDurationHolder prioDurationFromAttachments) {
Instant now = Instant.now();
task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK));
task.setState(TaskState.READY);
task.setCreated(now);
task.setModified(now);
task.setRead(false);
task.setTransferred(false);
String creator = CurrentUserContext.getUserid();
if (taskanaEngine.getConfiguration().isSecurityEnabled()) {
if (creator == null) {
throw new SystemException("TaskanaSecurity is enabled, but the current UserId is NULL while creating a Task.");
}
}
task.setCreator(creator);
if (task.getPlanned() == null) {
task.setPlanned(now);
}
// if no business process id is provided, a unique id is created.
if (task.getBusinessProcessId() == null) {
task.setBusinessProcessId(IdGenerator.generateWithPrefix(ID_PREFIX_BUSINESS_PROCESS));
}
if (classification != null) {
PrioDurationHolder finalPrioDuration = getNewPrioDuration(prioDurationFromAttachments.getPrio(), prioDurationFromAttachments.getDuration(), classification.getPriority(), classification.getServiceLevel());
Duration finalDuration = finalPrioDuration.getDuration();
if (finalDuration != null && !MAX_DURATION.equals(finalDuration)) {
long days = converter.convertWorkingDaysToDays(task.getPlanned(), finalDuration.toDays());
Instant due = task.getPlanned().plus(Duration.ofDays(days));
task.setDue(due);
}
task.setPriority(finalPrioDuration.getPrio());
}
if (task.getName() == null) {
task.setName(classification.getName());
}
if (task.getDescription() == null) {
task.setDescription(classification.getDescription());
}
// insert Attachments if needed
List<Attachment> attachments = task.getAttachments();
if (attachments != null) {
for (Attachment attachment : attachments) {
AttachmentImpl attachmentImpl = (AttachmentImpl) attachment;
attachmentImpl.setId(IdGenerator.generateWithPrefix(ID_PREFIX_ATTACHMENT));
attachmentImpl.setTaskId(task.getId());
attachmentImpl.setCreated(now);
attachmentImpl.setModified(now);
attachmentMapper.insert(attachmentImpl);
}
}
}
Aggregations