use of pro.taskana.ClassificationSummary in project taskana by Taskana.
the class TaskServiceImpl method augmentAttachmentsByClassification.
private List<Attachment> augmentAttachmentsByClassification(List<AttachmentImpl> attachmentImpls, BulkOperationResults<String, Exception> bulkLog) {
List<Attachment> result = new ArrayList<>();
if (attachmentImpls == null || attachmentImpls.isEmpty()) {
return result;
}
Set<String> classificationIds = attachmentImpls.stream().map(t -> t.getClassificationSummary().getId()).collect(Collectors.toSet());
List<ClassificationSummary> classifications = classificationService.createClassificationQuery().idIn(classificationIds.toArray(new String[0])).list();
for (AttachmentImpl att : attachmentImpls) {
ClassificationSummary classificationSummary = classifications.stream().filter(cl -> cl.getId().equals(att.getClassificationSummary().getId())).findFirst().orElse(null);
if (classificationSummary == null) {
String id = att.getClassificationSummary().getId();
bulkLog.addError(att.getClassificationSummary().getId(), new ClassificationNotFoundException(id, "When processing task updates due to change of classification, the classification with id " + id + " was not found."));
} else {
att.setClassificationSummary(classificationSummary);
result.add(att);
}
}
return result;
}
use of pro.taskana.ClassificationSummary in project taskana by Taskana.
the class TaskServiceImpl method handleAttachmentsOnTaskUpdate.
private PrioDurationHolder handleAttachmentsOnTaskUpdate(TaskImpl oldTaskImpl, TaskImpl newTaskImpl) throws AttachmentPersistenceException {
Duration minDuration = MAX_DURATION;
int maxPrio = Integer.MIN_VALUE;
// Iterator for removing invalid current values directly. OldAttachments can be ignored.
Iterator<Attachment> i = newTaskImpl.getAttachments().iterator();
while (i.hasNext()) {
Attachment attachment = i.next();
if (attachment != null) {
boolean wasAlreadyPresent = false;
if (attachment.getId() != null) {
for (Attachment oldAttachment : oldTaskImpl.getAttachments()) {
if (oldAttachment != null && attachment.getId().equals(oldAttachment.getId())) {
wasAlreadyPresent = true;
if (!attachment.equals(oldAttachment)) {
AttachmentImpl temp = (AttachmentImpl) attachment;
ClassificationSummary classification = attachment.getClassificationSummary();
if (classification != null) {
PrioDurationHolder newPrioDuration = getNewPrioDuration(maxPrio, minDuration, classification.getPriority(), classification.getServiceLevel());
maxPrio = newPrioDuration.getPrio();
minDuration = newPrioDuration.getDuration();
}
temp.setModified(Instant.now());
attachmentMapper.update(temp);
LOGGER.debug("TaskService.updateTask() for TaskId={} UPDATED an Attachment={}.", newTaskImpl.getId(), attachment);
break;
}
}
}
}
// ADD, when ID not set or not found in elements
if (!wasAlreadyPresent) {
AttachmentImpl attachmentImpl = (AttachmentImpl) attachment;
initAttachment(attachmentImpl, newTaskImpl);
ClassificationSummary classification = attachment.getClassificationSummary();
if (classification != null) {
PrioDurationHolder newPrioDuration = getNewPrioDuration(maxPrio, minDuration, classification.getPriority(), classification.getServiceLevel());
maxPrio = newPrioDuration.getPrio();
minDuration = newPrioDuration.getDuration();
}
try {
attachmentMapper.insert(attachmentImpl);
LOGGER.debug("TaskService.updateTask() for TaskId={} INSERTED an Attachment={}.", newTaskImpl.getId(), attachmentImpl);
} catch (PersistenceException e) {
LOGGER.error("TaskService.updateTask() for TaskId={} can NOT INSERT the current Attachment, because it was added fored multiple times and wasn´t persisted before. ID={}", newTaskImpl.getId(), attachmentImpl.getId());
throw new AttachmentPersistenceException(attachmentImpl.getId());
}
}
} else {
i.remove();
}
}
// DELETE, when an Attachment was only represented before
for (Attachment oldAttachment : oldTaskImpl.getAttachments()) {
if (oldAttachment != null) {
boolean isRepresented = false;
for (Attachment newAttachment : newTaskImpl.getAttachments()) {
if (newAttachment != null && oldAttachment.getId().equals(newAttachment.getId())) {
isRepresented = true;
break;
}
}
if (!isRepresented) {
attachmentMapper.deleteAttachment(oldAttachment.getId());
LOGGER.debug("TaskService.updateTask() for TaskId={} DELETED an Attachment={}.", newTaskImpl.getId(), oldAttachment);
}
}
}
if (minDuration != null && MAX_DURATION.equals(minDuration)) {
minDuration = null;
}
return new PrioDurationHolder(minDuration, maxPrio);
}
use of pro.taskana.ClassificationSummary in project taskana by Taskana.
the class ClassificationQueryImpl method single.
@Override
public ClassificationSummary single() {
LOGGER.debug("entry to single(), this = {}", this);
ClassificationSummary result = null;
try {
taskanaEngine.openConnection();
result = taskanaEngine.getSqlSession().selectOne(LINK_TO_SUMMARYMAPPER, this);
return result;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", result);
}
}
use of pro.taskana.ClassificationSummary in project taskana by Taskana.
the class ClassificationDefinitionController method importClassifications.
@PostMapping(path = "/import")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> importClassifications(@RequestBody List<ClassificationResource> classificationResources) throws InvalidArgumentException {
Map<String, String> systemIds = classificationService.createClassificationQuery().list().stream().collect(Collectors.toMap(i -> i.getKey() + "|" + i.getDomain(), ClassificationSummary::getId));
try {
for (ClassificationResource classificationResource : classificationResources) {
if (systemIds.containsKey(classificationResource.key + "|" + classificationResource.domain)) {
classificationService.updateClassification(classificationMapper.toModel(classificationResource));
} else {
classificationResource.classificationId = null;
classificationService.createClassification(classificationMapper.toModel(classificationResource));
}
}
} catch (NotAuthorizedException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
} catch (ClassificationNotFoundException | DomainNotFoundException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (ClassificationAlreadyExistException e) {
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(HttpStatus.CONFLICT);
// TODO why is this occuring???
} catch (ConcurrencyException e) {
}
return new ResponseEntity<>(HttpStatus.OK);
}
use of pro.taskana.ClassificationSummary in project taskana by Taskana.
the class ClassificationServiceImplIntExplicitTest method testInsertAndClassificationQuery.
@Test
public void testInsertAndClassificationQuery() throws SQLException, ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification = this.createNewClassificationWithUniqueKey("DOMAIN_A", "TASK");
classificationService.createClassification(classification);
List<ClassificationSummary> list = classificationService.createClassificationQuery().validInDomainEquals(Boolean.TRUE).createdWithin(today()).list();
Assert.assertEquals(1, list.size());
}
Aggregations