TSK-926: Refactor TaskServiceImpl
This commit is contained in:
parent
4049f4d4d7
commit
35ae1ea52f
|
|
@ -180,10 +180,12 @@ public class TaskServiceImpl implements TaskService {
|
|||
TaskImpl task = (TaskImpl) taskToCreate;
|
||||
try {
|
||||
taskanaEngine.openConnection();
|
||||
if (task.getId() != null && !"".equals(task.getId())) {
|
||||
|
||||
if (task.getId() != null && !task.getId().equals("")) {
|
||||
throw new TaskAlreadyExistException(task.getId());
|
||||
} else {
|
||||
LOGGER.debug("Task {} cannot be be found, so it can be created.", task.getId());
|
||||
}
|
||||
|
||||
LOGGER.debug("Task {} cannot be found, so it can be created.", task.getId());
|
||||
Workbasket workbasket;
|
||||
|
||||
if (task.getWorkbasketSummary().getId() != null) {
|
||||
|
|
@ -194,13 +196,12 @@ public class TaskServiceImpl implements TaskService {
|
|||
throw new InvalidArgumentException("Cannot create a task outside a workbasket");
|
||||
}
|
||||
|
||||
if (!workbasket.isMarkedForDeletion()) {
|
||||
task.setWorkbasketSummary(workbasket.asSummary());
|
||||
} else {
|
||||
if (workbasket.isMarkedForDeletion()) {
|
||||
throw new WorkbasketNotFoundException(workbasket.getId(),
|
||||
THE_WORKBASKET + workbasket.getId() + WAS_MARKED_FOR_DELETION);
|
||||
}
|
||||
|
||||
task.setWorkbasketSummary(workbasket.asSummary());
|
||||
task.setDomain(workbasket.getDomain());
|
||||
|
||||
workbasketService.checkAuthorization(task.getWorkbasketSummary().getId(),
|
||||
|
|
@ -246,7 +247,6 @@ public class TaskServiceImpl implements TaskService {
|
|||
}
|
||||
}
|
||||
return task;
|
||||
}
|
||||
} finally {
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from createTask(task = {})", task);
|
||||
|
|
@ -1208,16 +1208,8 @@ public class TaskServiceImpl implements TaskService {
|
|||
newTaskImpl.setClassificationSummary(newClassificationSummary);
|
||||
}
|
||||
|
||||
if (newClassificationSummary.getServiceLevel() != null) {
|
||||
Duration durationFromClassification = Duration.parse(newClassificationSummary.getServiceLevel());
|
||||
Duration minDuration = prioDurationFromAttachments.getDuration();
|
||||
Duration minDuration = calculateDuration(prioDurationFromAttachments, newClassificationSummary);
|
||||
if (minDuration != null) {
|
||||
if (minDuration.compareTo(durationFromClassification) > 0) {
|
||||
minDuration = durationFromClassification;
|
||||
}
|
||||
} else {
|
||||
minDuration = durationFromClassification;
|
||||
}
|
||||
|
||||
long days = converter.convertWorkingDaysToDays(newTaskImpl.getPlanned(), minDuration.toDays());
|
||||
Instant due = newTaskImpl.getPlanned().plus(Duration.ofDays(days));
|
||||
|
|
@ -1238,6 +1230,23 @@ public class TaskServiceImpl implements TaskService {
|
|||
LOGGER.debug("exit from updateTaskPrioDurationFromClassification()");
|
||||
}
|
||||
|
||||
Duration calculateDuration(PrioDurationHolder prioDurationFromAttachments,
|
||||
ClassificationSummary newClassificationSummary) {
|
||||
if (newClassificationSummary.getServiceLevel() == null) {
|
||||
return null;
|
||||
}
|
||||
Duration minDuration = prioDurationFromAttachments.getDuration();
|
||||
Duration durationFromClassification = Duration.parse(newClassificationSummary.getServiceLevel());
|
||||
if (minDuration != null) {
|
||||
if (minDuration.compareTo(durationFromClassification) > 0) {
|
||||
minDuration = durationFromClassification;
|
||||
}
|
||||
} else {
|
||||
minDuration = durationFromClassification;
|
||||
}
|
||||
return minDuration;
|
||||
}
|
||||
|
||||
private PrioDurationHolder handleAttachmentsOnTaskUpdate(TaskImpl oldTaskImpl, TaskImpl newTaskImpl)
|
||||
throws AttachmentPersistenceException {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
|
|
@ -1377,9 +1386,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
PrioDurationHolder prioDuration = new PrioDurationHolder(MAX_DURATION, 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();
|
||||
for (Attachment attachment : task.getAttachments()) {
|
||||
if (attachment != null) {
|
||||
ClassificationSummary classification = attachment.getClassificationSummary();
|
||||
if (classification != null) {
|
||||
|
|
@ -1521,17 +1528,9 @@ public class TaskServiceImpl implements TaskService {
|
|||
private void updateTaskPrioDurationFromClassificationAndAttachments(TaskImpl task,
|
||||
PrioDurationHolder prioDurationFromAttachments, ClassificationSummary classificationSummary) {
|
||||
LOGGER.debug("entry to updateTaskPrioDurationFromClassificationAndAttachments()");
|
||||
if (classificationSummary.getServiceLevel() != null) {
|
||||
Duration durationFromClassification = Duration.parse(classificationSummary.getServiceLevel());
|
||||
Duration minDuration = prioDurationFromAttachments.getDuration();
|
||||
if (minDuration != null) {
|
||||
if (minDuration.compareTo(durationFromClassification) > 0) {
|
||||
minDuration = durationFromClassification;
|
||||
}
|
||||
} else {
|
||||
minDuration = durationFromClassification;
|
||||
}
|
||||
|
||||
Duration minDuration = calculateDuration(prioDurationFromAttachments, classificationSummary);
|
||||
if (minDuration != null) {
|
||||
long days = converter.convertWorkingDaysToDays(task.getPlanned(), minDuration.toDays());
|
||||
Instant due = task.getPlanned().plus(Duration.ofDays(days));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue