ItEr36S07ValidacionEProbasFuncionaisItEr35S08: Fixing bug.
Given a order group with all its children scheduled. If they were unscheduled, a task group still existed. Now it only appears a task.
This commit is contained in:
parent
7cc44e4ca1
commit
7224d9cc1e
2 changed files with 48 additions and 1 deletions
|
|
@ -162,7 +162,13 @@ public abstract class OrderElement extends BaseEntity {
|
|||
taskSource = TaskSource.create(this, getHoursGroups());
|
||||
return TaskSource.mustAdd(taskSource);
|
||||
} else {
|
||||
return taskSource.withCurrentHoursGroup(getHoursGroups());
|
||||
if (taskSource.getTask().isLeaf()) {
|
||||
return taskSource.withCurrentHoursGroup(getHoursGroups());
|
||||
} else {
|
||||
List<TaskSource> toBeRemoved = getTaskSourcesFromBottomToTop();
|
||||
taskSource = TaskSource.create(this, getHoursGroups());
|
||||
return TaskSource.mustReplace(toBeRemoved, taskSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,6 +101,40 @@ public class TaskSource extends BaseEntity {
|
|||
}
|
||||
}
|
||||
|
||||
static class TaskGroupMustBeReplacedByTask extends
|
||||
TaskSourceSynchronization {
|
||||
private final List<TaskSource> toBeRemovedFromBottomToTop;
|
||||
|
||||
private final TaskSource taskSource;
|
||||
|
||||
private TaskGroupMustBeReplacedByTask(
|
||||
List<TaskSource> toBeRemovedFromBottomToTop,
|
||||
TaskSource taskSource) {
|
||||
this.toBeRemovedFromBottomToTop = toBeRemovedFromBottomToTop;
|
||||
this.taskSource = taskSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskElement apply(ITaskSourceDAO taskSourceDAO) {
|
||||
for (TaskSource each : toBeRemovedFromBottomToTop) {
|
||||
remove(taskSourceDAO, each);
|
||||
}
|
||||
taskSourceDAO.flush();
|
||||
// flush must be done to avoid ERROR: duplicate key value
|
||||
// violates unique constraint "tasksource_orderelement_key"
|
||||
return new TaskSourceMustBeAdded(taskSource)
|
||||
.apply(taskSourceDAO);
|
||||
}
|
||||
|
||||
private void remove(ITaskSourceDAO taskSourceDAO, TaskSource each) {
|
||||
try {
|
||||
taskSourceDAO.remove(each.getId());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static abstract class TaskGroupSynchronization extends
|
||||
TaskSourceSynchronization {
|
||||
|
||||
|
|
@ -205,6 +239,13 @@ public class TaskSource extends BaseEntity {
|
|||
return create(new TaskSource(orderElement));
|
||||
}
|
||||
|
||||
public static TaskSourceSynchronization mustReplace(
|
||||
final List<TaskSource> toBeRemovedFromBottomToTop,
|
||||
final TaskSource taskSource) {
|
||||
return new TaskGroupMustBeReplacedByTask(toBeRemovedFromBottomToTop,
|
||||
taskSource);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private OrderElement orderElement;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue