TSK-1143 UpdateTask with Planned sometimes fails

This commit is contained in:
BerndBreier 2020-02-28 10:45:51 +01:00
parent fa429cef97
commit c2d974b02e
2 changed files with 37 additions and 14 deletions

View File

@ -79,7 +79,7 @@ public class AttachmentHandler {
}
void insertAndDeleteAttachmentsOnTaskUpdate(TaskImpl newTaskImpl, TaskImpl oldTaskImpl)
throws InvalidArgumentException, AttachmentPersistenceException {
throws AttachmentPersistenceException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"entry to insertAndDeleteAttachmentsOnTaskUpdate(oldTaskImpl = {}, newTaskImpl = {})",
@ -122,34 +122,27 @@ public class AttachmentHandler {
}
void insertNewAttachmentsOnTaskUpdate(TaskImpl newTaskImpl, TaskImpl oldTaskImpl)
throws InvalidArgumentException, AttachmentPersistenceException {
throws AttachmentPersistenceException {
List<String> oldAttachmentIds =
oldTaskImpl.getAttachments().stream()
.map(AttachmentSummary::getId)
.collect(Collectors.toList());
List<InvalidArgumentException> invalidArgumentExceptions = new ArrayList<>();
List<AttachmentPersistenceException> attachmentPersistenceExceptions = new ArrayList<>();
List<AttachmentPersistenceException> exceptions = new ArrayList<>();
newTaskImpl
.getAttachments()
.forEach(
a -> {
if (!oldAttachmentIds.contains(a.getId())) {
try {
initializeAndInsertAttachment(newTaskImpl, (AttachmentImpl) a);
} catch (InvalidArgumentException excpt) {
invalidArgumentExceptions.add(excpt);
LOGGER.warn("attempted to insert attachment {} and caught exception", a, excpt);
insertNewAttachmentOnTaskUpdate(newTaskImpl, a);
} catch (AttachmentPersistenceException excpt) {
attachmentPersistenceExceptions.add(excpt);
exceptions.add(excpt);
LOGGER.warn("attempted to insert attachment {} and caught exception", a, excpt);
}
}
});
if (!invalidArgumentExceptions.isEmpty()) {
throw invalidArgumentExceptions.get(0);
}
if (!attachmentPersistenceExceptions.isEmpty()) {
throw attachmentPersistenceExceptions.get(0);
if (!exceptions.isEmpty()) {
throw exceptions.get(0);
}
}
@ -195,6 +188,30 @@ public class AttachmentHandler {
LOGGER.debug("exit from deleteRemovedAttachmentsOnTaskUpdate()");
}
void insertNewAttachmentOnTaskUpdate(TaskImpl newTaskImpl, Attachment attachment)
throws AttachmentPersistenceException {
LOGGER.debug("entry to insertNewAttachmentOnTaskUpdate()");
AttachmentImpl attachmentImpl = (AttachmentImpl) attachment;
initAttachment(attachmentImpl, newTaskImpl);
try {
attachmentMapper.insert(attachmentImpl);
LOGGER.debug(
"TaskService.updateTask() for TaskId={} INSERTED an Attachment={}.",
newTaskImpl.getId(),
attachmentImpl);
} catch (PersistenceException e) {
throw new AttachmentPersistenceException(
"Cannot insert the Attachement "
+ attachmentImpl.getId()
+ " for Task "
+ newTaskImpl.getId()
+ " because it already exists.",
e.getCause());
}
LOGGER.debug("exit from insertNewAttachmentOnTaskUpdate(), returning");
}
void initAttachment(AttachmentImpl attachment, Task newTask) {
LOGGER.debug("entry to initAttachment()");
if (attachment.getId() == null) {

View File

@ -1635,6 +1635,7 @@ public class TaskServiceImpl implements TaskService {
private void standardUpdateActions(TaskImpl oldTaskImpl, TaskImpl newTaskImpl)
throws InvalidArgumentException, InvalidStateException, ClassificationNotFoundException {
if (oldTaskImpl.getExternalId() == null
|| !(oldTaskImpl.getExternalId().equals(newTaskImpl.getExternalId()))) {
throw new InvalidArgumentException(
@ -1647,6 +1648,10 @@ public class TaskServiceImpl implements TaskService {
"A task's Workbasket cannot be changed via update of the task");
}
if (newTaskImpl.getClassificationSummary() == null) {
newTaskImpl.setClassificationSummary(oldTaskImpl.getClassificationSummary());
}
updateClassificationSummary(newTaskImpl, oldTaskImpl);
newTaskImpl = serviceLevelHandler.updatePrioPlannedDueOfTask(newTaskImpl, oldTaskImpl, false);
@ -1662,6 +1667,7 @@ public class TaskServiceImpl implements TaskService {
throw new InvalidStateException(
String.format(TASK_WITH_ID_IS_NOT_READY, oldTaskImpl.getId(), oldTaskImpl.getState()));
}
}
private void updateClassificationSummary(TaskImpl newTaskImpl, TaskImpl oldTaskImpl)