BP-807, fix error if phase is ending between a duration slot
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/PlanningController.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/PlanningController.java
index cdb2ac3..5f2f27f 100644
--- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/PlanningController.java
+++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/PlanningController.java
@@ -190,7 +190,7 @@
} else {
phase++;
LOGGER.debug("Add phase " + phase);
- resultMap.put(phase, new PlanningPhaseDto(tmpDate, tmpDate, lsUserInGroup));
+ resultMap.put(phase, new PlanningPhaseDto(dto.getEndDate(), tmpDate, lsUserInGroup));
}
} else {
LOGGER.debug("Add phase " + phase);
@@ -294,6 +294,7 @@
tmpDate = planningBodyResultDto.getTempDate();
currentPosition = planningBodyResultDto.getNewPosition();
lastStartUserId = planningBodyResultDto.getLastStartUserId();
+ lsPlanningMsg.addAll(planningBodyResultDto.getLsMsg());
}
} catch (Exception e) {
LOGGER.error(e, e);
@@ -495,7 +496,8 @@
if (!lsFittingDurations.isEmpty()) {
for (StandbyDuration fittingDuration : lsFittingDurations) {
- int startWeekDayInt = fittingDuration.getValidDayFrom();
+ // int startWeekDayInt = fittingDuration.getValidDayFrom();
+ int startWeekDayInt = DateHelper.getDayOfWeek(currentDate);
int endWeekDayInt = fittingDuration.getValidDayTo();
int coveredDays = DateHelper.calculateDifferenceOfDays(startWeekDayInt, endWeekDayInt,
fittingDuration.getValidFrom(),
@@ -508,7 +510,7 @@
standbyScheduleBodyRepository.save(stbyBody);
// calculate if holiday
stbyBody = this.calculateHoliday(group, currentDate, stbyBody);
- resultObj.getLsMsg().add(createMsgSavingBody(stbyBody));
+ createMsgSavingBody(stbyBody);
} else {
resultObj = this.calculateMultiScheduleBodyEntries(lsUserInGroup, currentDate, lastDate,
currentPosition, username, fittingDuration, coveredDays);
@@ -525,7 +527,8 @@
} else {
resultObj.setTempDate(DateHelper.addDaysToDate(currentDate, 1));
- // resultObj.getLsMsg().add(this.createMsgNotAvailable(group, currentDate));
+ /** TODO check if existing) */
+ this.createMsgNotAvailable(group, currentDate);
}
return resultObj;
}
@@ -538,19 +541,23 @@
// entries with over night or many days duration
for (int i = 0; i < coveredDays; i++) {
nextDay = DateHelper.addDaysToDate(currentDate, 1);
- if (DateHelper.isDateAfter(nextDay, lastDate)) {
+ if (DateHelper.isDateAfter(nextDay, lastDate) || DateHelper.isSameDate(nextDay, lastDate)) {
StandbyScheduleBody stbyBody = this.createScheduleBodyObject(lsUserInGroup.get(0).getStandbyGroup(),
username, currentDate, lsUserInGroup.get(currentPosition).getUser(), fittingDuration,
TXT_AUTOMATIC_PLANNING);
+
+ if (DateHelper.getDayOfWeek(currentDate) != DateHelper.getDayOfWeek(fittingDuration.getValidFrom())) {
+ // set start of day when it is not the start of the duration
+ stbyBody.setValidFrom(DateHelper.getStartOfDay(currentDate));
+ }
// reset ending date to beginning of next day.
stbyBody.setValidTo(DateHelper.getEndOfDay(currentDate));
standbyScheduleBodyRepository.save(stbyBody);
- resultObj.getLsMsg().add(createMsgSavingBody(stbyBody));
+ createMsgSavingBody(stbyBody);
String warning = "Für das Datum (" + currentDate
+ ") wird der Eintrag nur bis zum Tages-Ende geplant, da der Folgetag den definierten Zeitraum der Phase überschreitet.";
- resultObj.getLsMsg().add(new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN));
- resultObj.setTempDate(nextDay);
+ lsPlanningMsg.add(new PlanningMsgDto(warning, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO));
resultObj.setNewPosition(currentPosition);
return resultObj;
@@ -560,7 +567,7 @@
lsUserInGroup.get(currentPosition).getUser(), fittingDuration, i, coveredDays);
for (StandbyScheduleBody stbyBody : lsScheduleBodies) {
standbyScheduleBodyRepository.save(stbyBody);
- resultObj.getLsMsg().add(createMsgSavingBody(stbyBody));
+ createMsgSavingBody(stbyBody);
resultObj.setTempDate(nextDay);
}
resultObj.setNewPosition(currentPosition);
@@ -618,7 +625,7 @@
*/
protected PlanningMsgDto createMsgNotAvailable(StandbyGroup group, Date currentDate) {
String warning = "Für die Gruppe (" + group.getTitle()
- + ") wurde kein aktiver Zeitraum für folgenden Tag gefunden: (" + currentDate + ")";
+ + ") wurde keine beginnende Duration für folgenden Tag gefunden: (" + currentDate + ")";
LOGGER.warn(warning);
PlanningMsgDto dto = new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN);
lsPlanningMsg.add(dto);
@@ -1419,7 +1426,7 @@
currentDate);
if (lsFittingDurationsEndingAtStart != null && !lsFittingDurationsEndingAtStart.isEmpty()) {
for (StandbyDuration dur : lsFittingDurationsEndingAtStart) {
- int startWeekDayInt = dur.getValidDayFrom();
+ int startWeekDayInt = DateHelper.getDayOfWeek(currentDate);
int endWeekDayInt = dur.getValidDayTo();
int coveredDays = DateHelper.calculateDifferenceOfDays(startWeekDayInt, endWeekDayInt,
dur.getValidFrom(), dur.getValidTo());