TSK-1752: fixed calculation in TestPriorityServiceProvider
This commit is contained in:
parent
2b4c87f495
commit
cbf02e55d4
|
@ -15,18 +15,25 @@ import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
|||
|
||||
public class WorkingTimeCalculator {
|
||||
|
||||
private static final Map<DayOfWeek, LocalTimeInterval> WORKING_TIME =
|
||||
new HashMap<DayOfWeek, LocalTimeInterval>() {
|
||||
{
|
||||
put(DayOfWeek.MONDAY, new LocalTimeInterval(LocalTime.of(9, 0), LocalTime.of(17, 0)));
|
||||
put(DayOfWeek.TUESDAY, new LocalTimeInterval(LocalTime.of(9, 0), LocalTime.of(17, 0)));
|
||||
put(DayOfWeek.WEDNESDAY, new LocalTimeInterval(LocalTime.of(9, 0), LocalTime.of(17, 0)));
|
||||
put(DayOfWeek.THURSDAY, new LocalTimeInterval(LocalTime.of(9, 0), LocalTime.of(17, 0)));
|
||||
put(DayOfWeek.FRIDAY, new LocalTimeInterval(LocalTime.of(9, 0), LocalTime.of(17, 0)));
|
||||
put(DayOfWeek.SATURDAY, new LocalTimeInterval(LocalTime.of(10, 0), LocalTime.of(15, 0)));
|
||||
put(DayOfWeek.SUNDAY, null);
|
||||
}
|
||||
};
|
||||
private static final Map<DayOfWeek, LocalTimeInterval> WORKING_TIME;
|
||||
|
||||
static {
|
||||
WORKING_TIME = new HashMap<>();
|
||||
WORKING_TIME.put(
|
||||
DayOfWeek.MONDAY, new LocalTimeInterval(LocalTime.of(9, 0), LocalTime.of(17, 0)));
|
||||
WORKING_TIME.put(
|
||||
DayOfWeek.TUESDAY, new LocalTimeInterval(LocalTime.of(9, 0), LocalTime.of(17, 0)));
|
||||
WORKING_TIME.put(
|
||||
DayOfWeek.WEDNESDAY, new LocalTimeInterval(LocalTime.of(9, 0), LocalTime.of(17, 0)));
|
||||
WORKING_TIME.put(
|
||||
DayOfWeek.THURSDAY, new LocalTimeInterval(LocalTime.of(9, 0), LocalTime.of(17, 0)));
|
||||
WORKING_TIME.put(
|
||||
DayOfWeek.FRIDAY, new LocalTimeInterval(LocalTime.of(9, 0), LocalTime.of(17, 0)));
|
||||
WORKING_TIME.put(
|
||||
DayOfWeek.SATURDAY, new LocalTimeInterval(LocalTime.of(10, 0), LocalTime.of(15, 0)));
|
||||
WORKING_TIME.put(DayOfWeek.SUNDAY, null);
|
||||
}
|
||||
|
||||
private final ZoneId zone;
|
||||
private final WorkingDaysToDaysConverter converter;
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.util.OptionalInt;
|
|||
|
||||
import pro.taskana.common.api.WorkingDaysToDaysConverter;
|
||||
import pro.taskana.common.api.WorkingTimeCalculator;
|
||||
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.spi.priority.api.PriorityServiceProvider;
|
||||
import pro.taskana.task.api.TaskCustomField;
|
||||
import pro.taskana.task.api.models.TaskSummary;
|
||||
|
@ -14,27 +13,27 @@ import pro.taskana.task.api.models.TaskSummary;
|
|||
public class TestPriorityServiceProvider implements PriorityServiceProvider {
|
||||
private static final int MULTIPLIER = 10;
|
||||
|
||||
private final WorkingDaysToDaysConverter converter = new WorkingDaysToDaysConverter(true, true);
|
||||
private final WorkingTimeCalculator calculator = new WorkingTimeCalculator(converter);
|
||||
|
||||
@Override
|
||||
public OptionalInt calculatePriority(TaskSummary taskSummary) {
|
||||
WorkingDaysToDaysConverter converter = new WorkingDaysToDaysConverter(true, true);
|
||||
WorkingTimeCalculator calculator = new WorkingTimeCalculator(converter);
|
||||
int priority;
|
||||
|
||||
long priority;
|
||||
try {
|
||||
priority =
|
||||
Math.toIntExact(
|
||||
calculator
|
||||
.workingTimeBetweenTwoTimestamps(taskSummary.getCreated(), Instant.now())
|
||||
.toMinutes())
|
||||
calculator
|
||||
.workingTimeBetweenTwoTimestamps(taskSummary.getCreated(), Instant.now())
|
||||
.toMinutes()
|
||||
+ 1;
|
||||
} catch (InvalidArgumentException | ArithmeticException e) {
|
||||
long diffInDays = Duration.between(taskSummary.getCreated(), Instant.now()).toDays();
|
||||
priority = diffInDays >= 1 ? Math.toIntExact(diffInDays) : 1;
|
||||
|
||||
if ("true".equals(taskSummary.getCustomAttribute(TaskCustomField.CUSTOM_6))) {
|
||||
priority *= MULTIPLIER;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
priority = Duration.between(taskSummary.getCreated(), Instant.now()).toMinutes();
|
||||
}
|
||||
|
||||
return OptionalInt.of(priority);
|
||||
if (Boolean.parseBoolean(taskSummary.getCustomAttribute(TaskCustomField.CUSTOM_6))) {
|
||||
priority *= MULTIPLIER;
|
||||
}
|
||||
|
||||
return OptionalInt.of(Math.toIntExact(priority));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue