BP-755, change validation of available user
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/BodyDataCopyController.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/BodyDataCopyController.java
index eb4af81..6d85ab7 100644
--- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/BodyDataCopyController.java
+++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/BodyDataCopyController.java
@@ -148,7 +148,7 @@
 			responseDto.getLsMsg()
 					.addAll(validationController.startValidation(standbyScheduleCopyDto.getValidFrom(),
 							standbyScheduleCopyDto.getValidTo(), lsGroupsForValidation, validationBeanNames,
-							targetStatus.getId()));
+							targetStatus.getId(), null));
 		} catch (SpException e) {
 			LOGGER.error(e, e);
 			throw e;
@@ -392,8 +392,10 @@
 			validationBeanNames.add(ValidationController.BEAN_DOUBLE_PLANNED_VALIDATOR);
 			validationBeanNames.add(ValidationController.BEAN_PLACEHOLDER_STANDBY_USER_VALIDATOR);
 
-			responseDto.getLsMsg().addAll(validationController.startValidation(standbyScheduleCopyDto.getValidFrom(),
-					standbyScheduleCopyDto.getValidTo(), lsGroupsForValidation, validationBeanNames, status.getId()));
+			responseDto.getLsMsg()
+					.addAll(validationController.startValidation(standbyScheduleCopyDto.getValidFrom(),
+							standbyScheduleCopyDto.getValidTo(), lsGroupsForValidation, validationBeanNames,
+							status.getId(), null));
 		} catch (SpException e) {
 			LOGGER.error(e, e);
 			throw e;
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 de2ed9e..40848e5 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
@@ -1,1290 +1,1290 @@
-/********************************************************************************
- * Copyright (c) 2018 Mettenmeier GmbH 
- *
- * See the NOTICE file(s) distributed with this work for additional 
- * information regarding copyright ownership.
- *
- * This program and the accompanying materials are made available under the 
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0 
- ********************************************************************************/
-package org.eclipse.openk.sp.controller.planning;
-
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.log4j.Logger;
-import org.eclipse.openk.sp.controller.AbstractController;
-import org.eclipse.openk.sp.controller.validation.ValidationController;
-import org.eclipse.openk.sp.db.dao.CalendarRepository;
-import org.eclipse.openk.sp.db.dao.StandbyDurationRepository;
-import org.eclipse.openk.sp.db.dao.StandbyGroupRepository;
-import org.eclipse.openk.sp.db.dao.StandbyListRepository;
-import org.eclipse.openk.sp.db.dao.StandbyScheduleBodyRepository;
-import org.eclipse.openk.sp.db.dao.StandbyStatusRepository;
-import org.eclipse.openk.sp.db.dao.UserInStandbyGroupRepository;
-import org.eclipse.openk.sp.db.dao.UserRepository;
-import org.eclipse.openk.sp.db.model.CalendarDay;
-import org.eclipse.openk.sp.db.model.StandbyDuration;
-import org.eclipse.openk.sp.db.model.StandbyGroup;
-import org.eclipse.openk.sp.db.model.StandbyScheduleBody;
-import org.eclipse.openk.sp.db.model.User;
-import org.eclipse.openk.sp.db.model.UserInStandbyGroup;
-import org.eclipse.openk.sp.dto.StandbyScheduleBlueprintDto;
-import org.eclipse.openk.sp.dto.planning.PlanningBodyResultDto;
-import org.eclipse.openk.sp.dto.planning.PlanningMsgDto;
-import org.eclipse.openk.sp.dto.planning.PlanningMsgResponseDto;
-import org.eclipse.openk.sp.dto.planning.PlanningPhaseDto;
-import org.eclipse.openk.sp.dto.planning.StandbyScheduleActionDto;
-import org.eclipse.openk.sp.exceptions.SpErrorEntry;
-import org.eclipse.openk.sp.exceptions.SpException;
-import org.eclipse.openk.sp.exceptions.SpExceptionEnum;
-import org.eclipse.openk.sp.mail.MailRequest;
-import org.eclipse.openk.sp.util.DateHelper;
-import org.eclipse.openk.sp.util.SpMsg;
-import org.eclipse.openk.sp.util.ValidationHelper;
-import org.joda.time.DateTime;
-import org.joda.time.Interval;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-@Service
-@Transactional(rollbackFor = Exception.class)
-/** Class to handle planning operations. */
-public class PlanningController extends AbstractController {
-	protected static final Logger LOGGER = Logger.getLogger(PlanningController.class);
-	public static final String TXT_AUTOMATIC_PLANNING = "autom. Planung";
-	public static final String TXT_AUTOMATIC_PLANNING_HOLIDAY = "autom. Planung (Dienstfrei)";
-	public static final String TXT_AUTOMATIC_CHANGE = "autom. Änderung";
-	public static final String TXT_MANUAL_CHANGE = "manuelle Änderung";
-
-	@Autowired
-	private StandbyGroupRepository standbyGroupRepository;
-
-	@Autowired
-	private StandbyListRepository standbyListRepository;
-
-	@Autowired
-	private StandbyDurationRepository standbyDurationRepository;
-
-	@Autowired
-	private StandbyStatusRepository standbyStatusRepository;
-
-	@Autowired
-	private ArchiveController archiveController;
-
-	@Autowired
-	private StandbyScheduleBodyRepository standbyScheduleBodyRepository;
-
-	@Autowired
-	private UserInStandbyGroupRepository uisgRepository;
-
-	@Autowired
-	private UserRepository userRepository;
-
-	@Autowired
-	private CalendarRepository calendarRepository;
-
-	@Autowired
-	private ValidationController validatonController;
-
-	@Autowired
-	private MailRequest mailing;
-
-	private List<PlanningMsgDto> lsPlanningMsg = new ArrayList<>();
-
-	public PlanningMsgResponseDto startPlanning(StandbyScheduleBlueprintDto standbyBlueprintDto, String username)
-			throws SpException {
-		PlanningMsgResponseDto responseDto = new PlanningMsgResponseDto();
-		try {
-			lsPlanningMsg = new ArrayList<>();
-			// check if input is valid
-			if (this.validateInputForPlanCalculation(standbyBlueprintDto)) {
-				standbyBlueprintDto.setValidTo(DateHelper.getEndOfDay(standbyBlueprintDto.getValidTo()));
-				// calculate the different phases.
-				Map<Integer, PlanningPhaseDto> planningPhaseMap = this.calculatePlanningPhaseMap(standbyBlueprintDto);
-				this.createMsgNumberOfPhases(planningPhaseMap, standbyBlueprintDto);
-
-				Long lastStartUserId = standbyBlueprintDto.getStartIdOfUser();
-				// loop over planning phases
-				for (Entry<Integer, PlanningPhaseDto> entry : planningPhaseMap.entrySet()) {
-					LOGGER.debug("Start Plannig for phase " + entry.getKey());
-					PlanningPhaseDto dto = entry.getValue();
-					this.createMsgStartOfPhase(entry.getKey(), dto);
-					this.calculatePlanForPhase(dto, lastStartUserId, username);
-					this.createMsgEndOfPhase(entry.getKey());
-					LOGGER.debug("End Plannig for phase " + entry.getKey());
-				}
-
-				standbyScheduleBodyRepository.flush();
-
-				// start validation
-				List<String> lsValidationBeanNames = new ArrayList<>();
-				lsValidationBeanNames.add(ValidationController.BEAN_GROUP_COVERAGE_VALIDATOR);
-				lsValidationBeanNames.add(ValidationController.BEAN_DOUBLE_PLANNED_VALIDATOR);
-				lsValidationBeanNames.add(ValidationController.BEAN_PLACEHOLDER_STANDBY_USER_VALIDATOR);
-
-				List<StandbyGroup> lsStandbyGroups = new ArrayList<>();
-				lsStandbyGroups.add(standbyGroupRepository.findOne(standbyBlueprintDto.getStandbyGroupId()));
-
-				lsPlanningMsg.addAll(validatonController.startValidation(standbyBlueprintDto.getValidFrom(),
-						standbyBlueprintDto.getValidTo(), lsStandbyGroups, lsValidationBeanNames,
-						standbyBlueprintDto.getStatusId()));
-				responseDto.setLsMsg(lsPlanningMsg);
-			}
-			return responseDto;
-		} catch (SpException e) {
-			LOGGER.error(e, e);
-			throw e;
-		} catch (Exception e) {
-			LOGGER.error(e, e);
-			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();
-			ee.setE(e);
-			throw new SpException(ee);
-		}
-	}
-
-	/**
-	 * Method to calculate the different phases for changing groups.
-	 * 
-	 * @param standbyBlueprintDto
-	 * @return
-	 * @throws SpException
-	 */
-	public Map<Integer, PlanningPhaseDto> calculatePlanningPhaseMap(StandbyScheduleBlueprintDto standbyBlueprintDto)
-			throws SpException {
-		Map<Integer, PlanningPhaseDto> resultMap = new HashMap<>();
-		try {
-			Date validFrom = standbyBlueprintDto.getValidFrom();
-			Date validTo = DateHelper.getEndOfDay(standbyBlueprintDto.getValidTo());
-			Date tmpDate = validFrom;
-			int phase = 1;
-
-			while (tmpDate.getTime() <= validTo.getTime()) {
-				List<UserInStandbyGroup> lsUserInGroup = uisgRepository
-						.findUserForInterval(standbyBlueprintDto.getStandbyGroupId(), tmpDate, tmpDate);
-				if (lsUserInGroup != null && !lsUserInGroup.isEmpty()) {
-					if (resultMap.containsKey(phase)) {
-						PlanningPhaseDto dto = resultMap.get(phase);
-						if (CollectionUtils.isEqualCollection(dto.getLsUsers(), lsUserInGroup)) {
-							dto.setEndDate(DateHelper.addDaysToDate(dto.getEndDate(), 1));
-						} else {
-							phase++;
-							LOGGER.debug("Add phase " + phase);
-							resultMap.put(phase, new PlanningPhaseDto(tmpDate, tmpDate, lsUserInGroup));
-						}
-					} else {
-						LOGGER.debug("Add phase " + phase);
-						resultMap.put(phase, new PlanningPhaseDto(tmpDate, tmpDate, lsUserInGroup));
-					}
-				}
-				tmpDate = DateHelper.addDaysToDate(tmpDate, 1);
-			}
-			this.logPhases(resultMap);
-			return resultMap;
-		} catch (Exception e) {
-			LOGGER.error(e, e);
-			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();
-			ee.setE(e);
-			throw new SpException(ee);
-		}
-
-	}
-
-	public void changeOrDeleteAtIntervalStart(StandbyScheduleBody body, StandbyDuration duration, Date tmpDate,
-			String username) {
-		if (duration != null) {
-			Date durationStart = DateHelper.getDateWithTime(tmpDate, duration.getValidFrom());
-			if (DateHelper.isDateBefore(body.getValidFrom(), durationStart)) {
-				if (DateHelper.isDateAfter(body.getValidTo(), durationStart)) {
-					body.setValidTo(durationStart);
-					body.setModificationDate(new Date());
-					body.setModifiedCause(TXT_AUTOMATIC_CHANGE);
-					body.setModifiedCause(username);
-					standbyScheduleBodyRepository.save(body);
-				}
-			} else {
-				standbyScheduleBodyRepository.delete(body);
-			}
-		}
-	}
-
-	public void changeOrDeleteAtIntervalEnd(StandbyScheduleBody body, StandbyDuration duration, Date tmpDate,
-			String username) {
-		if (duration != null) {
-			Date durationEnd = DateHelper.getDateWithTime(tmpDate, duration.getValidTo());
-			if (DateHelper.isDateBefore(body.getValidFrom(), durationEnd)) {
-				if (DateHelper.isDateAfter(body.getValidTo(), durationEnd)) {
-					body.setValidTo(durationEnd);
-					body.setModificationDate(new Date());
-					body.setModifiedCause(TXT_AUTOMATIC_CHANGE);
-					body.setModifiedCause(username);
-					standbyScheduleBodyRepository.save(body);
-				}
-			} else {
-				standbyScheduleBodyRepository.delete(body);
-			}
-		}
-	}
-
-	public void changeOrDeleteExistingBodies(StandbyGroup group, Date startDate, Date endDate, Long statusId,
-			String username) {
-		Date tmpDate = startDate;
-		while (tmpDate.getTime() <= endDate.getTime()) {
-			List<StandbyScheduleBody> lsBodies = standbyScheduleBodyRepository
-					.findByGroupAndStatusHittingDateInterval(group.getId(), tmpDate, endDate, statusId);
-
-			List<StandbyDuration> lsFittingDurations = this.getFittingDurationsOfGroup(group, tmpDate);
-			StandbyDuration duration = null;
-			if (lsFittingDurations != null && !lsFittingDurations.isEmpty()) {
-				duration = lsFittingDurations.get(0);
-			}
-			for (StandbyScheduleBody body : lsBodies) {
-				if (tmpDate.getTime() == startDate.getTime()) {
-					this.changeOrDeleteAtIntervalStart(body, duration, tmpDate, username);
-				} else if (tmpDate.getTime() == endDate.getTime()) {
-					this.changeOrDeleteAtIntervalEnd(body, duration, tmpDate, username);
-				} else {
-					standbyScheduleBodyRepository.delete(body);
-				}
-			}
-			tmpDate = DateHelper.addDaysToDate(tmpDate, 1);
-		}
-
-	}
-
-	public void calculatePlanForPhase(PlanningPhaseDto dto, Long lastStartUserId, String username) throws SpException {
-		try {
-			List<UserInStandbyGroup> lsUserInGroup = dto.getLsUsers();
-
-			Collections.sort(lsUserInGroup,
-					(UserInStandbyGroup o1, UserInStandbyGroup o2) -> o1.getPosition().compareTo(o2.getPosition()));
-
-			int currentPosition = this.getIndexOfLastPlannedUser(lastStartUserId, lsUserInGroup);
-			if (currentPosition == -1) {
-				this.createMsgGroupLeaderChanged(userRepository.findOne(lastStartUserId), lsUserInGroup);
-				currentPosition = 0;
-			}
-			Date tmpDate = dto.getStartDate();
-
-			this.changeOrDeleteExistingBodies(lsUserInGroup.get(0).getStandbyGroup(), dto.getStartDate(),
-					dto.getEndDate(), 1L, username);
-			while (tmpDate.getTime() <= dto.getEndDate().getTime()) {
-
-				// reset position if end of list has been reached
-				PlanningBodyResultDto planningBodyResultDto = this.calculateScheduleBodyEntries(lsUserInGroup, tmpDate,
-						dto.getEndDate(), currentPosition, username, lastStartUserId);
-				tmpDate = planningBodyResultDto.getTempDate();
-				currentPosition = planningBodyResultDto.getNewPosition();
-			}
-		} catch (Exception e) {
-			LOGGER.error(e, e);
-			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();
-			ee.setE(e);
-			throw new SpException(ee);
-		}
-	}
-
-	/**
-	 * Method to create a simple {@link StandbyScheduleBody} object with input
-	 * values for planning.
-	 * 
-	 * @param group
-	 * @param username
-	 * @param date
-	 * @param user
-	 * @param duration
-	 * @return
-	 */
-	public StandbyScheduleBody createScheduleBodyObject(StandbyGroup group, String username, Date date, User user,
-			StandbyDuration duration, String cause) {
-		StandbyScheduleBody stbyBody = new StandbyScheduleBody();
-		stbyBody.setModificationDate(new Date());
-		stbyBody.setModifiedBy(username);
-		stbyBody.setModifiedCause(cause);
-		stbyBody.setStandbyGroup(group);
-		stbyBody.setUser(user);
-		stbyBody.setStatus(standbyStatusRepository.findOne(1l));
-		stbyBody.setValidFrom(DateHelper.getDateWithTime(date, duration.getValidFrom()));
-		stbyBody.setValidTo(DateHelper.getDateWithTime(date, duration.getValidTo()));
-		return stbyBody;
-	}
-
-	public List<StandbyScheduleBody> createOverlappingScheduleBodyObjects(StandbyGroup group, String username,
-			Date date, User user, StandbyDuration duration, int loopPos, int loopLength) {
-		List<StandbyScheduleBody> lsStandbyScheduleBodies = new ArrayList<>();
-		StandbyScheduleBody stbyBody = this.createScheduleBodyObject(group, username, date, user, duration,
-				TXT_AUTOMATIC_PLANNING);
-		if (loopPos > 0) {
-			// if not the first loop the schedule body should start at the begin of the day.
-			stbyBody.setValidFrom(DateHelper.getDateWithTime(date, DateHelper.getStartOfDay(duration.getValidFrom())));
-		}
-		Date validTo = DateHelper.getDateWithTime(date, duration.getValidTo());
-		validTo = DateHelper.getEndOfDay(validTo);
-		stbyBody.setValidTo(validTo);
-
-		stbyBody = this.calculateHoliday(group, date, stbyBody);
-
-		lsStandbyScheduleBodies.add(stbyBody);
-		if (loopPos + 1 == loopLength) {
-			// if last entry use end time of duration
-			StandbyScheduleBody stbyBody2 = null;
-			stbyBody2 = this.createScheduleBodyObject(group, username, date, user, duration, TXT_AUTOMATIC_PLANNING);
-			Date nextDay = DateHelper.addDaysToDate(date, 1);
-			Date validFrom = DateHelper.getDateWithTime(DateHelper.addDaysToDate(date, 1),
-					DateHelper.getStartOfDay(duration.getValidFrom()));
-			stbyBody2.setValidFrom(validFrom);
-			validTo = DateHelper.getDateWithTime(nextDay, duration.getValidTo());
-			stbyBody2.setValidTo(validTo);
-			this.calculateHoliday(group, nextDay, stbyBody2);
-			lsStandbyScheduleBodies.add(stbyBody2);
-		}
-
-		return lsStandbyScheduleBodies;
-	}
-
-	/**
-	 * Method to check if the current day is a holiday for the standby group and
-	 * calls the pre-draw or extend calculation.
-	 * 
-	 * @param group
-	 * @param date
-	 * @param stbyBody
-	 * @return
-	 */
-	public StandbyScheduleBody calculateHoliday(StandbyGroup group, Date date, StandbyScheduleBody stbyBody) {
-		if (isHoliday(date, group)) {
-			if (group.getExtendStandbyTime()) {
-				// if extend of standby time is needed
-				stbyBody = this.calculateHolidayExtend(group, date, stbyBody);
-			} else {
-				// is pre-draw of standby time needed
-				stbyBody = this.calculateHolidayPreDraw(group, date, stbyBody);
-			}
-		}
-		return stbyBody;
-	}
-
-	/**
-	 * Method to change the standby time if a holiday / calendar day is defined and
-	 * the standby time has to be pre-drawn.
-	 * 
-	 * @param group
-	 * @param date
-	 * @param stbyBody
-	 * @return
-	 */
-	public StandbyScheduleBody calculateHolidayPreDraw(StandbyGroup group, Date date, StandbyScheduleBody stbyBody) {
-
-		List<StandbyDuration> lsDurations = this.getFittingDurationsByValidTo(group, date);
-		if (lsDurations != null) {
-			int size = lsDurations.size();
-			// loop backward to find last fitting duration
-			for (int a = size; a > 0; a--) {
-				StandbyDuration dur = lsDurations.get(a - 1);
-				// proof if found duration ends before current body starts.
-				if (dur != null && DateHelper.isDateBefore(DateHelper.getDateWithTime(date, dur.getValidTo()),
-						stbyBody.getValidFrom())) {
-					// set last found duration end as start of current entry
-					stbyBody.setValidFrom(DateHelper.getDateWithTime(date, dur.getValidTo()));
-					this.createMsgExtendHoliday(stbyBody, date, false);
-					// end loop after first fitting result.
-					stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);
-					return stbyBody;
-				}
-			}
-			// no last duration for the day has been found. Therefore the start of day has
-			// been used for current entry
-			if (DateHelper.isDateBefore(DateHelper.getStartOfDay(date), stbyBody.getValidFrom())) {
-				stbyBody.setValidFrom(DateHelper.getDateWithTime(date, DateHelper.getStartOfDay(date)));
-				this.createMsgExtendHoliday(stbyBody, date, false);
-				stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);
-			}
-		} else {
-			// no last duration for the day has been found. Therefore the start of day has
-			// been used for current entry
-			if (DateHelper.isDateBefore(DateHelper.getStartOfDay(date), stbyBody.getValidFrom())) {
-				stbyBody.setValidFrom(DateHelper.getDateWithTime(date, DateHelper.getStartOfDay(date)));
-				this.createMsgExtendHoliday(stbyBody, date, false);
-				stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);
-			}
-		}
-
-		return stbyBody;
-	}
-
-	/**
-	 * Method to change the standby time if a holiday / calendar day is defined and
-	 * the standby time has to be extended.
-	 * 
-	 * @param group
-	 * @param date
-	 * @param stbyBody
-	 * @return
-	 */
-	public StandbyScheduleBody calculateHolidayExtend(StandbyGroup group, Date date, StandbyScheduleBody stbyBody) {
-		List<StandbyDuration> lsDurations = this.getFittingDurationsOfGroup(group, date);
-		if (lsDurations != null) {
-			int size = lsDurations.size();
-			// loop forward to find fitting duration that starts after current schedule body
-			for (int a = 0; a < size; a++) {
-				StandbyDuration dur = lsDurations.get(a);
-				// proof if found duration starts after the end of current body.
-				if (dur != null && DateHelper.isDateAfter(DateHelper.getDateWithTime(date, dur.getValidFrom()),
-						stbyBody.getValidTo())) {
-					// set end time of current entry to the start of the next duration
-					stbyBody.setValidTo(DateHelper.getDateWithTime(date, dur.getValidFrom()));
-					stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);
-					this.createMsgExtendHoliday(stbyBody, date, true);
-					// end loop after first fitting result.
-					return stbyBody;
-				}
-			}
-			// no last duration for the day has been found. Therefore the start of day has
-			// been used for current entry
-			if (DateHelper.isDateAfter(DateHelper.getEndOfDay(date), stbyBody.getValidTo())) {
-				stbyBody.setValidTo(DateHelper.getDateWithTime(date, DateHelper.getEndOfDay(date)));
-				stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);
-				this.createMsgExtendHoliday(stbyBody, date, true);
-			}
-		} else {
-			// no last duration for the day has been found. Therefore the start of day has
-			// been used for current entry
-			if (DateHelper.isDateAfter(DateHelper.getEndOfDay(date), stbyBody.getValidTo())) {
-				stbyBody.setValidTo(DateHelper.getDateWithTime(date, DateHelper.getEndOfDay(date)));
-				stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);
-				this.createMsgExtendHoliday(stbyBody, date, true);
-			}
-		}
-		return stbyBody;
-	}
-
-	public PlanningBodyResultDto calculateScheduleBodyEntries(List<UserInStandbyGroup> lsUserInGroup, Date currentDate,
-			Date lastDate, int currentPosition, String username, Long lastStartUserId) {
-		StandbyGroup group = lsUserInGroup.get(0).getStandbyGroup();
-		PlanningBodyResultDto resultObj = new PlanningBodyResultDto();
-		List<StandbyDuration> lsFittingDurations = this.getFittingDurationsOfGroup(group, currentDate);
-
-		if (lsFittingDurations != null) {
-			for (StandbyDuration fittingDuration : lsFittingDurations) {
-				int startWeekDayInt = fittingDuration.getValidDayFrom();
-				int endWeekDayInt = fittingDuration.getValidDayTo();
-				int coveredDays = DateHelper.calculateDifferenceOfDays(startWeekDayInt, endWeekDayInt,
-						fittingDuration.getValidFrom(), fittingDuration.getValidTo());
-				if (coveredDays == 0) {
-					// single entry with no over night duration
-					LOGGER.debug("A day was found that just cover a single day.");
-					StandbyScheduleBody stbyBody = this.createScheduleBodyObject(group, username, currentDate,
-							lsUserInGroup.get(currentPosition).getUser(), fittingDuration, TXT_AUTOMATIC_PLANNING);
-					standbyScheduleBodyRepository.save(stbyBody);
-					// calculate if holiday
-					stbyBody = this.calculateHoliday(group, currentDate, stbyBody);
-					resultObj.getLsMsg().add(createMsgSavingBody(stbyBody));
-				} else {
-					resultObj = this.calculateMultiScheduleBodyEntries(lsUserInGroup, currentDate, lastDate,
-							currentPosition, username, fittingDuration, coveredDays);
-				}
-				resultObj.setCurrentDuration(fittingDuration);
-				currentPosition = this
-						.resetCounterToNewPosition(currentPosition, lastStartUserId, lsUserInGroup,
-								group.getNextUserInNextCycle(), fittingDuration.getNextUserInNextDuration())
-						.getNewPosition();
-			}
-			resultObj.setNewPosition(currentPosition);
-			resultObj.setTempDate(DateHelper.addDaysToDate(currentDate, 1));
-		} else {
-			resultObj.setTempDate(DateHelper.addDaysToDate(currentDate, 1));
-			resultObj.getLsMsg().add(this.createMsgNotAvailable(group, currentDate));
-		}
-		return resultObj;
-	}
-
-	public PlanningBodyResultDto calculateMultiScheduleBodyEntries(List<UserInStandbyGroup> lsUserInGroup,
-			Date currentDate, Date lastDate, int currentPosition, String username, StandbyDuration fittingDuration,
-			int coveredDays) {
-		PlanningBodyResultDto resultObj = new PlanningBodyResultDto();
-		Date nextDay = null;
-		// 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)) {
-				String warning = "Für das Datum (" + currentDate
-						+ ") wird kein Eintrag erzeugt, da der Folgetag den definierten Zeitraum überschereitet.";
-				resultObj.getLsMsg().add(new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN));
-				resultObj.setTempDate(nextDay);
-				resultObj.setNewPosition(currentPosition);
-				return resultObj;
-			} else {
-				List<StandbyScheduleBody> lsScheduleBodies = this.createOverlappingScheduleBodyObjects(
-						lsUserInGroup.get(0).getStandbyGroup(), username, currentDate,
-						lsUserInGroup.get(currentPosition).getUser(), fittingDuration, i, coveredDays);
-				for (StandbyScheduleBody stbyBody : lsScheduleBodies) {
-					standbyScheduleBodyRepository.save(stbyBody);
-					resultObj.getLsMsg().add(createMsgSavingBody(stbyBody));
-					resultObj.setTempDate(nextDay);
-				}
-				resultObj.setNewPosition(currentPosition);
-				resultObj.setTempDate(nextDay);
-				currentDate = resultObj.getTempDate();
-			}
-		}
-		return resultObj;
-	}
-
-	/**
-	 * Method to create a success message for saving an {@link StandbyScheduleBody}
-	 * object.
-	 * 
-	 * @param stbyBody
-	 * @return
-	 */
-	protected PlanningMsgDto createMsgSavingBody(StandbyScheduleBody stbyBody) {
-		String info = stbyBody.getUser().getFirstname() + " " + stbyBody.getUser().getLastname()
-				+ " wurde für den Zeitraum vom (" + stbyBody.getValidFrom() + ") bis zum (" + stbyBody.getValidTo()
-				+ ") eingeplant.";
-		PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO_ML3);
-		lsPlanningMsg.add(dto);
-		return dto;
-	}
-
-	/**
-	 * Method to create a success message for saving an {@link StandbyScheduleBody}
-	 * object.
-	 * 
-	 * @param stbyBody
-	 * @return
-	 */
-	protected PlanningMsgDto createMsgExtendHoliday(StandbyScheduleBody stbyBody, Date date, Boolean isExtendedDuty) {
-		StringBuilder strBuilder = new StringBuilder("Die Bereitschaftszeit für " + stbyBody.getUser().getFirstname()
-				+ " " + stbyBody.getUser().getLastname() + " muss am (" + date
-				+ ") auf Grund eines dienstfreien Tages");
-
-		if (isExtendedDuty) {
-			strBuilder.append(" verlängert werden.");
-		} else {
-			strBuilder.append(" vorgezogen werden.");
-		}
-
-		PlanningMsgDto dto = new PlanningMsgDto(strBuilder.toString(), PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);
-		lsPlanningMsg.add(dto);
-		return dto;
-	}
-
-	/**
-	 * Method to create a warning because of no given group for planning.
-	 * 
-	 * @param stbyBody
-	 * @return
-	 */
-	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 + ")";
-		LOGGER.warn(warning);
-		PlanningMsgDto dto = new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN);
-		lsPlanningMsg.add(dto);
-		return dto;
-	}
-
-	/**
-	 * Method to create a info message with the number of old deleted ScheduleBody
-	 * objects.
-	 * 
-	 * @param map
-	 * @param blueprintDto
-	 * @return
-	 */
-	protected PlanningMsgDto createMsgNumberOfPhases(Map<Integer, PlanningPhaseDto> map,
-			StandbyScheduleBlueprintDto blueprintDto) {
-		String info = "";
-		if (map.size() == 0) {
-			info = "Auf Grund fehlender Bereitschaften im gewählten Zeitraum, vom " + blueprintDto.getValidFrom()
-					+ " bis " + blueprintDto.getValidTo() + ", konnte keine Bereitschaftsphase generiert werden.";
-			LOGGER.info(info);
-			PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN);
-			lsPlanningMsg.add(dto);
-			return dto;
-		} else {
-			info = "Durch wechselnde Gruppenmitglieder wurde(n)  " + map.size()
-					+ " Bereitschaftsphase(n) für den angegebenen Zeitraum , vom " + blueprintDto.getValidFrom()
-					+ " bis " + blueprintDto.getValidTo() + ", erkannt.";
-			LOGGER.info(info);
-			PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);
-			lsPlanningMsg.add(dto);
-			return dto;
-		}
-
-	}
-
-	protected List<PlanningMsgDto> createMsgStartOfPhase(Integer phaseId, PlanningPhaseDto phase) {
-		List<PlanningMsgDto> lsMsgDto = new ArrayList<>();
-		String info = "Die Bereitschaftsphase (" + phaseId + ") wird jetzt für den Zeitraum vom ("
-				+ DateHelper.getStartOfDay(phase.getStartDate()) + ") bis zum ("
-				+ DateHelper.getStartOfDay(phase.getEndDate()) + ") berechnet";
-		LOGGER.info(info);
-		PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);
-		lsPlanningMsg.add(dto);
-		lsMsgDto.add(dto);
-
-		StringBuilder builder = new StringBuilder();
-		for (UserInStandbyGroup uisg : phase.getLsUsers()) {
-			User user = uisg.getUser();
-			String name = user.getFirstname() + " " + user.getLastname();
-			if (builder.toString().isEmpty()) {
-				builder.append(name);
-			} else {
-				builder.append(", " + name);
-			}
-		}
-		info = "Folgende Bereitschaftende werden verplant: " + builder.toString();
-		LOGGER.info(info);
-		dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);
-		lsPlanningMsg.add(dto);
-		lsMsgDto.add(dto);
-
-		return lsMsgDto;
-	}
-
-	protected PlanningMsgDto createMsgEndOfPhase(Integer phasenId) {
-		String info = "Die Berechnung der Bereitschaftsphase (" + phasenId + ") wurde abgeschlossen";
-		LOGGER.info(info);
-		PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);
-		lsPlanningMsg.add(dto);
-		return dto;
-	}
-
-	/**
-	 * Method to create a info message with the number of old deleted ScheduleBody
-	 * objects.
-	 * 
-	 * @param stbyBody
-	 * @return
-	 */
-	protected PlanningMsgDto createMsgLeaveOutStarter() {
-		String info = "Der letzte Starter wurde aufgrund des aktivierten Vorschubs übersprungen.";
-		LOGGER.info(info);
-		PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);
-		lsPlanningMsg.add(dto);
-		return dto;
-	}
-
-	/**
-	 * Method to create a info message with the number of old deleted ScheduleBody
-	 * objects.
-	 * 
-	 * @param stbyBody
-	 * @return
-	 */
-	protected PlanningMsgDto createMsgDeleteScheduleBodies(int numberOfElements) {
-		String warning = "Es wurden " + numberOfElements
-				+ " ältere Bereitschaften für den angegebenen Zeitraum entfernt.";
-		LOGGER.info(warning);
-		PlanningMsgDto dto = new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN);
-		lsPlanningMsg.add(dto);
-		return dto;
-	}
-
-	/**
-	 * Method to create a info message with the number of old deleted ScheduleBody
-	 * objects.
-	 * 
-	 * @param stbyBody
-	 * @return
-	 */
-	protected PlanningMsgDto createMsgGroupLeaderChanged(User user, List<UserInStandbyGroup> lsUserInStandbyGroup) {
-		User nextUser = lsUserInStandbyGroup.get(0).getUser();
-		String warning = "Die ausgewählte Start - Bereitschaft (" + user.getFirstname() + " " + user.getLastname()
-				+ ") ist im angebenen Zeitraum nicht aktiv. Es wird mit (" + nextUser.getFirstname() + " "
-				+ nextUser.getLastname() + ") begonnen.";
-		LOGGER.info(warning);
-		PlanningMsgDto dto = new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN);
-		lsPlanningMsg.add(dto);
-		return dto;
-	}
-
-	/**
-	 * Method to delete {@link StandbyScheduleBody} Objects by a list of id's.
-	 * 
-	 * @param lsIds
-	 * @return
-	 */
-	public PlanningMsgDto deleteScheduleBodiesByIds(List<Long> lsIds) throws SpException {
-		try {
-			for (Long id : lsIds) {
-				standbyScheduleBodyRepository.delete(id);
-			}
-			return createMsgDeleteScheduleBodies(lsIds.size());
-		} catch (Exception e) {
-			SpErrorEntry ee = SpExceptionEnum.COULD_NOT_DELETE_ENTITY_EXCEPTION.getEntry();
-			ee.setMessage(MessageFormat.format(ee.getMessage(), "StandbyScheduleBodies", e.getMessage()));
-			SpException spE = new SpException(ee);
-			LOGGER.error(spE, spE);
-			throw spE;
-		}
-	}
-
-	/**
-	 * Method to check if date is a defined value in calendar database.
-	 * 
-	 * @param date
-	 * @return
-	 */
-	public Boolean isHoliday(Date date, StandbyGroup group) {
-
-		List<CalendarDay> lsCalendarDays = calendarRepository.findValidByDate(DateHelper.getStartOfDay(date),
-				DateHelper.getEndOfDay(date));
-		if (lsCalendarDays != null && !lsCalendarDays.isEmpty()) {
-			List<CalendarDay> lsIgnoreList = group.getLsIgnoredCalendarDays();
-			for (CalendarDay day : lsCalendarDays) {
-				if (!lsIgnoreList.contains(day)) {
-					return true;
-				}
-			}
-			return false;
-		} else {
-			return false;
-		}
-	}
-
-	/**
-	 * Method to get the start duration time for the group.
-	 * 
-	 * @param group
-	 * @param date
-	 * @return null if no fitting duration is available
-	 */
-	public StandbyDuration getFittingDurationOfGroup(StandbyGroup group, Date date) {
-		List<StandbyDuration> lsDuration = this.getFittingDurationsOfGroup(group, date);
-		if (lsDuration != null && !lsDuration.isEmpty()) {
-			return lsDuration.get(0);
-		}
-		return null;
-	}
-
-	/**
-	 * Method to get the start duration time for the group.
-	 * 
-	 * @param group
-	 * @param date
-	 * @return null if no fitting duration is available
-	 */
-	public List<StandbyDuration> getFittingDurationsOfGroup(StandbyGroup group, Date date) {
-		int dayOfWeek = DateHelper.getDayOfWeek(date);
-		return standbyDurationRepository.findDurationForValidFromDay(group.getId(), dayOfWeek);
-	}
-
-	/**
-	 * Method to get the start duration time for the group.
-	 * 
-	 * @param group
-	 * @param date
-	 * @return null if no fitting duration is available
-	 */
-	public StandbyDuration getFittingDurationByValidTo(StandbyGroup group, Date date) {
-		List<StandbyDuration> lsDuration = this.getFittingDurationsByValidTo(group, date);
-		if (lsDuration != null && !lsDuration.isEmpty()) {
-			return lsDuration.get(lsDuration.size() - 1);
-		}
-		return null;
-	}
-
-	/**
-	 * Method to get a list of {@link StandbyDuration} by its end time for the
-	 * group.
-	 * 
-	 * @param group
-	 * @param date
-	 * @return null if no fitting duration is available
-	 */
-	public List<StandbyDuration> getFittingDurationsByValidTo(StandbyGroup group, Date endDate) {
-		int dayOfWeek = DateHelper.getDayOfWeek(endDate);
-		return standbyDurationRepository.findDurationForValidToDay(group.getId(), dayOfWeek);
-	}
-
-	/**
-	 * Method to set the currentPosition to 0 if end of list is reached.
-	 * 
-	 * @param currentPosition
-	 * @param listSize
-	 * @return
-	 */
-	public PlanningBodyResultDto resetCounterToNewPosition(int currentPosition, Long lastStartUserId,
-			List<UserInStandbyGroup> lsUserInGroup, Boolean isNextUserInNextCycle, Boolean isNextUserInNextDuration) {
-		LOGGER.debug("currentPosition: " + currentPosition);
-		LOGGER.debug("lastStartUserId: " + lastStartUserId);
-		LOGGER.debug("UserList Size: " + lsUserInGroup.size());
-
-		// default values
-		PlanningBodyResultDto result = new PlanningBodyResultDto();
-		result.setLastStartUserId(lastStartUserId);
-		result.setNewPosition(currentPosition);
-
-		if (isNextUserInNextDuration) {
-			// get next available position
-			currentPosition = this.getNextAvailablePosition(currentPosition, lsUserInGroup);
-			LOGGER.debug("next currentPosition is: " + currentPosition);
-			int lastIndex = this.getIndexOfLastPlannedUser(lastStartUserId, lsUserInGroup);
-			LOGGER.debug("lastIndexOf: " + lastIndex);
-			if (currentPosition == lastIndex) {
-				LOGGER.debug("start user found at current position " + currentPosition);
-				if (isNextUserInNextCycle) {
-					LOGGER.debug("Because of isNextUserInNextCycle = '" + isNextUserInNextCycle
-							+ "' next position will be searched...) ");
-					this.createMsgLeaveOutStarter();
-					currentPosition = this.getNextAvailablePosition(currentPosition, lsUserInGroup);
-					LOGGER.debug("next currentPosition is: " + currentPosition);
-					Long nextStartUserId = lsUserInGroup.get(currentPosition).getUser().getId();
-					result.setLastStartUserId(nextStartUserId);
-					LOGGER.debug("Next start user id is set to :" + nextStartUserId.longValue());
-				} else {
-					LOGGER.debug("Because of isNextUserInNextCycle = '" + isNextUserInNextCycle
-							+ "' currentPosition is still: " + currentPosition);
-				}
-			}
-		} else {
-			LOGGER.info("isNextUserInNextDuration == false. CurrentUser still in charge.");
-		}
-		result.setNewPosition(currentPosition);
-		return result;
-	}
-
-	/**
-	 * Method to calculate the next available position in array list. Starts with
-	 * the first on if list has reached the end.
-	 * 
-	 * @param currentPosition
-	 * @param lsUserInGroup
-	 * @return
-	 */
-	public int getNextAvailablePosition(int currentPosition, List<UserInStandbyGroup> lsUserInGroup) {
-		if (currentPosition + 1 < lsUserInGroup.size()) {
-			return currentPosition + 1;
-		} else {
-			return 0;
-		}
-	}
-
-	/**
-	 * Method to get the position of the last planned user. Returns back '-1' if not
-	 * found in given list.
-	 * 
-	 * @param currentPosition
-	 * @param listSize
-	 * @return
-	 */
-	public int getIndexOfLastPlannedUser(Long lastStartUserId, List<UserInStandbyGroup> lsUserInGroup) {
-		int indexOf = -1;
-		for (UserInStandbyGroup userInGroup : lsUserInGroup) {
-			if (userInGroup.getUser().getId().longValue() == lastStartUserId.longValue()) {
-				indexOf = lsUserInGroup.indexOf(userInGroup);
-				return indexOf;
-			}
-		}
-		return indexOf;
-	}
-
-	/**
-	 * Method to validate the input parameter for the planning.
-	 * 
-	 * @param standbyBlueprintDto
-	 * @return
-	 * @throws SpException
-	 */
-	public boolean validateInputForPlanCalculation(StandbyScheduleBlueprintDto standbyBlueprintDto) throws SpException {
-		if (standbyBlueprintDto.getStandbyListId() != null) {
-			if (!standbyListRepository.exists(standbyBlueprintDto.getStandbyListId())) {
-				SpErrorEntry ee = SpExceptionEnum.UNKNOWN_ENTITY_EXCEPTION.getEntry();
-				String txt = MessageFormat.format(SpMsg.TXT_STANDBY_LIST_WITH_ID,
-						standbyBlueprintDto.getStandbyListId());
-				ee.setMessage(MessageFormat.format(ee.getMessage(), txt));
-				SpException spE = new SpException(ee);
-				LOGGER.error(spE, spE);
-				throw spE;
-			}
-		} else {
-			SpErrorEntry ee = SpExceptionEnum.MISSING_PARAMETER_EXCEPTION.getEntry();
-			ee.setMessage(MessageFormat.format(ee.getMessage(), "StandbyList"));
-			SpException spE = new SpException(ee);
-			LOGGER.error(spE, spE);
-			throw spE;
-		}
-
-		if (standbyBlueprintDto.getStandbyGroupId() != null) {
-			if (!standbyGroupRepository.exists(standbyBlueprintDto.getStandbyGroupId())) {
-				SpErrorEntry ee = SpExceptionEnum.UNKNOWN_ENTITY_EXCEPTION.getEntry();
-				String txt = MessageFormat.format(SpMsg.TXT_STANDBY_GROUP_WITH_ID,
-						standbyBlueprintDto.getStandbyGroupId());
-				ee.setMessage(MessageFormat.format(ee.getMessage(), txt));
-				SpException spE = new SpException(ee);
-				LOGGER.error(spE, spE);
-				throw spE;
-			}
-		} else {
-			SpErrorEntry ee = SpExceptionEnum.MISSING_PARAMETER_EXCEPTION.getEntry();
-			ee.setMessage(MessageFormat.format(ee.getMessage(), "StandbyGroup"));
-			SpException spE = new SpException(ee);
-			LOGGER.error(spE, spE);
-			throw spE;
-		}
-
-		if (standbyBlueprintDto.getValidFrom() == null) {
-			SpErrorEntry ee = SpExceptionEnum.MISSING_PARAMETER_EXCEPTION.getEntry();
-			ee.setMessage(MessageFormat.format(ee.getMessage(), "validFrom"));
-			SpException spE = new SpException(ee);
-			LOGGER.error(spE, spE);
-			throw spE;
-		}
-
-		if (standbyBlueprintDto.getValidTo() == null) {
-			SpErrorEntry ee = SpExceptionEnum.MISSING_PARAMETER_EXCEPTION.getEntry();
-			ee.setMessage(MessageFormat.format(ee.getMessage(), "validTo"));
-			SpException spE = new SpException(ee);
-			LOGGER.error(spE, spE);
-			throw spE;
-		}
-
-		return true;
-	}
-
-	/**
-	 * Method to log the phase map object.
-	 * 
-	 * @param resultMap
-	 */
-	public void logPhases(Map<Integer, PlanningPhaseDto> resultMap) {
-		LOGGER.debug("The following " + resultMap.keySet().size() + " had been found");
-		for (Entry<Integer, PlanningPhaseDto> entry : resultMap.entrySet()) {
-			LOGGER.debug("-----------------------");
-			LOGGER.debug("Phase :" + entry.getKey());
-			LOGGER.debug("-----------------------");
-			PlanningPhaseDto dto = entry.getValue();
-			LOGGER.debug("StartDate :" + dto.getStartDate());
-			LOGGER.debug("EndDate :" + dto.getEndDate());
-			LOGGER.debug("Number of StandbyUser :" + dto.getLsUsers().size());
-			for (UserInStandbyGroup uisg : dto.getLsUsers()) {
-				LOGGER.debug("Gruppenmitglied :" + uisg.getUser().getFirstname() + " " + uisg.getUser().getLastname());
-			}
-		}
-	}
-
-	/**
-	 * Method to replace user in schedule bodies for the given interval
-	 * 
-	 * @param actionDto
-	 * @param username
-	 * @return
-	 * @throws SpException
-	 */
-	public PlanningMsgResponseDto replaceUserInPlan(StandbyScheduleActionDto actionDto, String username)
-			throws SpException {
-		PlanningMsgResponseDto responseDto = new PlanningMsgResponseDto();
-
-		// check input values
-		List<Object> lsInputParams = new ArrayList<>();
-		lsInputParams.add(actionDto.getCurrentUserId());
-		lsInputParams.add(actionDto.getNewUserId());
-		lsInputParams.add(actionDto.getStandbyGroupId());
-		lsInputParams.add(actionDto.getStatusId());
-		lsInputParams.add(actionDto.getValidFrom());
-		lsInputParams.add(actionDto.getValidTo());
-		lsInputParams.add(username);
-		ValidationHelper.isNoNullValueInList(lsInputParams);
-
-		// input validation
-		responseDto.getLsMsg().addAll(validatonController.validatePlanningActionInput(actionDto));
-
-		try {
-
-			// history
-			archiveController.createArchiveOnReplaceInOneGroup(actionDto, username);
-
-			User currentUser = userRepository.findOne(actionDto.getCurrentUserId());
-			User newUser = userRepository.findOne(actionDto.getNewUserId());
-			StandbyGroup standbyGroup = standbyGroupRepository.findOne(actionDto.getStandbyGroupId());
-			Date from = actionDto.getValidFrom();
-			Date to = actionDto.getValidTo();
-
-			// mail
-			mailing.replaceMessage1(actionDto, currentUser, newUser, standbyGroup);
-			mailing.replaceMessage2(actionDto, currentUser, newUser, standbyGroup);
-
-			ArrayList<StandbyGroup> lsStandbyGroups = new ArrayList<>();
-			List<StandbyScheduleBody> lsBodies = standbyScheduleBodyRepository.findByUserAndGroupAndDateAndStatus(
-					currentUser.getId(), actionDto.getStandbyGroupId(), DateHelper.getStartOfDay(from),
-					DateHelper.getEndOfDay(to), actionDto.getStatusId());
-
-			for (StandbyScheduleBody body : lsBodies) {
-				this.splitScheduleBody(body, from, to, newUser, username);
-				if (!lsStandbyGroups.contains(body.getStandbyGroup())) {
-					lsStandbyGroups.add(body.getStandbyGroup());
-				}
-			}
-
-			// start validation
-			List<String> lsValidationBeanNames = new ArrayList<>();
-			lsValidationBeanNames.add(ValidationController.BEAN_GROUP_COVERAGE_VALIDATOR);
-			lsValidationBeanNames.add(ValidationController.BEAN_DOUBLE_PLANNED_VALIDATOR);
-			lsValidationBeanNames.add(ValidationController.BEAN_PLACEHOLDER_STANDBY_USER_VALIDATOR);
-
-			responseDto.getLsMsg().addAll(validatonController.startValidation(actionDto.getValidFrom(),
-					actionDto.getValidTo(), lsStandbyGroups, lsValidationBeanNames, actionDto.getStatusId()));
-
-			return responseDto;
-		} catch (Exception e) {
-			LOGGER.error(e, e);
-			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();
-			ee.setE(e);
-			throw new SpException(ee);
-		}
-	}
-
-	protected Boolean splitScheduleBody(StandbyScheduleBody body, Date from, Date to, User newUser, String modifiedBy)
-			throws SpException {
-		try {
-			Date tmpFrom = from;
-			Date tmpTo = to;
-			if (DateHelper.isDateBefore(from, DateHelper.getStartOfDay(body.getValidFrom()))) {
-				tmpFrom = DateHelper.getStartOfDay(body.getValidFrom());
-			}
-
-			if (DateHelper.isDateAfter(to, DateHelper.getEndOfDay(body.getValidFrom()))) {
-				tmpTo = DateHelper.getEndOfDay(body.getValidFrom());
-			}
-
-			// interval of ui params
-			Interval intervalSelection = new Interval(new DateTime(tmpFrom).getMillis(),
-					new DateTime(tmpTo).getMillis());
-
-			// interval of saved schedule body
-			Interval intervalBody = new Interval(new DateTime(body.getValidFrom()).getMillis(),
-					new DateTime(body.getValidTo()).getMillis());
-
-			// overlapping interval between params and schedule body values
-			Interval intervalOverlap = intervalBody.overlap(intervalSelection);
-
-			if (intervalOverlap != null) {
-				int isSameStart = DateHelper.isSameDateTime(body.getValidFrom(), tmpFrom);
-				int isSameEnd = DateHelper.isSameDateTime(body.getValidTo(), tmpTo);
-
-				tmpFrom = intervalOverlap.getStart().toDate();
-				tmpTo = intervalOverlap.getEnd().toDate();
-				if (isSameStart >= 0) {
-					if (isSameEnd == 0) {
-						// full replace
-						body.setUser(newUser);
-						body.setModifiedCause(TXT_MANUAL_CHANGE);
-						body.setModificationDate(new Date());
-						body.setModifiedBy(modifiedBy);
-						standbyScheduleBodyRepository.save(body);
-					} else if (isSameEnd < 0) {
-						body.setUser(newUser);
-						body.setModifiedCause(TXT_MANUAL_CHANGE);
-						body.setModificationDate(new Date());
-						body.setModifiedBy(modifiedBy);
-						body.setValidTo(tmpTo);
-						standbyScheduleBodyRepository.save(body);
-					} else {
-						StandbyScheduleBody newBody = body.copy();
-						newBody.setUser(newUser);
-						newBody.setModifiedCause(TXT_MANUAL_CHANGE);
-						newBody.setModificationDate(new Date());
-						newBody.setModifiedBy(modifiedBy);
-						newBody.setValidTo(tmpTo);
-						standbyScheduleBodyRepository.save(newBody);
-
-						body.setValidFrom(tmpTo);
-						body.setModifiedCause(TXT_MANUAL_CHANGE);
-						body.setModificationDate(new Date());
-						body.setModifiedBy(modifiedBy);
-						standbyScheduleBodyRepository.save(body);
-					}
-				} else if (isSameEnd == 0) {
-					StandbyScheduleBody newBody = body.copy();
-					newBody.setUser(newUser);
-					newBody.setModifiedCause(TXT_MANUAL_CHANGE);
-					newBody.setModificationDate(new Date());
-					newBody.setModifiedBy(modifiedBy);
-					newBody.setValidFrom(tmpFrom);
-					standbyScheduleBodyRepository.save(newBody);
-
-					body.setValidTo(tmpFrom);
-					body.setModifiedCause(TXT_MANUAL_CHANGE);
-					body.setModificationDate(new Date());
-					body.setModifiedBy(modifiedBy);
-					standbyScheduleBodyRepository.save(body);
-				} else if (isSameEnd < 0) {
-					// replace with end at 23:59
-					StandbyScheduleBody newBody = body.copy();
-					newBody.setUser(newUser);
-					newBody.setModifiedCause(TXT_MANUAL_CHANGE);
-					newBody.setModificationDate(new Date());
-					newBody.setModifiedBy(modifiedBy);
-					newBody.setValidFrom(tmpFrom);
-					newBody.setValidTo(tmpTo);
-					standbyScheduleBodyRepository.save(newBody);
-
-					body.setModifiedCause(TXT_MANUAL_CHANGE);
-					body.setModificationDate(new Date());
-					body.setModifiedBy(modifiedBy);
-					body.setValidTo(tmpFrom);
-					standbyScheduleBodyRepository.save(body);
-				} else {
-					// set new user (n1) between old (o1) existing entry by splitting it.
-					// Looks like this [o1--n1--o2]
-					StandbyScheduleBody newBody = body.copy();
-					newBody.setUser(newUser);
-					newBody.setModifiedCause(TXT_MANUAL_CHANGE);
-					newBody.setModificationDate(new Date());
-					newBody.setModifiedBy(modifiedBy);
-					newBody.setValidFrom(tmpFrom);
-					newBody.setValidTo(tmpTo);
-					standbyScheduleBodyRepository.save(newBody);
-
-					// set new entry to not loose the time after
-					StandbyScheduleBody oldBodyAfter = body.copy();
-					oldBodyAfter.setModifiedCause(TXT_MANUAL_CHANGE);
-					oldBodyAfter.setModificationDate(new Date());
-					oldBodyAfter.setModifiedBy(modifiedBy);
-					oldBodyAfter.setValidFrom(tmpTo);
-					standbyScheduleBodyRepository.save(oldBodyAfter);
-
-					// set
-					body.setModifiedCause(TXT_MANUAL_CHANGE);
-					body.setModificationDate(new Date());
-					body.setModifiedBy(modifiedBy);
-					body.setValidTo(tmpFrom);
-					standbyScheduleBodyRepository.save(body);
-				}
-			}
-
-			return true;
-		} catch (Exception e) {
-			LOGGER.error(e, e);
-			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();
-			ee.setE(e);
-			throw new SpException(ee);
-		}
-	}
-
-	/**
-	 * Method to change the time of a schedule body.
-	 * 
-	 * @param actionDto
-	 * @param username
-	 * @return
-	 * @throws SpException
-	 */
-	public PlanningMsgResponseDto moveUserInPlan(StandbyScheduleActionDto actionDto, String username)
-			throws SpException {
-		PlanningMsgResponseDto responseDto = new PlanningMsgResponseDto();
-
-		// check input values
-		List<Object> lsInputParams = new ArrayList<>();
-		lsInputParams.add(actionDto.getNewUserId());
-		lsInputParams.add(actionDto.getScheduleBodyId());
-		lsInputParams.add(actionDto.getValidFrom());
-		lsInputParams.add(actionDto.getValidTo());
-		lsInputParams.add(actionDto.getStandbyGroupId());
-		lsInputParams.add(username);
-		ValidationHelper.isNoNullValueInList(lsInputParams);
-
-		// input validation
-		responseDto.getLsMsg().addAll(validatonController.validatePlanningActionInput(actionDto));
-
-		StandbyGroup tempOldGroup = null;
-		StandbyGroup tempNewGroup = null;
-
-		try {
-
-			// history
-			archiveController.createArchiveOnMove(actionDto, username);
-
-			StandbyScheduleBody body = standbyScheduleBodyRepository.findOne(actionDto.getScheduleBodyId());
-			tempNewGroup = standbyGroupRepository.findOne(actionDto.getStandbyGroupId());
-
-			// mail
-			mailing.moveMessage1(actionDto, body, tempNewGroup);
-
-			tempOldGroup = body.getStandbyGroup();
-			body.setModifiedCause(SpMsg.ACT_STANDBY_MOVE);
-			body.setModificationDate(new Date());
-			body.setModifiedBy(username);
-			body.setStandbyGroup(tempNewGroup);
-
-			if (DateHelper.isSameDate(actionDto.getValidFrom(), actionDto.getValidTo())) {
-				// because of no overlapping day schedule body just
-				// gets new values, no second body is needed.
-				body.setValidFrom(actionDto.getValidFrom());
-				body.setValidTo(actionDto.getValidTo());
-				standbyScheduleBodyRepository.save(body);
-
-			} else {
-				Date nextDate = actionDto.getValidFrom();
-				StandbyScheduleBody newBody = null;
-				while (DateHelper.isDateBefore(nextDate, actionDto.getValidTo())
-						&& !DateHelper.isSameDate(nextDate, actionDto.getValidTo())) {
-					newBody = body.copy();
-					if (DateHelper.isSameDate(actionDto.getValidFrom(), nextDate)) {
-						// do not change start time on first day
-						newBody.setValidFrom(nextDate);
-					} else {
-						// begin with = 0:00 if not first day
-						newBody.setValidFrom(DateHelper.getStartOfDay(nextDate));
-					}
-					newBody.setValidTo(DateHelper.getEndOfDay(nextDate));
-					newBody.setModifiedCause(TXT_MANUAL_CHANGE);
-					newBody.setModificationDate(new Date());
-					newBody.setModifiedBy(username);
-					newBody.setStandbyGroup(body.getStandbyGroup());
-					standbyScheduleBodyRepository.save(newBody);
-
-					nextDate = DateHelper.addDaysToDate(nextDate, 1);
-				}
-
-				// add last day
-				StandbyScheduleBody lastBody = body.copy();
-				lastBody.setValidFrom(DateHelper.getStartOfDay(actionDto.getValidTo()));
-				lastBody.setValidTo(actionDto.getValidTo());
-				lastBody.setModifiedCause(TXT_MANUAL_CHANGE);
-				lastBody.setModificationDate(new Date());
-				lastBody.setModifiedBy(username);
-				lastBody.setStandbyGroup(body.getStandbyGroup());
-				standbyScheduleBodyRepository.save(lastBody);
-
-				// remove original because of splitting it to multiple entries
-				standbyScheduleBodyRepository.delete(body.getId());
-			}
-
-			ArrayList<StandbyGroup> lsStandbyGroups = new ArrayList<>();
-			lsStandbyGroups.add(tempOldGroup);
-			// add new group to check list if it differs from origin group
-			if (tempOldGroup.getId().longValue() != tempNewGroup.getId().longValue()) {
-				lsStandbyGroups.add(tempNewGroup);
-			}
-
-			// start validation
-			List<String> lsValidationBeanNames = new ArrayList<>();
-			lsValidationBeanNames.add(ValidationController.BEAN_GROUP_COVERAGE_VALIDATOR);
-			lsValidationBeanNames.add(ValidationController.BEAN_DOUBLE_PLANNED_VALIDATOR);
-			lsValidationBeanNames.add(ValidationController.BEAN_PLACEHOLDER_STANDBY_USER_VALIDATOR);
-			responseDto.getLsMsg().addAll(validatonController.startValidation(actionDto.getValidFrom(),
-					actionDto.getValidTo(), lsStandbyGroups, lsValidationBeanNames, actionDto.getStatusId()));
-
-			return responseDto;
-		} catch (Exception e) {
-			LOGGER.error(e, e);
-			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();
-			ee.setE(e);
-			throw new SpException(ee);
-		}
-	}
-}
+/********************************************************************************

+ * Copyright (c) 2018 Mettenmeier GmbH 

+ *

+ * See the NOTICE file(s) distributed with this work for additional 

+ * information regarding copyright ownership.

+ *

+ * This program and the accompanying materials are made available under the 

+ * terms of the Eclipse Public License 2.0 which is available at

+ * http://www.eclipse.org/legal/epl-2.0

+ *

+ * SPDX-License-Identifier: EPL-2.0 

+ ********************************************************************************/

+package org.eclipse.openk.sp.controller.planning;

+

+import java.text.MessageFormat;

+import java.util.ArrayList;

+import java.util.Collections;

+import java.util.Date;

+import java.util.HashMap;

+import java.util.List;

+import java.util.Map;

+import java.util.Map.Entry;

+

+import org.apache.commons.collections.CollectionUtils;

+import org.apache.log4j.Logger;

+import org.eclipse.openk.sp.controller.AbstractController;

+import org.eclipse.openk.sp.controller.validation.ValidationController;

+import org.eclipse.openk.sp.db.dao.CalendarRepository;

+import org.eclipse.openk.sp.db.dao.StandbyDurationRepository;

+import org.eclipse.openk.sp.db.dao.StandbyGroupRepository;

+import org.eclipse.openk.sp.db.dao.StandbyListRepository;

+import org.eclipse.openk.sp.db.dao.StandbyScheduleBodyRepository;

+import org.eclipse.openk.sp.db.dao.StandbyStatusRepository;

+import org.eclipse.openk.sp.db.dao.UserInStandbyGroupRepository;

+import org.eclipse.openk.sp.db.dao.UserRepository;

+import org.eclipse.openk.sp.db.model.CalendarDay;

+import org.eclipse.openk.sp.db.model.StandbyDuration;

+import org.eclipse.openk.sp.db.model.StandbyGroup;

+import org.eclipse.openk.sp.db.model.StandbyScheduleBody;

+import org.eclipse.openk.sp.db.model.User;

+import org.eclipse.openk.sp.db.model.UserInStandbyGroup;

+import org.eclipse.openk.sp.dto.StandbyScheduleBlueprintDto;

+import org.eclipse.openk.sp.dto.planning.PlanningBodyResultDto;

+import org.eclipse.openk.sp.dto.planning.PlanningMsgDto;

+import org.eclipse.openk.sp.dto.planning.PlanningMsgResponseDto;

+import org.eclipse.openk.sp.dto.planning.PlanningPhaseDto;

+import org.eclipse.openk.sp.dto.planning.StandbyScheduleActionDto;

+import org.eclipse.openk.sp.exceptions.SpErrorEntry;

+import org.eclipse.openk.sp.exceptions.SpException;

+import org.eclipse.openk.sp.exceptions.SpExceptionEnum;

+import org.eclipse.openk.sp.mail.MailRequest;

+import org.eclipse.openk.sp.util.DateHelper;

+import org.eclipse.openk.sp.util.SpMsg;

+import org.eclipse.openk.sp.util.ValidationHelper;

+import org.joda.time.DateTime;

+import org.joda.time.Interval;

+import org.springframework.beans.factory.annotation.Autowired;

+import org.springframework.stereotype.Service;

+import org.springframework.transaction.annotation.Transactional;

+

+@Service

+@Transactional(rollbackFor = Exception.class)

+/** Class to handle planning operations. */

+public class PlanningController extends AbstractController {

+	protected static final Logger LOGGER = Logger.getLogger(PlanningController.class);

+	public static final String TXT_AUTOMATIC_PLANNING = "autom. Planung";

+	public static final String TXT_AUTOMATIC_PLANNING_HOLIDAY = "autom. Planung (Dienstfrei)";

+	public static final String TXT_AUTOMATIC_CHANGE = "autom. Änderung";

+	public static final String TXT_MANUAL_CHANGE = "manuelle Änderung";

+

+	@Autowired

+	private StandbyGroupRepository standbyGroupRepository;

+

+	@Autowired

+	private StandbyListRepository standbyListRepository;

+

+	@Autowired

+	private StandbyDurationRepository standbyDurationRepository;

+

+	@Autowired

+	private StandbyStatusRepository standbyStatusRepository;

+

+	@Autowired

+	private ArchiveController archiveController;

+

+	@Autowired

+	private StandbyScheduleBodyRepository standbyScheduleBodyRepository;

+

+	@Autowired

+	private UserInStandbyGroupRepository uisgRepository;

+

+	@Autowired

+	private UserRepository userRepository;

+

+	@Autowired

+	private CalendarRepository calendarRepository;

+

+	@Autowired

+	private ValidationController validatonController;

+

+	@Autowired

+	private MailRequest mailing;

+

+	private List<PlanningMsgDto> lsPlanningMsg = new ArrayList<>();

+

+	public PlanningMsgResponseDto startPlanning(StandbyScheduleBlueprintDto standbyBlueprintDto, String username)

+			throws SpException {

+		PlanningMsgResponseDto responseDto = new PlanningMsgResponseDto();

+		try {

+			lsPlanningMsg = new ArrayList<>();

+			// check if input is valid

+			if (this.validateInputForPlanCalculation(standbyBlueprintDto)) {

+				standbyBlueprintDto.setValidTo(DateHelper.getEndOfDay(standbyBlueprintDto.getValidTo()));

+				// calculate the different phases.

+				Map<Integer, PlanningPhaseDto> planningPhaseMap = this.calculatePlanningPhaseMap(standbyBlueprintDto);

+				this.createMsgNumberOfPhases(planningPhaseMap, standbyBlueprintDto);

+

+				Long lastStartUserId = standbyBlueprintDto.getStartIdOfUser();

+				// loop over planning phases

+				for (Entry<Integer, PlanningPhaseDto> entry : planningPhaseMap.entrySet()) {

+					LOGGER.debug("Start Plannig for phase " + entry.getKey());

+					PlanningPhaseDto dto = entry.getValue();

+					this.createMsgStartOfPhase(entry.getKey(), dto);

+					this.calculatePlanForPhase(dto, lastStartUserId, username);

+					this.createMsgEndOfPhase(entry.getKey());

+					LOGGER.debug("End Plannig for phase " + entry.getKey());

+				}

+

+				standbyScheduleBodyRepository.flush();

+

+				// start validation

+				List<String> lsValidationBeanNames = new ArrayList<>();

+				lsValidationBeanNames.add(ValidationController.BEAN_GROUP_COVERAGE_VALIDATOR);

+				lsValidationBeanNames.add(ValidationController.BEAN_DOUBLE_PLANNED_VALIDATOR);

+				lsValidationBeanNames.add(ValidationController.BEAN_PLACEHOLDER_STANDBY_USER_VALIDATOR);

+

+				List<StandbyGroup> lsStandbyGroups = new ArrayList<>();

+				lsStandbyGroups.add(standbyGroupRepository.findOne(standbyBlueprintDto.getStandbyGroupId()));

+

+				lsPlanningMsg.addAll(validatonController.startValidation(standbyBlueprintDto.getValidFrom(),

+						standbyBlueprintDto.getValidTo(), lsStandbyGroups, lsValidationBeanNames,

+						standbyBlueprintDto.getStatusId(), null));

+				responseDto.setLsMsg(lsPlanningMsg);

+			}

+			return responseDto;

+		} catch (SpException e) {

+			LOGGER.error(e, e);

+			throw e;

+		} catch (Exception e) {

+			LOGGER.error(e, e);

+			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();

+			ee.setE(e);

+			throw new SpException(ee);

+		}

+	}

+

+	/**

+	 * Method to calculate the different phases for changing groups.

+	 * 

+	 * @param standbyBlueprintDto

+	 * @return

+	 * @throws SpException

+	 */

+	public Map<Integer, PlanningPhaseDto> calculatePlanningPhaseMap(StandbyScheduleBlueprintDto standbyBlueprintDto)

+			throws SpException {

+		Map<Integer, PlanningPhaseDto> resultMap = new HashMap<>();

+		try {

+			Date validFrom = standbyBlueprintDto.getValidFrom();

+			Date validTo = DateHelper.getEndOfDay(standbyBlueprintDto.getValidTo());

+			Date tmpDate = validFrom;

+			int phase = 1;

+

+			while (tmpDate.getTime() <= validTo.getTime()) {

+				List<UserInStandbyGroup> lsUserInGroup = uisgRepository

+						.findUserForInterval(standbyBlueprintDto.getStandbyGroupId(), tmpDate, tmpDate);

+				if (lsUserInGroup != null && !lsUserInGroup.isEmpty()) {

+					if (resultMap.containsKey(phase)) {

+						PlanningPhaseDto dto = resultMap.get(phase);

+						if (CollectionUtils.isEqualCollection(dto.getLsUsers(), lsUserInGroup)) {

+							dto.setEndDate(DateHelper.addDaysToDate(dto.getEndDate(), 1));

+						} else {

+							phase++;

+							LOGGER.debug("Add phase " + phase);

+							resultMap.put(phase, new PlanningPhaseDto(tmpDate, tmpDate, lsUserInGroup));

+						}

+					} else {

+						LOGGER.debug("Add phase " + phase);

+						resultMap.put(phase, new PlanningPhaseDto(tmpDate, tmpDate, lsUserInGroup));

+					}

+				}

+				tmpDate = DateHelper.addDaysToDate(tmpDate, 1);

+			}

+			this.logPhases(resultMap);

+			return resultMap;

+		} catch (Exception e) {

+			LOGGER.error(e, e);

+			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();

+			ee.setE(e);

+			throw new SpException(ee);

+		}

+

+	}

+

+	public void changeOrDeleteAtIntervalStart(StandbyScheduleBody body, StandbyDuration duration, Date tmpDate,

+			String username) {

+		if (duration != null) {

+			Date durationStart = DateHelper.getDateWithTime(tmpDate, duration.getValidFrom());

+			if (DateHelper.isDateBefore(body.getValidFrom(), durationStart)) {

+				if (DateHelper.isDateAfter(body.getValidTo(), durationStart)) {

+					body.setValidTo(durationStart);

+					body.setModificationDate(new Date());

+					body.setModifiedCause(TXT_AUTOMATIC_CHANGE);

+					body.setModifiedCause(username);

+					standbyScheduleBodyRepository.save(body);

+				}

+			} else {

+				standbyScheduleBodyRepository.delete(body);

+			}

+		}

+	}

+

+	public void changeOrDeleteAtIntervalEnd(StandbyScheduleBody body, StandbyDuration duration, Date tmpDate,

+			String username) {

+		if (duration != null) {

+			Date durationEnd = DateHelper.getDateWithTime(tmpDate, duration.getValidTo());

+			if (DateHelper.isDateBefore(body.getValidFrom(), durationEnd)) {

+				if (DateHelper.isDateAfter(body.getValidTo(), durationEnd)) {

+					body.setValidTo(durationEnd);

+					body.setModificationDate(new Date());

+					body.setModifiedCause(TXT_AUTOMATIC_CHANGE);

+					body.setModifiedCause(username);

+					standbyScheduleBodyRepository.save(body);

+				}

+			} else {

+				standbyScheduleBodyRepository.delete(body);

+			}

+		}

+	}

+

+	public void changeOrDeleteExistingBodies(StandbyGroup group, Date startDate, Date endDate, Long statusId,

+			String username) {

+		Date tmpDate = startDate;

+		while (tmpDate.getTime() <= endDate.getTime()) {

+			List<StandbyScheduleBody> lsBodies = standbyScheduleBodyRepository

+					.findByGroupAndStatusHittingDateInterval(group.getId(), tmpDate, endDate, statusId);

+

+			List<StandbyDuration> lsFittingDurations = this.getFittingDurationsOfGroup(group, tmpDate);

+			StandbyDuration duration = null;

+			if (lsFittingDurations != null && !lsFittingDurations.isEmpty()) {

+				duration = lsFittingDurations.get(0);

+			}

+			for (StandbyScheduleBody body : lsBodies) {

+				if (tmpDate.getTime() == startDate.getTime()) {

+					this.changeOrDeleteAtIntervalStart(body, duration, tmpDate, username);

+				} else if (tmpDate.getTime() == endDate.getTime()) {

+					this.changeOrDeleteAtIntervalEnd(body, duration, tmpDate, username);

+				} else {

+					standbyScheduleBodyRepository.delete(body);

+				}

+			}

+			tmpDate = DateHelper.addDaysToDate(tmpDate, 1);

+		}

+

+	}

+

+	public void calculatePlanForPhase(PlanningPhaseDto dto, Long lastStartUserId, String username) throws SpException {

+		try {

+			List<UserInStandbyGroup> lsUserInGroup = dto.getLsUsers();

+

+			Collections.sort(lsUserInGroup,

+					(UserInStandbyGroup o1, UserInStandbyGroup o2) -> o1.getPosition().compareTo(o2.getPosition()));

+

+			int currentPosition = this.getIndexOfLastPlannedUser(lastStartUserId, lsUserInGroup);

+			if (currentPosition == -1) {

+				this.createMsgGroupLeaderChanged(userRepository.findOne(lastStartUserId), lsUserInGroup);

+				currentPosition = 0;

+			}

+			Date tmpDate = dto.getStartDate();

+

+			this.changeOrDeleteExistingBodies(lsUserInGroup.get(0).getStandbyGroup(), dto.getStartDate(),

+					dto.getEndDate(), 1L, username);

+			while (tmpDate.getTime() <= dto.getEndDate().getTime()) {

+

+				// reset position if end of list has been reached

+				PlanningBodyResultDto planningBodyResultDto = this.calculateScheduleBodyEntries(lsUserInGroup,

+						dto.getStartDate(), tmpDate, dto.getEndDate(), currentPosition, username, lastStartUserId);

+				tmpDate = planningBodyResultDto.getTempDate();

+				currentPosition = planningBodyResultDto.getNewPosition();

+			}

+		} catch (Exception e) {

+			LOGGER.error(e, e);

+			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();

+			ee.setE(e);

+			throw new SpException(ee);

+		}

+	}

+

+	/**

+	 * Method to create a simple {@link StandbyScheduleBody} object with input

+	 * values for planning.

+	 * 

+	 * @param group

+	 * @param username

+	 * @param date

+	 * @param user

+	 * @param duration

+	 * @return

+	 */

+	public StandbyScheduleBody createScheduleBodyObject(StandbyGroup group, String username, Date date, User user,

+			StandbyDuration duration, String cause) {

+		StandbyScheduleBody stbyBody = new StandbyScheduleBody();

+		stbyBody.setModificationDate(new Date());

+		stbyBody.setModifiedBy(username);

+		stbyBody.setModifiedCause(cause);

+		stbyBody.setStandbyGroup(group);

+		stbyBody.setUser(user);

+		stbyBody.setStatus(standbyStatusRepository.findOne(1l));

+		stbyBody.setValidFrom(DateHelper.getDateWithTime(date, duration.getValidFrom()));

+		stbyBody.setValidTo(DateHelper.getDateWithTime(date, duration.getValidTo()));

+		return stbyBody;

+	}

+

+	public List<StandbyScheduleBody> createOverlappingScheduleBodyObjects(StandbyGroup group, String username,

+			Date date, User user, StandbyDuration duration, int loopPos, int loopLength) {

+		List<StandbyScheduleBody> lsStandbyScheduleBodies = new ArrayList<>();

+		StandbyScheduleBody stbyBody = this.createScheduleBodyObject(group, username, date, user, duration,

+				TXT_AUTOMATIC_PLANNING);

+		if (loopPos > 0) {

+			// if not the first loop the schedule body should start at the begin of the day.

+			stbyBody.setValidFrom(DateHelper.getDateWithTime(date, DateHelper.getStartOfDay(duration.getValidFrom())));

+		}

+		Date validTo = DateHelper.getDateWithTime(date, duration.getValidTo());

+		validTo = DateHelper.getEndOfDay(validTo);

+		stbyBody.setValidTo(validTo);

+

+		stbyBody = this.calculateHoliday(group, date, stbyBody);

+

+		lsStandbyScheduleBodies.add(stbyBody);

+		if (loopPos + 1 == loopLength) {

+			// if last entry use end time of duration

+			StandbyScheduleBody stbyBody2 = null;

+			stbyBody2 = this.createScheduleBodyObject(group, username, date, user, duration, TXT_AUTOMATIC_PLANNING);

+			Date nextDay = DateHelper.addDaysToDate(date, 1);

+			Date validFrom = DateHelper.getDateWithTime(DateHelper.addDaysToDate(date, 1),

+					DateHelper.getStartOfDay(duration.getValidFrom()));

+			stbyBody2.setValidFrom(validFrom);

+			validTo = DateHelper.getDateWithTime(nextDay, duration.getValidTo());

+			stbyBody2.setValidTo(validTo);

+			this.calculateHoliday(group, nextDay, stbyBody2);

+			lsStandbyScheduleBodies.add(stbyBody2);

+		}

+

+		return lsStandbyScheduleBodies;

+	}

+

+	/**

+	 * Method to check if the current day is a holiday for the standby group and

+	 * calls the pre-draw or extend calculation.

+	 * 

+	 * @param group

+	 * @param date

+	 * @param stbyBody

+	 * @return

+	 */

+	public StandbyScheduleBody calculateHoliday(StandbyGroup group, Date date, StandbyScheduleBody stbyBody) {

+		if (isHoliday(date, group)) {

+			if (group.getExtendStandbyTime()) {

+				// if extend of standby time is needed

+				stbyBody = this.calculateHolidayExtend(group, date, stbyBody);

+			} else {

+				// is pre-draw of standby time needed

+				stbyBody = this.calculateHolidayPreDraw(group, date, stbyBody);

+			}

+		}

+		return stbyBody;

+	}

+

+	/**

+	 * Method to change the standby time if a holiday / calendar day is defined and

+	 * the standby time has to be pre-drawn.

+	 * 

+	 * @param group

+	 * @param date

+	 * @param stbyBody

+	 * @return

+	 */

+	public StandbyScheduleBody calculateHolidayPreDraw(StandbyGroup group, Date date, StandbyScheduleBody stbyBody) {

+

+		List<StandbyDuration> lsDurations = this.getFittingDurationsByValidTo(group, date);

+		if (lsDurations != null) {

+			int size = lsDurations.size();

+			// loop backward to find last fitting duration

+			for (int a = size; a > 0; a--) {

+				StandbyDuration dur = lsDurations.get(a - 1);

+				// proof if found duration ends before current body starts.

+				if (dur != null && DateHelper.isDateBefore(DateHelper.getDateWithTime(date, dur.getValidTo()),

+						stbyBody.getValidFrom())) {

+					// set last found duration end as start of current entry

+					stbyBody.setValidFrom(DateHelper.getDateWithTime(date, dur.getValidTo()));

+					this.createMsgExtendHoliday(stbyBody, date, false);

+					// end loop after first fitting result.

+					stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);

+					return stbyBody;

+				}

+			}

+			// no last duration for the day has been found. Therefore the start of day has

+			// been used for current entry

+			if (DateHelper.isDateBefore(DateHelper.getStartOfDay(date), stbyBody.getValidFrom())) {

+				stbyBody.setValidFrom(DateHelper.getDateWithTime(date, DateHelper.getStartOfDay(date)));

+				this.createMsgExtendHoliday(stbyBody, date, false);

+				stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);

+			}

+		} else {

+			// no last duration for the day has been found. Therefore the start of day has

+			// been used for current entry

+			if (DateHelper.isDateBefore(DateHelper.getStartOfDay(date), stbyBody.getValidFrom())) {

+				stbyBody.setValidFrom(DateHelper.getDateWithTime(date, DateHelper.getStartOfDay(date)));

+				this.createMsgExtendHoliday(stbyBody, date, false);

+				stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);

+			}

+		}

+

+		return stbyBody;

+	}

+

+	/**

+	 * Method to change the standby time if a holiday / calendar day is defined and

+	 * the standby time has to be extended.

+	 * 

+	 * @param group

+	 * @param date

+	 * @param stbyBody

+	 * @return

+	 */

+	public StandbyScheduleBody calculateHolidayExtend(StandbyGroup group, Date date, StandbyScheduleBody stbyBody) {

+		List<StandbyDuration> lsDurations = this.getFittingDurationsOfGroup(group, date);

+		if (lsDurations != null) {

+			int size = lsDurations.size();

+			// loop forward to find fitting duration that starts after current schedule body

+			for (int a = 0; a < size; a++) {

+				StandbyDuration dur = lsDurations.get(a);

+				// proof if found duration starts after the end of current body.

+				if (dur != null && DateHelper.isDateAfter(DateHelper.getDateWithTime(date, dur.getValidFrom()),

+						stbyBody.getValidTo())) {

+					// set end time of current entry to the start of the next duration

+					stbyBody.setValidTo(DateHelper.getDateWithTime(date, dur.getValidFrom()));

+					stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);

+					this.createMsgExtendHoliday(stbyBody, date, true);

+					// end loop after first fitting result.

+					return stbyBody;

+				}

+			}

+			// no last duration for the day has been found. Therefore the start of day has

+			// been used for current entry

+			if (DateHelper.isDateAfter(DateHelper.getEndOfDay(date), stbyBody.getValidTo())) {

+				stbyBody.setValidTo(DateHelper.getDateWithTime(date, DateHelper.getEndOfDay(date)));

+				stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);

+				this.createMsgExtendHoliday(stbyBody, date, true);

+			}

+		} else {

+			// no last duration for the day has been found. Therefore the start of day has

+			// been used for current entry

+			if (DateHelper.isDateAfter(DateHelper.getEndOfDay(date), stbyBody.getValidTo())) {

+				stbyBody.setValidTo(DateHelper.getDateWithTime(date, DateHelper.getEndOfDay(date)));

+				stbyBody.setModifiedCause(TXT_AUTOMATIC_PLANNING_HOLIDAY);

+				this.createMsgExtendHoliday(stbyBody, date, true);

+			}

+		}

+		return stbyBody;

+	}

+

+	public PlanningBodyResultDto calculateScheduleBodyEntries(List<UserInStandbyGroup> lsUserInGroup, Date startDate,

+			Date currentDate, Date lastDate, int currentPosition, String username, Long lastStartUserId) {

+		StandbyGroup group = lsUserInGroup.get(0).getStandbyGroup();

+		PlanningBodyResultDto resultObj = new PlanningBodyResultDto();

+		List<StandbyDuration> lsFittingDurations = this.getFittingDurationsOfGroup(group, currentDate);

+

+		if (lsFittingDurations != null) {

+			for (StandbyDuration fittingDuration : lsFittingDurations) {

+				int startWeekDayInt = fittingDuration.getValidDayFrom();

+				int endWeekDayInt = fittingDuration.getValidDayTo();

+				int coveredDays = DateHelper.calculateDifferenceOfDays(startWeekDayInt, endWeekDayInt,

+						fittingDuration.getValidFrom(), fittingDuration.getValidTo());

+				if (coveredDays == 0) {

+					// single entry with no over night duration

+					LOGGER.debug("A day was found that just cover a single day.");

+					StandbyScheduleBody stbyBody = this.createScheduleBodyObject(group, username, currentDate,

+							lsUserInGroup.get(currentPosition).getUser(), fittingDuration, TXT_AUTOMATIC_PLANNING);

+					standbyScheduleBodyRepository.save(stbyBody);

+					// calculate if holiday

+					stbyBody = this.calculateHoliday(group, currentDate, stbyBody);

+					resultObj.getLsMsg().add(createMsgSavingBody(stbyBody));

+				} else {

+					resultObj = this.calculateMultiScheduleBodyEntries(lsUserInGroup, currentDate, lastDate,

+							currentPosition, username, fittingDuration, coveredDays);

+				}

+				resultObj.setCurrentDuration(fittingDuration);

+				currentPosition = this

+						.resetCounterToNewPosition(currentPosition, lastStartUserId, lsUserInGroup,

+								group.getNextUserInNextCycle(), fittingDuration.getNextUserInNextDuration())

+						.getNewPosition();

+			}

+			resultObj.setNewPosition(currentPosition);

+			resultObj.setTempDate(DateHelper.addDaysToDate(currentDate, 1));

+		} else {

+			resultObj.setTempDate(DateHelper.addDaysToDate(currentDate, 1));

+			resultObj.getLsMsg().add(this.createMsgNotAvailable(group, currentDate));

+		}

+		return resultObj;

+	}

+

+	public PlanningBodyResultDto calculateMultiScheduleBodyEntries(List<UserInStandbyGroup> lsUserInGroup,

+			Date currentDate, Date lastDate, int currentPosition, String username, StandbyDuration fittingDuration,

+			int coveredDays) {

+		PlanningBodyResultDto resultObj = new PlanningBodyResultDto();

+		Date nextDay = null;

+		// 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)) {

+				String warning = "Für das Datum (" + currentDate

+						+ ") wird kein Eintrag erzeugt, da der Folgetag den definierten Zeitraum überschereitet.";

+				resultObj.getLsMsg().add(new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN));

+				resultObj.setTempDate(nextDay);

+				resultObj.setNewPosition(currentPosition);

+				return resultObj;

+			} else {

+				List<StandbyScheduleBody> lsScheduleBodies = this.createOverlappingScheduleBodyObjects(

+						lsUserInGroup.get(0).getStandbyGroup(), username, currentDate,

+						lsUserInGroup.get(currentPosition).getUser(), fittingDuration, i, coveredDays);

+				for (StandbyScheduleBody stbyBody : lsScheduleBodies) {

+					standbyScheduleBodyRepository.save(stbyBody);

+					resultObj.getLsMsg().add(createMsgSavingBody(stbyBody));

+					resultObj.setTempDate(nextDay);

+				}

+				resultObj.setNewPosition(currentPosition);

+				resultObj.setTempDate(nextDay);

+				currentDate = resultObj.getTempDate();

+			}

+		}

+		return resultObj;

+	}

+

+	/**

+	 * Method to create a success message for saving an {@link StandbyScheduleBody}

+	 * object.

+	 * 

+	 * @param stbyBody

+	 * @return

+	 */

+	protected PlanningMsgDto createMsgSavingBody(StandbyScheduleBody stbyBody) {

+		String info = stbyBody.getUser().getFirstname() + " " + stbyBody.getUser().getLastname()

+				+ " wurde für den Zeitraum vom (" + stbyBody.getValidFrom() + ") bis zum (" + stbyBody.getValidTo()

+				+ ") eingeplant.";

+		PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO_ML3);

+		lsPlanningMsg.add(dto);

+		return dto;

+	}

+

+	/**

+	 * Method to create a success message for saving an {@link StandbyScheduleBody}

+	 * object.

+	 * 

+	 * @param stbyBody

+	 * @return

+	 */

+	protected PlanningMsgDto createMsgExtendHoliday(StandbyScheduleBody stbyBody, Date date, Boolean isExtendedDuty) {

+		StringBuilder strBuilder = new StringBuilder("Die Bereitschaftszeit für " + stbyBody.getUser().getFirstname()

+				+ " " + stbyBody.getUser().getLastname() + " muss am (" + date

+				+ ") auf Grund eines dienstfreien Tages");

+

+		if (isExtendedDuty) {

+			strBuilder.append(" verlängert werden.");

+		} else {

+			strBuilder.append(" vorgezogen werden.");

+		}

+

+		PlanningMsgDto dto = new PlanningMsgDto(strBuilder.toString(), PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);

+		lsPlanningMsg.add(dto);

+		return dto;

+	}

+

+	/**

+	 * Method to create a warning because of no given group for planning.

+	 * 

+	 * @param stbyBody

+	 * @return

+	 */

+	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 + ")";

+		LOGGER.warn(warning);

+		PlanningMsgDto dto = new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN);

+		lsPlanningMsg.add(dto);

+		return dto;

+	}

+

+	/**

+	 * Method to create a info message with the number of old deleted ScheduleBody

+	 * objects.

+	 * 

+	 * @param map

+	 * @param blueprintDto

+	 * @return

+	 */

+	protected PlanningMsgDto createMsgNumberOfPhases(Map<Integer, PlanningPhaseDto> map,

+			StandbyScheduleBlueprintDto blueprintDto) {

+		String info = "";

+		if (map.size() == 0) {

+			info = "Auf Grund fehlender Bereitschaften im gewählten Zeitraum, vom " + blueprintDto.getValidFrom()

+					+ " bis " + blueprintDto.getValidTo() + ", konnte keine Bereitschaftsphase generiert werden.";

+			LOGGER.info(info);

+			PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN);

+			lsPlanningMsg.add(dto);

+			return dto;

+		} else {

+			info = "Durch wechselnde Gruppenmitglieder wurde(n)  " + map.size()

+					+ " Bereitschaftsphase(n) für den angegebenen Zeitraum , vom " + blueprintDto.getValidFrom()

+					+ " bis " + blueprintDto.getValidTo() + ", erkannt.";

+			LOGGER.info(info);

+			PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);

+			lsPlanningMsg.add(dto);

+			return dto;

+		}

+

+	}

+

+	protected List<PlanningMsgDto> createMsgStartOfPhase(Integer phaseId, PlanningPhaseDto phase) {

+		List<PlanningMsgDto> lsMsgDto = new ArrayList<>();

+		String info = "Die Bereitschaftsphase (" + phaseId + ") wird jetzt für den Zeitraum vom ("

+				+ DateHelper.getStartOfDay(phase.getStartDate()) + ") bis zum ("

+				+ DateHelper.getStartOfDay(phase.getEndDate()) + ") berechnet";

+		LOGGER.info(info);

+		PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);

+		lsPlanningMsg.add(dto);

+		lsMsgDto.add(dto);

+

+		StringBuilder builder = new StringBuilder();

+		for (UserInStandbyGroup uisg : phase.getLsUsers()) {

+			User user = uisg.getUser();

+			String name = user.getFirstname() + " " + user.getLastname();

+			if (builder.toString().isEmpty()) {

+				builder.append(name);

+			} else {

+				builder.append(", " + name);

+			}

+		}

+		info = "Folgende Bereitschaftende werden verplant: " + builder.toString();

+		LOGGER.info(info);

+		dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);

+		lsPlanningMsg.add(dto);

+		lsMsgDto.add(dto);

+

+		return lsMsgDto;

+	}

+

+	protected PlanningMsgDto createMsgEndOfPhase(Integer phasenId) {

+		String info = "Die Berechnung der Bereitschaftsphase (" + phasenId + ") wurde abgeschlossen";

+		LOGGER.info(info);

+		PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);

+		lsPlanningMsg.add(dto);

+		return dto;

+	}

+

+	/**

+	 * Method to create a info message with the number of old deleted ScheduleBody

+	 * objects.

+	 * 

+	 * @param stbyBody

+	 * @return

+	 */

+	protected PlanningMsgDto createMsgLeaveOutStarter() {

+		String info = "Der letzte Starter wurde aufgrund des aktivierten Vorschubs übersprungen.";

+		LOGGER.info(info);

+		PlanningMsgDto dto = new PlanningMsgDto(info, PlanningMsgDto.INFO, PlanningMsgDto.CSS_INFO);

+		lsPlanningMsg.add(dto);

+		return dto;

+	}

+

+	/**

+	 * Method to create a info message with the number of old deleted ScheduleBody

+	 * objects.

+	 * 

+	 * @param stbyBody

+	 * @return

+	 */

+	protected PlanningMsgDto createMsgDeleteScheduleBodies(int numberOfElements) {

+		String warning = "Es wurden " + numberOfElements

+				+ " ältere Bereitschaften für den angegebenen Zeitraum entfernt.";

+		LOGGER.info(warning);

+		PlanningMsgDto dto = new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN);

+		lsPlanningMsg.add(dto);

+		return dto;

+	}

+

+	/**

+	 * Method to create a info message with the number of old deleted ScheduleBody

+	 * objects.

+	 * 

+	 * @param stbyBody

+	 * @return

+	 */

+	protected PlanningMsgDto createMsgGroupLeaderChanged(User user, List<UserInStandbyGroup> lsUserInStandbyGroup) {

+		User nextUser = lsUserInStandbyGroup.get(0).getUser();

+		String warning = "Die ausgewählte Start - Bereitschaft (" + user.getFirstname() + " " + user.getLastname()

+				+ ") ist im angebenen Zeitraum nicht aktiv. Es wird mit (" + nextUser.getFirstname() + " "

+				+ nextUser.getLastname() + ") begonnen.";

+		LOGGER.info(warning);

+		PlanningMsgDto dto = new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN);

+		lsPlanningMsg.add(dto);

+		return dto;

+	}

+

+	/**

+	 * Method to delete {@link StandbyScheduleBody} Objects by a list of id's.

+	 * 

+	 * @param lsIds

+	 * @return

+	 */

+	public PlanningMsgDto deleteScheduleBodiesByIds(List<Long> lsIds) throws SpException {

+		try {

+			for (Long id : lsIds) {

+				standbyScheduleBodyRepository.delete(id);

+			}

+			return createMsgDeleteScheduleBodies(lsIds.size());

+		} catch (Exception e) {

+			SpErrorEntry ee = SpExceptionEnum.COULD_NOT_DELETE_ENTITY_EXCEPTION.getEntry();

+			ee.setMessage(MessageFormat.format(ee.getMessage(), "StandbyScheduleBodies", e.getMessage()));

+			SpException spE = new SpException(ee);

+			LOGGER.error(spE, spE);

+			throw spE;

+		}

+	}

+

+	/**

+	 * Method to check if date is a defined value in calendar database.

+	 * 

+	 * @param date

+	 * @return

+	 */

+	public Boolean isHoliday(Date date, StandbyGroup group) {

+

+		List<CalendarDay> lsCalendarDays = calendarRepository.findValidByDate(DateHelper.getStartOfDay(date),

+				DateHelper.getEndOfDay(date));

+		if (lsCalendarDays != null && !lsCalendarDays.isEmpty()) {

+			List<CalendarDay> lsIgnoreList = group.getLsIgnoredCalendarDays();

+			for (CalendarDay day : lsCalendarDays) {

+				if (!lsIgnoreList.contains(day)) {

+					return true;

+				}

+			}

+			return false;

+		} else {

+			return false;

+		}

+	}

+

+	/**

+	 * Method to get the start duration time for the group.

+	 * 

+	 * @param group

+	 * @param date

+	 * @return null if no fitting duration is available

+	 */

+	public StandbyDuration getFittingDurationOfGroup(StandbyGroup group, Date date) {

+		List<StandbyDuration> lsDuration = this.getFittingDurationsOfGroup(group, date);

+		if (lsDuration != null && !lsDuration.isEmpty()) {

+			return lsDuration.get(0);

+		}

+		return null;

+	}

+

+	/**

+	 * Method to get the start duration time for the group.

+	 * 

+	 * @param group

+	 * @param date

+	 * @return null if no fitting duration is available

+	 */

+	public List<StandbyDuration> getFittingDurationsOfGroup(StandbyGroup group, Date date) {

+		int dayOfWeek = DateHelper.getDayOfWeek(date);

+		return standbyDurationRepository.findDurationForValidFromDay(group.getId(), dayOfWeek);

+	}

+

+	/**

+	 * Method to get the start duration time for the group.

+	 * 

+	 * @param group

+	 * @param date

+	 * @return null if no fitting duration is available

+	 */

+	public StandbyDuration getFittingDurationByValidTo(StandbyGroup group, Date date) {

+		List<StandbyDuration> lsDuration = this.getFittingDurationsByValidTo(group, date);

+		if (lsDuration != null && !lsDuration.isEmpty()) {

+			return lsDuration.get(lsDuration.size() - 1);

+		}

+		return null;

+	}

+

+	/**

+	 * Method to get a list of {@link StandbyDuration} by its end time for the

+	 * group.

+	 * 

+	 * @param group

+	 * @param date

+	 * @return null if no fitting duration is available

+	 */

+	public List<StandbyDuration> getFittingDurationsByValidTo(StandbyGroup group, Date endDate) {

+		int dayOfWeek = DateHelper.getDayOfWeek(endDate);

+		return standbyDurationRepository.findDurationForValidToDay(group.getId(), dayOfWeek);

+	}

+

+	/**

+	 * Method to set the currentPosition to 0 if end of list is reached.

+	 * 

+	 * @param currentPosition

+	 * @param listSize

+	 * @return

+	 */

+	public PlanningBodyResultDto resetCounterToNewPosition(int currentPosition, Long lastStartUserId,

+			List<UserInStandbyGroup> lsUserInGroup, Boolean isNextUserInNextCycle, Boolean isNextUserInNextDuration) {

+		LOGGER.debug("currentPosition: " + currentPosition);

+		LOGGER.debug("lastStartUserId: " + lastStartUserId);

+		LOGGER.debug("UserList Size: " + lsUserInGroup.size());

+

+		// default values

+		PlanningBodyResultDto result = new PlanningBodyResultDto();

+		result.setLastStartUserId(lastStartUserId);

+		result.setNewPosition(currentPosition);

+

+		if (isNextUserInNextDuration) {

+			// get next available position

+			currentPosition = this.getNextAvailablePosition(currentPosition, lsUserInGroup);

+			LOGGER.debug("next currentPosition is: " + currentPosition);

+			int lastIndex = this.getIndexOfLastPlannedUser(lastStartUserId, lsUserInGroup);

+			LOGGER.debug("lastIndexOf: " + lastIndex);

+			if (currentPosition == lastIndex) {

+				LOGGER.debug("start user found at current position " + currentPosition);

+				if (isNextUserInNextCycle) {

+					LOGGER.debug("Because of isNextUserInNextCycle = '" + isNextUserInNextCycle

+							+ "' next position will be searched...) ");

+					this.createMsgLeaveOutStarter();

+					currentPosition = this.getNextAvailablePosition(currentPosition, lsUserInGroup);

+					LOGGER.debug("next currentPosition is: " + currentPosition);

+					Long nextStartUserId = lsUserInGroup.get(currentPosition).getUser().getId();

+					result.setLastStartUserId(nextStartUserId);

+					LOGGER.debug("Next start user id is set to :" + nextStartUserId.longValue());

+				} else {

+					LOGGER.debug("Because of isNextUserInNextCycle = '" + isNextUserInNextCycle

+							+ "' currentPosition is still: " + currentPosition);

+				}

+			}

+		} else {

+			LOGGER.info("isNextUserInNextDuration == false. CurrentUser still in charge.");

+		}

+		result.setNewPosition(currentPosition);

+		return result;

+	}

+

+	/**

+	 * Method to calculate the next available position in array list. Starts with

+	 * the first on if list has reached the end.

+	 * 

+	 * @param currentPosition

+	 * @param lsUserInGroup

+	 * @return

+	 */

+	public int getNextAvailablePosition(int currentPosition, List<UserInStandbyGroup> lsUserInGroup) {

+		if (currentPosition + 1 < lsUserInGroup.size()) {

+			return currentPosition + 1;

+		} else {

+			return 0;

+		}

+	}

+

+	/**

+	 * Method to get the position of the last planned user. Returns back '-1' if not

+	 * found in given list.

+	 * 

+	 * @param currentPosition

+	 * @param listSize

+	 * @return

+	 */

+	public int getIndexOfLastPlannedUser(Long lastStartUserId, List<UserInStandbyGroup> lsUserInGroup) {

+		int indexOf = -1;

+		for (UserInStandbyGroup userInGroup : lsUserInGroup) {

+			if (userInGroup.getUser().getId().longValue() == lastStartUserId.longValue()) {

+				indexOf = lsUserInGroup.indexOf(userInGroup);

+				return indexOf;

+			}

+		}

+		return indexOf;

+	}

+

+	/**

+	 * Method to validate the input parameter for the planning.

+	 * 

+	 * @param standbyBlueprintDto

+	 * @return

+	 * @throws SpException

+	 */

+	public boolean validateInputForPlanCalculation(StandbyScheduleBlueprintDto standbyBlueprintDto) throws SpException {

+		if (standbyBlueprintDto.getStandbyListId() != null) {

+			if (!standbyListRepository.exists(standbyBlueprintDto.getStandbyListId())) {

+				SpErrorEntry ee = SpExceptionEnum.UNKNOWN_ENTITY_EXCEPTION.getEntry();

+				String txt = MessageFormat.format(SpMsg.TXT_STANDBY_LIST_WITH_ID,

+						standbyBlueprintDto.getStandbyListId());

+				ee.setMessage(MessageFormat.format(ee.getMessage(), txt));

+				SpException spE = new SpException(ee);

+				LOGGER.error(spE, spE);

+				throw spE;

+			}

+		} else {

+			SpErrorEntry ee = SpExceptionEnum.MISSING_PARAMETER_EXCEPTION.getEntry();

+			ee.setMessage(MessageFormat.format(ee.getMessage(), "StandbyList"));

+			SpException spE = new SpException(ee);

+			LOGGER.error(spE, spE);

+			throw spE;

+		}

+

+		if (standbyBlueprintDto.getStandbyGroupId() != null) {

+			if (!standbyGroupRepository.exists(standbyBlueprintDto.getStandbyGroupId())) {

+				SpErrorEntry ee = SpExceptionEnum.UNKNOWN_ENTITY_EXCEPTION.getEntry();

+				String txt = MessageFormat.format(SpMsg.TXT_STANDBY_GROUP_WITH_ID,

+						standbyBlueprintDto.getStandbyGroupId());

+				ee.setMessage(MessageFormat.format(ee.getMessage(), txt));

+				SpException spE = new SpException(ee);

+				LOGGER.error(spE, spE);

+				throw spE;

+			}

+		} else {

+			SpErrorEntry ee = SpExceptionEnum.MISSING_PARAMETER_EXCEPTION.getEntry();

+			ee.setMessage(MessageFormat.format(ee.getMessage(), "StandbyGroup"));

+			SpException spE = new SpException(ee);

+			LOGGER.error(spE, spE);

+			throw spE;

+		}

+

+		if (standbyBlueprintDto.getValidFrom() == null) {

+			SpErrorEntry ee = SpExceptionEnum.MISSING_PARAMETER_EXCEPTION.getEntry();

+			ee.setMessage(MessageFormat.format(ee.getMessage(), "validFrom"));

+			SpException spE = new SpException(ee);

+			LOGGER.error(spE, spE);

+			throw spE;

+		}

+

+		if (standbyBlueprintDto.getValidTo() == null) {

+			SpErrorEntry ee = SpExceptionEnum.MISSING_PARAMETER_EXCEPTION.getEntry();

+			ee.setMessage(MessageFormat.format(ee.getMessage(), "validTo"));

+			SpException spE = new SpException(ee);

+			LOGGER.error(spE, spE);

+			throw spE;

+		}

+

+		return true;

+	}

+

+	/**

+	 * Method to log the phase map object.

+	 * 

+	 * @param resultMap

+	 */

+	public void logPhases(Map<Integer, PlanningPhaseDto> resultMap) {

+		LOGGER.debug("The following " + resultMap.keySet().size() + " had been found");

+		for (Entry<Integer, PlanningPhaseDto> entry : resultMap.entrySet()) {

+			LOGGER.debug("-----------------------");

+			LOGGER.debug("Phase :" + entry.getKey());

+			LOGGER.debug("-----------------------");

+			PlanningPhaseDto dto = entry.getValue();

+			LOGGER.debug("StartDate :" + dto.getStartDate());

+			LOGGER.debug("EndDate :" + dto.getEndDate());

+			LOGGER.debug("Number of StandbyUser :" + dto.getLsUsers().size());

+			for (UserInStandbyGroup uisg : dto.getLsUsers()) {

+				LOGGER.debug("Gruppenmitglied :" + uisg.getUser().getFirstname() + " " + uisg.getUser().getLastname());

+			}

+		}

+	}

+

+	/**

+	 * Method to replace user in schedule bodies for the given interval

+	 * 

+	 * @param actionDto

+	 * @param username

+	 * @return

+	 * @throws SpException

+	 */

+	public PlanningMsgResponseDto replaceUserInPlan(StandbyScheduleActionDto actionDto, String username)

+			throws SpException {

+		PlanningMsgResponseDto responseDto = new PlanningMsgResponseDto();

+

+		// check input values

+		List<Object> lsInputParams = new ArrayList<>();

+		lsInputParams.add(actionDto.getCurrentUserId());

+		lsInputParams.add(actionDto.getNewUserId());

+		lsInputParams.add(actionDto.getStandbyGroupId());

+		lsInputParams.add(actionDto.getStatusId());

+		lsInputParams.add(actionDto.getValidFrom());

+		lsInputParams.add(actionDto.getValidTo());

+		lsInputParams.add(username);

+		ValidationHelper.isNoNullValueInList(lsInputParams);

+

+		try {

+

+			// history

+			archiveController.createArchiveOnReplaceInOneGroup(actionDto, username);

+

+			User currentUser = userRepository.findOne(actionDto.getCurrentUserId());

+			User newUser = userRepository.findOne(actionDto.getNewUserId());

+			StandbyGroup standbyGroup = standbyGroupRepository.findOne(actionDto.getStandbyGroupId());

+			Date from = actionDto.getValidFrom();

+			Date to = actionDto.getValidTo();

+

+			// mail

+			mailing.replaceMessage1(actionDto, currentUser, newUser, standbyGroup);

+			mailing.replaceMessage2(actionDto, currentUser, newUser, standbyGroup);

+

+			ArrayList<StandbyGroup> lsStandbyGroups = new ArrayList<>();

+			List<StandbyScheduleBody> lsBodies = standbyScheduleBodyRepository.findByUserAndGroupAndDateAndStatus(

+					currentUser.getId(), actionDto.getStandbyGroupId(), DateHelper.getStartOfDay(from),

+					DateHelper.getEndOfDay(to), actionDto.getStatusId());

+

+			for (StandbyScheduleBody body : lsBodies) {

+				this.splitScheduleBody(body, from, to, newUser, username);

+				if (!lsStandbyGroups.contains(body.getStandbyGroup())) {

+					lsStandbyGroups.add(body.getStandbyGroup());

+				}

+			}

+

+			// start validation

+			List<String> lsValidationBeanNames = new ArrayList<>();

+			lsValidationBeanNames.add(ValidationController.BEAN_USER_AVAILABLE_VALIDATOR);

+			lsValidationBeanNames.add(ValidationController.BEAN_USER_AVAILABLE_FOR_GROUP_VALIDATOR);

+			lsValidationBeanNames.add(ValidationController.BEAN_GROUP_COVERAGE_VALIDATOR);

+			lsValidationBeanNames.add(ValidationController.BEAN_DOUBLE_PLANNED_VALIDATOR);

+			lsValidationBeanNames.add(ValidationController.BEAN_PLACEHOLDER_STANDBY_USER_VALIDATOR);

+

+			responseDto.getLsMsg()

+					.addAll(validatonController.startValidation(actionDto.getValidFrom(), actionDto.getValidTo(),

+							lsStandbyGroups, lsValidationBeanNames, actionDto.getStatusId(), actionDto.getNewUserId()));

+

+			return responseDto;

+		} catch (Exception e) {

+			LOGGER.error(e, e);

+			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();

+			ee.setE(e);

+			throw new SpException(ee);

+		}

+	}

+

+	protected Boolean splitScheduleBody(StandbyScheduleBody body, Date from, Date to, User newUser, String modifiedBy)

+			throws SpException {

+		try {

+			Date tmpFrom = from;

+			Date tmpTo = to;

+			if (DateHelper.isDateBefore(from, DateHelper.getStartOfDay(body.getValidFrom()))) {

+				tmpFrom = DateHelper.getStartOfDay(body.getValidFrom());

+			}

+

+			if (DateHelper.isDateAfter(to, DateHelper.getEndOfDay(body.getValidFrom()))) {

+				tmpTo = DateHelper.getEndOfDay(body.getValidFrom());

+			}

+

+			// interval of ui params

+			Interval intervalSelection = new Interval(new DateTime(tmpFrom).getMillis(),

+					new DateTime(tmpTo).getMillis());

+

+			// interval of saved schedule body

+			Interval intervalBody = new Interval(new DateTime(body.getValidFrom()).getMillis(),

+					new DateTime(body.getValidTo()).getMillis());

+

+			// overlapping interval between params and schedule body values

+			Interval intervalOverlap = intervalBody.overlap(intervalSelection);

+

+			if (intervalOverlap != null) {

+				int isSameStart = DateHelper.isSameDateTime(body.getValidFrom(), tmpFrom);

+				int isSameEnd = DateHelper.isSameDateTime(body.getValidTo(), tmpTo);

+

+				tmpFrom = intervalOverlap.getStart().toDate();

+				tmpTo = intervalOverlap.getEnd().toDate();

+				if (isSameStart >= 0) {

+					if (isSameEnd == 0) {

+						// full replace

+						body.setUser(newUser);

+						body.setModifiedCause(TXT_MANUAL_CHANGE);

+						body.setModificationDate(new Date());

+						body.setModifiedBy(modifiedBy);

+						standbyScheduleBodyRepository.save(body);

+					} else if (isSameEnd < 0) {

+						body.setUser(newUser);

+						body.setModifiedCause(TXT_MANUAL_CHANGE);

+						body.setModificationDate(new Date());

+						body.setModifiedBy(modifiedBy);

+						body.setValidTo(tmpTo);

+						standbyScheduleBodyRepository.save(body);

+					} else {

+						StandbyScheduleBody newBody = body.copy();

+						newBody.setUser(newUser);

+						newBody.setModifiedCause(TXT_MANUAL_CHANGE);

+						newBody.setModificationDate(new Date());

+						newBody.setModifiedBy(modifiedBy);

+						newBody.setValidTo(tmpTo);

+						standbyScheduleBodyRepository.save(newBody);

+

+						body.setValidFrom(tmpTo);

+						body.setModifiedCause(TXT_MANUAL_CHANGE);

+						body.setModificationDate(new Date());

+						body.setModifiedBy(modifiedBy);

+						standbyScheduleBodyRepository.save(body);

+					}

+				} else if (isSameEnd == 0) {

+					StandbyScheduleBody newBody = body.copy();

+					newBody.setUser(newUser);

+					newBody.setModifiedCause(TXT_MANUAL_CHANGE);

+					newBody.setModificationDate(new Date());

+					newBody.setModifiedBy(modifiedBy);

+					newBody.setValidFrom(tmpFrom);

+					standbyScheduleBodyRepository.save(newBody);

+

+					body.setValidTo(tmpFrom);

+					body.setModifiedCause(TXT_MANUAL_CHANGE);

+					body.setModificationDate(new Date());

+					body.setModifiedBy(modifiedBy);

+					standbyScheduleBodyRepository.save(body);

+				} else if (isSameEnd < 0) {

+					// replace with end at 23:59

+					StandbyScheduleBody newBody = body.copy();

+					newBody.setUser(newUser);

+					newBody.setModifiedCause(TXT_MANUAL_CHANGE);

+					newBody.setModificationDate(new Date());

+					newBody.setModifiedBy(modifiedBy);

+					newBody.setValidFrom(tmpFrom);

+					newBody.setValidTo(tmpTo);

+					standbyScheduleBodyRepository.save(newBody);

+

+					body.setModifiedCause(TXT_MANUAL_CHANGE);

+					body.setModificationDate(new Date());

+					body.setModifiedBy(modifiedBy);

+					body.setValidTo(tmpFrom);

+					standbyScheduleBodyRepository.save(body);

+				} else {

+					// set new user (n1) between old (o1) existing entry by splitting it.

+					// Looks like this [o1--n1--o2]

+					StandbyScheduleBody newBody = body.copy();

+					newBody.setUser(newUser);

+					newBody.setModifiedCause(TXT_MANUAL_CHANGE);

+					newBody.setModificationDate(new Date());

+					newBody.setModifiedBy(modifiedBy);

+					newBody.setValidFrom(tmpFrom);

+					newBody.setValidTo(tmpTo);

+					standbyScheduleBodyRepository.save(newBody);

+

+					// set new entry to not loose the time after

+					StandbyScheduleBody oldBodyAfter = body.copy();

+					oldBodyAfter.setModifiedCause(TXT_MANUAL_CHANGE);

+					oldBodyAfter.setModificationDate(new Date());

+					oldBodyAfter.setModifiedBy(modifiedBy);

+					oldBodyAfter.setValidFrom(tmpTo);

+					standbyScheduleBodyRepository.save(oldBodyAfter);

+

+					// set

+					body.setModifiedCause(TXT_MANUAL_CHANGE);

+					body.setModificationDate(new Date());

+					body.setModifiedBy(modifiedBy);

+					body.setValidTo(tmpFrom);

+					standbyScheduleBodyRepository.save(body);

+				}

+			}

+

+			return true;

+		} catch (Exception e) {

+			LOGGER.error(e, e);

+			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();

+			ee.setE(e);

+			throw new SpException(ee);

+		}

+	}

+

+	/**

+	 * Method to change the time of a schedule body.

+	 * 

+	 * @param actionDto

+	 * @param username

+	 * @return

+	 * @throws SpException

+	 */

+	public PlanningMsgResponseDto moveUserInPlan(StandbyScheduleActionDto actionDto, String username)

+			throws SpException {

+		PlanningMsgResponseDto responseDto = new PlanningMsgResponseDto();

+

+		// check input values

+		List<Object> lsInputParams = new ArrayList<>();

+		lsInputParams.add(actionDto.getNewUserId());

+		lsInputParams.add(actionDto.getScheduleBodyId());

+		lsInputParams.add(actionDto.getValidFrom());

+		lsInputParams.add(actionDto.getValidTo());

+		lsInputParams.add(actionDto.getStandbyGroupId());

+		lsInputParams.add(username);

+		ValidationHelper.isNoNullValueInList(lsInputParams);

+

+		StandbyGroup tempOldGroup = null;

+		StandbyGroup tempNewGroup = null;

+

+		try {

+

+			// history

+			archiveController.createArchiveOnMove(actionDto, username);

+

+			StandbyScheduleBody body = standbyScheduleBodyRepository.findOne(actionDto.getScheduleBodyId());

+			tempNewGroup = standbyGroupRepository.findOne(actionDto.getStandbyGroupId());

+

+			// mail

+			mailing.moveMessage1(actionDto, body, tempNewGroup);

+

+			tempOldGroup = body.getStandbyGroup();

+			body.setModifiedCause(SpMsg.ACT_STANDBY_MOVE);

+			body.setModificationDate(new Date());

+			body.setModifiedBy(username);

+			body.setStandbyGroup(tempNewGroup);

+

+			if (DateHelper.isSameDate(actionDto.getValidFrom(), actionDto.getValidTo())) {

+				// because of no overlapping day schedule body just

+				// gets new values, no second body is needed.

+				body.setValidFrom(actionDto.getValidFrom());

+				body.setValidTo(actionDto.getValidTo());

+				standbyScheduleBodyRepository.save(body);

+

+			} else {

+				Date nextDate = actionDto.getValidFrom();

+				StandbyScheduleBody newBody = null;

+				while (DateHelper.isDateBefore(nextDate, actionDto.getValidTo())

+						&& !DateHelper.isSameDate(nextDate, actionDto.getValidTo())) {

+					newBody = body.copy();

+					if (DateHelper.isSameDate(actionDto.getValidFrom(), nextDate)) {

+						// do not change start time on first day

+						newBody.setValidFrom(nextDate);

+					} else {

+						// begin with = 0:00 if not first day

+						newBody.setValidFrom(DateHelper.getStartOfDay(nextDate));

+					}

+					newBody.setValidTo(DateHelper.getEndOfDay(nextDate));

+					newBody.setModifiedCause(TXT_MANUAL_CHANGE);

+					newBody.setModificationDate(new Date());

+					newBody.setModifiedBy(username);

+					newBody.setStandbyGroup(body.getStandbyGroup());

+					standbyScheduleBodyRepository.save(newBody);

+

+					nextDate = DateHelper.addDaysToDate(nextDate, 1);

+				}

+

+				// add last day

+				StandbyScheduleBody lastBody = body.copy();

+				lastBody.setValidFrom(DateHelper.getStartOfDay(actionDto.getValidTo()));

+				lastBody.setValidTo(actionDto.getValidTo());

+				lastBody.setModifiedCause(TXT_MANUAL_CHANGE);

+				lastBody.setModificationDate(new Date());

+				lastBody.setModifiedBy(username);

+				lastBody.setStandbyGroup(body.getStandbyGroup());

+				standbyScheduleBodyRepository.save(lastBody);

+

+				// remove original because of splitting it to multiple entries

+				standbyScheduleBodyRepository.delete(body.getId());

+			}

+

+			ArrayList<StandbyGroup> lsStandbyGroups = new ArrayList<>();

+			lsStandbyGroups.add(tempOldGroup);

+			// add new group to check list if it differs from origin group

+			if (tempOldGroup.getId().longValue() != tempNewGroup.getId().longValue()) {

+				lsStandbyGroups.add(tempNewGroup);

+			}

+

+			// start validation

+			List<String> lsValidationBeanNames = new ArrayList<>();

+			lsValidationBeanNames.add(ValidationController.BEAN_USER_AVAILABLE_VALIDATOR);

+			lsValidationBeanNames.add(ValidationController.BEAN_USER_AVAILABLE_FOR_GROUP_VALIDATOR);

+			lsValidationBeanNames.add(ValidationController.BEAN_GROUP_COVERAGE_VALIDATOR);

+			lsValidationBeanNames.add(ValidationController.BEAN_DOUBLE_PLANNED_VALIDATOR);

+			lsValidationBeanNames.add(ValidationController.BEAN_PLACEHOLDER_STANDBY_USER_VALIDATOR);

+			responseDto.getLsMsg()

+					.addAll(validatonController.startValidation(actionDto.getValidFrom(), actionDto.getValidTo(),

+							lsStandbyGroups, lsValidationBeanNames, actionDto.getStatusId(), actionDto.getNewUserId()));

+

+			return responseDto;

+		} catch (Exception e) {

+			LOGGER.error(e, e);

+			SpErrorEntry ee = SpExceptionEnum.DEFAULT_EXCEPTION.getEntry();

+			ee.setE(e);

+			throw new SpException(ee);

+		}

+	}

+}

diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/IValidator.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/IValidator.java
index d59fa4c..7f5089c 100644
--- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/IValidator.java
+++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/IValidator.java
@@ -27,5 +27,5 @@
 public interface IValidator {
 
 	List<PlanningMsgDto> execute(Date from, Date till, StandbyGroup currentGroup, List<StandbyGroup> lsStandbyGroups,
-			Long statusId) throws SpException;
+			Long statusId, Long userId) throws SpException;
 }
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/ValidationController.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/ValidationController.java
index c6ff2a8..11e53eb 100644
--- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/ValidationController.java
+++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/ValidationController.java
@@ -30,7 +30,6 @@
 import org.eclipse.openk.sp.dto.ValidationDto;
 import org.eclipse.openk.sp.dto.planning.PlanningMsgDto;
 import org.eclipse.openk.sp.dto.planning.PlanningMsgResponseDto;
-import org.eclipse.openk.sp.dto.planning.StandbyScheduleActionDto;
 import org.eclipse.openk.sp.exceptions.SpErrorEntry;
 import org.eclipse.openk.sp.exceptions.SpException;
 import org.eclipse.openk.sp.exceptions.SpExceptionEnum;
@@ -44,6 +43,8 @@
 /** Class to handle planning operations. */
 public class ValidationController extends AbstractController {
 	protected static final Logger LOGGER = Logger.getLogger(ValidationController.class);
+	public static final String BEAN_USER_AVAILABLE_VALIDATOR = "userAvailableValidator";
+	public static final String BEAN_USER_AVAILABLE_FOR_GROUP_VALIDATOR = "userAvailableForGroupValidator";
 	public static final String BEAN_GROUP_COVERAGE_VALIDATOR = "groupCoverageValidator";
 	public static final String BEAN_DOUBLE_PLANNED_VALIDATOR = "doublePlannedValidator";
 	public static final String BEAN_PLACEHOLDER_STANDBY_USER_VALIDATOR = "placeholderStandbyUserValidator";
@@ -67,7 +68,7 @@
 	private StandbyStatusRepository standbyStatusRepository;
 
 	public List<PlanningMsgDto> startValidation(Date from, Date till, List<StandbyGroup> lsStandbyGroups,
-			List<String> lsValidationBeanNames, Long statusId) throws SpException {
+			List<String> lsValidationBeanNames, Long statusId, Long userId) throws SpException {
 		List<PlanningMsgDto> lsMsgDto = new ArrayList<>();
 		try {
 			lsMsgDto.addAll(ValidationMsgController.createMsgStartValidation(from, till, lsStandbyGroups));
@@ -79,12 +80,12 @@
 							for (StandbyStatus stbyStatus : standbyStatusRepository.findAll()) {
 								// check for given status
 								lsMsgDto.addAll(((IValidator) appContext.getBean(beanName)).execute(from, till, group,
-										lsStandbyGroups, stbyStatus.getId()));
+										lsStandbyGroups, stbyStatus.getId(), userId));
 							}
 						} else {
 							// check for given status
 							lsMsgDto.addAll(((IValidator) appContext.getBean(beanName)).execute(from, till, group,
-									lsStandbyGroups, statusId));
+									lsStandbyGroups, statusId, userId));
 						}
 					}
 				}
@@ -123,7 +124,7 @@
 			lsValidationBeanNames.add(ValidationController.BEAN_DOUBLE_PLANNED_VALIDATOR);
 			lsValidationBeanNames.add(ValidationController.BEAN_PLACEHOLDER_STANDBY_USER_VALIDATOR);
 			responseDto.getLsMsg().addAll(this.startValidation(validatonDto.getValidFrom(), validatonDto.getValidTo(),
-					lsStandbyGroups, lsValidationBeanNames, validatonDto.getStatusId()));
+					lsStandbyGroups, lsValidationBeanNames, validatonDto.getStatusId(), validatonDto.getNewUserId()));
 			return responseDto;
 		} catch (SpException e) {
 			throw e;
@@ -134,27 +135,4 @@
 			throw new SpException(ee);
 		}
 	}
-
-	public List<PlanningMsgDto> validatePlanningActionInput(StandbyScheduleActionDto actionDto) throws SpException {
-		PlanningMsgResponseDto responseDto = new PlanningMsgResponseDto();
-		// check if user is valid for interval
-		Boolean isValid = userController.isUserValid(actionDto.getNewUserId(), actionDto.getValidFrom(),
-				actionDto.getValidTo());
-		if (!isValid) {
-			responseDto.getLsMsg().addAll(ValidationMsgController
-					.createMsgInvalidTimeForUser(userRepository.findOne(actionDto.getNewUserId())));
-		}
-
-		// check if user is in selected group
-		isValid = userController.isUserInGroup(actionDto.getNewUserId(), actionDto.getStandbyGroupId(),
-				actionDto.getValidFrom(), actionDto.getValidTo());
-		if (!isValid) {
-			responseDto.getLsMsg()
-					.addAll(ValidationMsgController.createMsgInvalidGroupForUser(
-							userRepository.findOne(actionDto.getNewUserId()),
-							standbyGroupRepository.findOne(actionDto.getStandbyGroupId())));
-		}
-
-		return responseDto.getLsMsg();
-	}
 }
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/DoublePlannedValidator.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/DoublePlannedValidator.java
index 90182f7..dacdc4f 100644
--- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/DoublePlannedValidator.java
+++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/DoublePlannedValidator.java
@@ -41,7 +41,7 @@
 
 	@Override
 	public List<PlanningMsgDto> execute(Date from, Date till, StandbyGroup currentGroup,
-			List<StandbyGroup> lsStandbyGroups, Long statusId) throws SpException {
+			List<StandbyGroup> lsStandbyGroups, Long statusId, Long userId) throws SpException {
 		List<PlanningMsgDto> planningMsgDtos = new ArrayList<>();
 
 		// fetch all active schedule bodies
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/GroupCoverageValidator.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/GroupCoverageValidator.java
index af77aad..87b3f1d 100644
--- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/GroupCoverageValidator.java
+++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/GroupCoverageValidator.java
@@ -48,7 +48,7 @@
 
 	@Override
 	public List<PlanningMsgDto> execute(Date from, Date till, StandbyGroup currentGroup,
-			List<StandbyGroup> lsStandbyGroups, Long statusId) throws SpException {
+			List<StandbyGroup> lsStandbyGroups, Long statusId, Long userId) throws SpException {
 		List<PlanningMsgDto> planningMsgDtos = new ArrayList<>();
 
 		Date tempDate = from;
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/PlaceholderStandbyUserValidator.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/PlaceholderStandbyUserValidator.java
index e8de3e2..78ea12d 100644
--- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/PlaceholderStandbyUserValidator.java
+++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/PlaceholderStandbyUserValidator.java
@@ -49,7 +49,7 @@
 
 	@Override
 	public List<PlanningMsgDto> execute(Date from, Date till, StandbyGroup currentGroup,
-			List<StandbyGroup> lsStandbyGroups, Long statusId) throws SpException {
+			List<StandbyGroup> lsStandbyGroups, Long statusId, Long userId) throws SpException {
 		List<PlanningMsgDto> planningMsgDtos = new ArrayList<>();
 
 		try {
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableForGroupValidator.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableForGroupValidator.java
new file mode 100644
index 0000000..9257433
--- /dev/null
+++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableForGroupValidator.java
@@ -0,0 +1,62 @@
+/********************************************************************************
+ * Copyright (c) 2018 Mettenmeier GmbH 
+ *
+ * See the NOTICE file(s) distributed with this work for additional 
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the 
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0 
+ ********************************************************************************/
+package org.eclipse.openk.sp.controller.validation.validator;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.eclipse.openk.sp.controller.AbstractController;
+import org.eclipse.openk.sp.controller.UserController;
+import org.eclipse.openk.sp.controller.msg.ValidationMsgController;
+import org.eclipse.openk.sp.controller.validation.IValidator;
+import org.eclipse.openk.sp.db.dao.StandbyGroupRepository;
+import org.eclipse.openk.sp.db.dao.UserRepository;
+import org.eclipse.openk.sp.db.model.StandbyGroup;
+import org.eclipse.openk.sp.dto.planning.PlanningMsgDto;
+import org.eclipse.openk.sp.exceptions.SpException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional(rollbackFor = Exception.class)
+/** Class to validate if all time slots are set for a group. */
+public class UserAvailableForGroupValidator extends AbstractController implements IValidator {
+	protected static final Logger LOGGER = Logger.getLogger(UserAvailableForGroupValidator.class);
+
+	@Autowired
+	private UserController userController;
+
+	@Autowired
+	private StandbyGroupRepository standbyGroupRepository;
+
+	@Autowired
+	private UserRepository userRepository;
+
+	@Override
+	public List<PlanningMsgDto> execute(Date from, Date till, StandbyGroup currentGroup,
+			List<StandbyGroup> lsStandbyGroups, Long statusId, Long userId) throws SpException {
+		List<PlanningMsgDto> planningMsgDtos = new ArrayList<>();
+
+		// check if user is in selected group
+		Boolean isValid = userController.isUserInGroup(userId, currentGroup.getId(), from, till);
+		if (!isValid) {
+			planningMsgDtos.addAll(ValidationMsgController.createMsgInvalidGroupForUser(userRepository.findOne(userId),
+					standbyGroupRepository.findOne(currentGroup.getId())));
+		}
+
+		return planningMsgDtos;
+	}
+}
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableValidator.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableValidator.java
new file mode 100644
index 0000000..cd49046
--- /dev/null
+++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableValidator.java
@@ -0,0 +1,55 @@
+/********************************************************************************
+ * Copyright (c) 2018 Mettenmeier GmbH 
+ *
+ * See the NOTICE file(s) distributed with this work for additional 
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the 
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0 
+ ********************************************************************************/
+package org.eclipse.openk.sp.controller.validation.validator;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.eclipse.openk.sp.controller.AbstractController;
+import org.eclipse.openk.sp.controller.UserController;
+import org.eclipse.openk.sp.controller.msg.ValidationMsgController;
+import org.eclipse.openk.sp.controller.validation.IValidator;
+import org.eclipse.openk.sp.db.dao.UserRepository;
+import org.eclipse.openk.sp.db.model.StandbyGroup;
+import org.eclipse.openk.sp.dto.planning.PlanningMsgDto;
+import org.eclipse.openk.sp.exceptions.SpException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional(rollbackFor = Exception.class)
+/** Class to validate if all time slots are set for a group. */
+public class UserAvailableValidator extends AbstractController implements IValidator {
+	protected static final Logger LOGGER = Logger.getLogger(UserAvailableValidator.class);
+
+	@Autowired
+	private UserController userController;
+
+	@Autowired
+	private UserRepository userRepository;
+
+	@Override
+	public List<PlanningMsgDto> execute(Date from, Date till, StandbyGroup currentGroup,
+			List<StandbyGroup> lsStandbyGroups, Long statusId, Long userId) throws SpException {
+		List<PlanningMsgDto> planningMsgDtos = new ArrayList<>();
+
+		Boolean isValid = userController.isUserValid(userId, from, till);
+		if (!isValid) {
+			planningMsgDtos.addAll(ValidationMsgController.createMsgInvalidTimeForUser(userRepository.findOne(userId)));
+		}
+		return planningMsgDtos;
+	}
+}
diff --git a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/StandbyGroupControllerTest.java b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/StandbyGroupControllerTest.java
index 6d41380..c318c6d 100644
--- a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/StandbyGroupControllerTest.java
+++ b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/StandbyGroupControllerTest.java
@@ -429,7 +429,7 @@
 		when(standbyGroupRepository.exists(Mockito.anyLong())).thenReturn(true);
 		when(standbyDurationRepository.exists(Mockito.anyLong())).thenReturn(false);
 		when(validationController.startValidation(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),
-				Mockito.any())).thenReturn(new ArrayList<PlanningMsgDto>());
+				Mockito.any(), Mockito.any())).thenReturn(new ArrayList<PlanningMsgDto>());
 
 		when(entityConverter.convertEntityToDtoList((List<AbstractEntity>) any(), (List<AbstractDto>) any(), any()))
 				.thenReturn(lsDtos);
diff --git a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/planning/BodyDataCopyControllerTest.java b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/planning/BodyDataCopyControllerTest.java
index 522a629..4a6086b 100644
--- a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/planning/BodyDataCopyControllerTest.java
+++ b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/planning/BodyDataCopyControllerTest.java
@@ -475,7 +475,8 @@
 		when(archiveController.createArchiveForIntervallAndGroups(any(), any(), any(), any(), any(), any(), any()))
 				.thenReturn(true);
 
-		when(validationController.startValidation(any(), any(), any(), any(), any())).thenReturn(new ArrayList<>());
+		when(validationController.startValidation(any(), any(), any(), any(), any(), any()))
+				.thenReturn(new ArrayList<>());
 
 		result = bodyDataCopyController.copyByGroups(standbyScheduleCopyDto, modUserName);
 		assertNotNull(result);
@@ -695,7 +696,8 @@
 		when(archiveController.createArchiveForIntervallAndGroups(any(), any(), any(), any(), any(), any(), any()))
 				.thenReturn(true);
 
-		when(validationController.startValidation(any(), any(), any(), any(), any())).thenReturn(new ArrayList<>());
+		when(validationController.startValidation(any(), any(), any(), any(), any(), any()))
+				.thenReturn(new ArrayList<>());
 
 		result = bodyDataCopyController.deleteByGroups(standbyScheduleCopyDto, modUserName);
 		assertNotNull(result);
diff --git a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/planning/PlanningControllerTest.java b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/planning/PlanningControllerTest.java
index 3651522..9cce919 100644
--- a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/planning/PlanningControllerTest.java
+++ b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/planning/PlanningControllerTest.java
@@ -1,1199 +1,1200 @@
-/********************************************************************************
- * Copyright (c) 2018 Mettenmeier GmbH 
- *
- * See the NOTICE file(s) distributed with this work for additional 
- * information regarding copyright ownership.
- *
- * This program and the accompanying materials are made available under the 
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0 
- ********************************************************************************/
-package org.eclipse.openk.sp.controller.planning;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.eclipse.openk.sp.controller.UserController;
-import org.eclipse.openk.sp.controller.validation.ValidationController;
-import org.eclipse.openk.sp.db.dao.CalendarRepository;
-import org.eclipse.openk.sp.db.dao.StandbyDurationRepository;
-import org.eclipse.openk.sp.db.dao.StandbyGroupRepository;
-import org.eclipse.openk.sp.db.dao.StandbyListRepository;
-import org.eclipse.openk.sp.db.dao.StandbyScheduleBodyRepository;
-import org.eclipse.openk.sp.db.dao.StandbyStatusRepository;
-import org.eclipse.openk.sp.db.dao.UserInStandbyGroupRepository;
-import org.eclipse.openk.sp.db.dao.UserRepository;
-import org.eclipse.openk.sp.db.model.CalendarDay;
-import org.eclipse.openk.sp.db.model.StandbyDuration;
-import org.eclipse.openk.sp.db.model.StandbyGroup;
-import org.eclipse.openk.sp.db.model.StandbyScheduleBody;
-import org.eclipse.openk.sp.db.model.StandbyStatus;
-import org.eclipse.openk.sp.db.model.User;
-import org.eclipse.openk.sp.db.model.UserInStandbyGroup;
-import org.eclipse.openk.sp.dto.StandbyScheduleBlueprintDto;
-import org.eclipse.openk.sp.dto.planning.PlanningBodyResultDto;
-import org.eclipse.openk.sp.dto.planning.PlanningMsgDto;
-import org.eclipse.openk.sp.dto.planning.PlanningPhaseDto;
-import org.eclipse.openk.sp.dto.planning.StandbyScheduleActionDto;
-import org.eclipse.openk.sp.exceptions.SpException;
-import org.eclipse.openk.sp.mail.MailRequest;
-import org.eclipse.openk.sp.util.DateHelper;
-import org.eclipse.openk.sp.util.SpMsg;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.Spy;
-import org.mockito.runners.MockitoJUnitRunner;
-
-@RunWith(MockitoJUnitRunner.class)
-public class PlanningControllerTest extends PlanningController {
-	protected static final Logger LOGGER = Logger.getLogger(PlanningControllerTest.class);
-
-	private static final String ERROR_MSG_MISSING_ENTITY = "Eines der folgenden Entities kann nicht gefunden werden:";
-	private static final String ERROR_MSG_STANDBYLIST = "Es fehlt der folgendende Einagebeparameter : StandbyList";
-	private static final String ERROR_MSG_STANDBYGROUP = "Es fehlt der folgendende Einagebeparameter : StandbyGroup";
-	private static final String ERROR_MSG_VALID_FROM = "Es fehlt der folgendende Einagebeparameter : validFrom";
-	private static final String ERROR_MSG_VALID_TO = "Es fehlt der folgendende Einagebeparameter : validTo";
-
-	@InjectMocks
-	@Spy
-	PlanningController planningController;
-
-	@Mock
-	private StandbyGroupRepository standbyGroupRepository;
-
-	@Mock
-	private StandbyListRepository standbyListRepository;
-
-	@Mock
-	private StandbyDurationRepository standbyDurationRepository;
-
-	@Mock
-	private StandbyStatusRepository standbyStatusRepository;
-
-	@Mock
-	private StandbyScheduleBodyRepository standbyScheduleBodyRepository;
-
-	@Mock
-	private UserRepository userRepository;
-
-	@Mock
-	private CalendarRepository calendarRepository;
-
-	@Mock
-	private UserController userController;
-
-	@Mock
-	private ValidationController validationController;
-
-	@Mock
-	private ArchiveController archiveController;
-
-	@Mock
-	private MailRequest mailRequest;
-
-	@Mock
-	private UserInStandbyGroupRepository uisgRepository;
-
-	@Test
-	public void calculatePlanTest() throws SpException {
-		assertNotNull(new Boolean(true));
-	}
-
-	@Test
-	public void startPlanningTest() throws SpException {
-		String username = "JUnit";
-		StandbyScheduleBlueprintDto standbyBlueprintDto = new StandbyScheduleBlueprintDto();
-		standbyBlueprintDto.setStandbyGroupId(1L);
-		standbyBlueprintDto.setStandbyListId(1L);
-		standbyBlueprintDto.setStartIdOfUser(1L);
-		standbyBlueprintDto.setValidFrom(DateHelper.getDate(2018, 1, 1, 8, 0, 0));
-		standbyBlueprintDto.setValidTo(DateHelper.getDate(2018, 1, 1, 16, 0, 0));
-
-		List<UserInStandbyGroup> lsUserInStandbyGroup = new ArrayList<>();
-		User user1 = new User();
-		user1.setFirstname("J.");
-		user1.setLastname("Unit");
-		UserInStandbyGroup uisg = new UserInStandbyGroup();
-		uisg.setUser(user1);
-
-		Map<Integer, PlanningPhaseDto> planningPhaseMap = new HashMap<>();
-		PlanningPhaseDto planningPhaseDto = new PlanningPhaseDto();
-		planningPhaseDto.setStartDate(DateHelper.getDate(2018, 1, 1, 0, 0, 0));
-		planningPhaseDto.setEndDate(DateHelper.getDate(2018, 1, 31, 0, 0, 0));
-		planningPhaseDto.setLsUsers(lsUserInStandbyGroup);
-		planningPhaseMap.put(1, planningPhaseDto);
-
-		try {
-			// success test 01 - validInput
-			Mockito.doReturn(true).when(planningController).validateInputForPlanCalculation(standbyBlueprintDto);
-			Mockito.doReturn(planningPhaseMap).when(planningController).calculatePlanningPhaseMap(standbyBlueprintDto);
-			Mockito.doNothing().when(planningController).calculatePlanForPhase(Mockito.any(), Mockito.any(),
-					Mockito.any());
-			planningController.startPlanning(standbyBlueprintDto, username);
-
-			// success test 02 - invalidInput
-			Mockito.doReturn(false).when(planningController).validateInputForPlanCalculation(standbyBlueprintDto);
-			Mockito.doReturn(planningPhaseMap).when(planningController).calculatePlanningPhaseMap(standbyBlueprintDto);
-			Mockito.doNothing().when(planningController).calculatePlanForPhase(Mockito.any(), Mockito.any(),
-					Mockito.any());
-			planningController.startPlanning(standbyBlueprintDto, username);
-		} catch (SpException e) {
-			assertNull(e);
-		}
-
-		// negative test 01
-		try {
-			Mockito.doThrow(new SpException()).when(planningController)
-					.validateInputForPlanCalculation(standbyBlueprintDto);
-			planningController.startPlanning(standbyBlueprintDto, username);
-		} catch (SpException e) {
-			assertNotNull(e);
-		}
-
-		// negative test 02
-		try {
-			Mockito.doThrow(new IllegalArgumentException()).when(standbyGroupRepository).findOne(Mockito.any());
-			planningController.startPlanning(standbyBlueprintDto, username);
-		} catch (SpException e) {
-			assertNotNull(e);
-		}
-	}
-
-	@Test
-	public void calculatePlanForPhaseTest() {
-		PlanningPhaseDto dto = new PlanningPhaseDto();
-		List<UserInStandbyGroup> lsUserInStandbyGroup = this.getTestDataForUserInStandbyGroups();
-		dto.setLsUsers(lsUserInStandbyGroup);
-
-		dto.setStartDate(new Date());
-		dto.setEndDate(DateHelper.addDaysToDate(new Date(), 7));
-		Long lastStartUserId = 1L;
-		String username = "JUnit";
-
-		when(standbyScheduleBodyRepository.save(Mockito.any(StandbyScheduleBody.class)))
-				.thenReturn(new StandbyScheduleBody());
-
-		when(userRepository.findOne(Mockito.any())).thenReturn(lsUserInStandbyGroup.get(0).getUser());
-
-		Mockito.doNothing().when(planningController).changeOrDeleteExistingBodies(Mockito.any(), Mockito.any(),
-				Mockito.any(), Mockito.any(), Mockito.any());
-
-		try {
-			planningController.calculatePlanForPhase(dto, lastStartUserId, username);
-		} catch (Exception e) {
-			LOGGER.error(e, e);
-			assertNull(e);
-		}
-	}
-
-	@Test
-	public void calculatePlanningPhaseMapTest() {
-		Map<Integer, PlanningPhaseDto> planningPhaseMap = new HashMap<>();
-		StandbyScheduleBlueprintDto standbyBlueprintDto = new StandbyScheduleBlueprintDto();
-		standbyBlueprintDto.setStandbyGroupId(1L);
-		standbyBlueprintDto.setStandbyListId(1L);
-		standbyBlueprintDto.setStartIdOfUser(1L);
-		standbyBlueprintDto.setValidFrom(DateHelper.getDate(2018, 1, 1, 8, 0, 0));
-		standbyBlueprintDto.setValidTo(DateHelper.getDate(2018, 1, 9, 16, 0, 0));
-
-		List<UserInStandbyGroup> lsUserInStandbyGroupsEmpty = new ArrayList<>();
-		List<UserInStandbyGroup> lsUserInStandbyGroups = new ArrayList<>();
-		UserInStandbyGroup uisg = new UserInStandbyGroup();
-		User user = new User();
-		uisg.setUser(user);
-		lsUserInStandbyGroups.add(uisg);
-		user = new User();
-		uisg.setUser(user);
-		lsUserInStandbyGroups.add(uisg);
-
-		try {
-			// [SUCCESS] returning null list for lsUserInGroup
-			when(uisgRepository.findUserForInterval(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(null);
-			planningPhaseMap = planningController.calculatePlanningPhaseMap(standbyBlueprintDto);
-			assertNotNull(planningPhaseMap);
-			assertTrue(planningPhaseMap.isEmpty());
-
-			// [SUCCESS] returning empty list for lsUserInGroup
-			when(uisgRepository.findUserForInterval(Mockito.any(), Mockito.any(), Mockito.any()))
-					.thenReturn(lsUserInStandbyGroupsEmpty);
-			planningPhaseMap = planningController.calculatePlanningPhaseMap(standbyBlueprintDto);
-			assertNotNull(planningPhaseMap);
-			assertTrue(planningPhaseMap.isEmpty());
-
-			// [SUCCESS] returning list for lsUserInGroup
-			when(uisgRepository.findUserForInterval(Mockito.any(), Mockito.any(), Mockito.any()))
-					.thenReturn(lsUserInStandbyGroups);
-			planningPhaseMap = planningController.calculatePlanningPhaseMap(standbyBlueprintDto);
-			assertNotNull(planningPhaseMap);
-			assertFalse(planningPhaseMap.isEmpty());
-
-		} catch (Exception e) {
-			LOGGER.error(e, e);
-			assertNull(e);
-		}
-	}
-
-	@Test
-	public void createScheduleBodyEntryTest() {
-		Date currentDate = new Date();
-		Date lastDate = new Date();
-		int currentPosition = 0;
-		String username = "JUnit";
-		Long lastUserId = 1L;
-		List<UserInStandbyGroup> lsUserInStandbyGroup = this.getTestDataForUserInStandbyGroups();
-
-		List<StandbyDuration> lsDuration = new ArrayList<>();
-		StandbyDuration dur = new StandbyDuration();
-		dur.setId(1L);
-		dur.setNextUserInNextDuration(true);
-		dur.setValidDayFrom(1);
-		dur.setValidDayTo(1);
-		dur.setValidFrom(DateHelper.getDate(2018, 10, 1));
-		dur.setValidFrom(DateHelper.getDate(2018, 10, 31));
-		lsDuration.add(dur);
-
-		when(standbyDurationRepository.findDurationForValidFromDay(Mockito.any(), Mockito.any()))
-				.thenReturn(lsDuration);
-		when(standbyScheduleBodyRepository.save(Mockito.any(StandbyScheduleBody.class)))
-				.thenReturn(new StandbyScheduleBody());
-
-		// covered days = 1
-		try {
-			PlanningBodyResultDto dto = planningController.calculateScheduleBodyEntries(lsUserInStandbyGroup,
-					currentDate, lastDate, currentPosition, username, lastUserId);
-			assertNotNull(dto);
-		} catch (Exception e) {
-			assertNotNull(e);
-		}
-
-		// covered days > 1
-		lsDuration.get(0).setValidDayTo(3);
-		lastDate = DateHelper.addDaysToDate(new Date(), 5);
-		try {
-			PlanningBodyResultDto dto = planningController.calculateScheduleBodyEntries(lsUserInStandbyGroup,
-					currentDate, lastDate, currentPosition, username, lastUserId);
-			assertNotNull(dto);
-		} catch (Exception e) {
-			assertNotNull(e);
-		}
-
-		// date after current
-		try {
-			currentDate = DateHelper.addDaysToDate(new Date(), 1);
-			lastDate = DateHelper.addDaysToDate(new Date(), 1);
-			PlanningBodyResultDto dto = planningController.calculateScheduleBodyEntries(lsUserInStandbyGroup,
-					currentDate, lastDate, currentPosition, username, lastUserId);
-			assertNotNull(dto);
-		} catch (Exception e) {
-			assertNotNull(e);
-		}
-
-		// fitting duration = false
-		when(standbyDurationRepository.findDurationForValidFromDay(Mockito.any(), Mockito.any())).thenReturn(null);
-		try {
-			PlanningBodyResultDto dto = planningController.calculateScheduleBodyEntries(lsUserInStandbyGroup,
-					currentDate, lastDate, currentPosition, username, lastUserId);
-			assertNotNull(dto);
-			assertTrue(
-					dto.getLsMsg().get(0).getMsg().contains("wurde kein aktiver Zeitraum für folgenden Tag gefunden"));
-		} catch (Exception e) {
-			assertNotNull(e);
-		}
-	}
-
-	public PlanningBodyResultDto calculateScheduleBodyEntries(List<UserInStandbyGroup> lsUserInGroup, Date currentDate,
-			Date lastDate, int currentPosition, String username) {
-		StandbyGroup group = lsUserInGroup.get(0).getStandbyGroup();
-		PlanningBodyResultDto resultObj = new PlanningBodyResultDto();
-		StandbyDuration fittingDuration = this.getFittingDurationOfGroup(group, currentDate);
-		if (fittingDuration != null) {
-			int intStartDay = fittingDuration.getValidDayFrom();
-			int intEndDay = fittingDuration.getValidDayTo();
-			int coveredDays = DateHelper.calculateDifferenceOfDays(intStartDay, intEndDay, new Date(), new Date());
-			Date nextDay = null;
-
-			if (coveredDays == 0) {
-				// single entry with no over night duration
-				LOGGER.debug("A day was found that just cover a single day.");
-				StandbyScheduleBody stbyBody = this.createScheduleBodyObject(group, username, currentDate,
-						lsUserInGroup.get(currentPosition).getUser(), fittingDuration,
-						PlanningController.TXT_AUTOMATIC_PLANNING);
-				standbyScheduleBodyRepository.save(stbyBody);
-				resultObj.getLsMsg().add(createMsgSavingBody(stbyBody));
-			} else {
-				// 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)) {
-						String warning = "Für das Datum (" + currentDate
-								+ ") wird kein Eintrag erzeugt, da der Folgetag den definierten Zeitraum überschereitet.";
-						resultObj.getLsMsg()
-								.add(new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN));
-						resultObj.setTempDate(nextDay);
-						resultObj.setNewPosition(currentPosition);
-						return resultObj;
-					} else {
-						List<StandbyScheduleBody> lsScheduleBodies = this.createOverlappingScheduleBodyObjects(group,
-								username, currentDate, lsUserInGroup.get(currentPosition).getUser(), fittingDuration, i,
-								coveredDays);
-						for (StandbyScheduleBody stbyBody : lsScheduleBodies) {
-							standbyScheduleBodyRepository.save(stbyBody);
-							resultObj.getLsMsg().add(createMsgSavingBody(stbyBody));
-							resultObj.setTempDate(nextDay);
-						}
-						resultObj.setNewPosition(currentPosition);
-						resultObj.setTempDate(nextDay);
-						currentDate = resultObj.getTempDate();
-					}
-				}
-			}
-			resultObj.setTempDate(nextDay);
-			resultObj.setCurrentDuration(fittingDuration);
-		} else {
-			resultObj.setTempDate(DateHelper.addDaysToDate(currentDate, 1));
-			resultObj.getLsMsg().add(this.createMsgNotAvailable(group, currentDate));
-		}
-		return resultObj;
-	}
-
-	@Test
-	public void createMsgExtendHolidayTest() {
-		StandbyScheduleBody stbyBody = new StandbyScheduleBody();
-		User user = new User();
-		user.setFirstname("J.");
-		user.setLastname("Unit");
-		stbyBody.setUser(user);
-		Date date = new Date();
-		Boolean isStandbyTimeExtension = true;
-
-		// positive test - extend
-		PlanningMsgDto dto = planningController.createMsgExtendHoliday(stbyBody, date, isStandbyTimeExtension);
-		assertNotNull(dto);
-		assertTrue(dto.getMsg().endsWith("verlängert werden."));
-
-		// negative test - pre
-		isStandbyTimeExtension = false;
-		dto = planningController.createMsgExtendHoliday(stbyBody, date, isStandbyTimeExtension);
-		assertNotNull(dto);
-		assertTrue(dto.getMsg().endsWith("vorgezogen werden."));
-	}
-
-	@Test
-	public void createMsgStartOfPhaseTest() {
-		List<UserInStandbyGroup> lsUserInStandbyGroup = this.getTestDataForUserInStandbyGroups();
-		Integer phaseId = 1;
-		PlanningPhaseDto phase = new PlanningPhaseDto();
-		phase.setEndDate(new Date());
-		phase.setStartDate(new Date());
-		phase.setLsUsers(lsUserInStandbyGroup);
-		try {
-			List<PlanningMsgDto> lsMsgDto = planningController.createMsgStartOfPhase(phaseId, phase);
-			assertNotNull(lsMsgDto);
-		} catch (Exception e) {
-			assertNull(e);
-		}
-	}
-
-	@Test
-	public void createMsgEndOfPhaseTest() {
-		Integer phaseId = 1;
-		PlanningMsgDto msgDto = planningController.createMsgEndOfPhase(phaseId);
-		assertNotNull(msgDto);
-	}
-
-	@Test
-	public void createMsgSavingBodyTest() {
-		StandbyScheduleBody stbyBody = new StandbyScheduleBody();
-		User user = new User();
-		user.setFirstname("J.");
-		user.setLastname("Unit");
-		stbyBody.setUser(user);
-		stbyBody.setValidFrom(new Date());
-		stbyBody.setValidTo(new Date());
-		PlanningMsgDto msgDto = planningController.createMsgSavingBody(stbyBody);
-		assertNotNull(msgDto);
-	}
-
-	@Test
-	public void createMsgNotAvailableTest() {
-		StandbyGroup group = new StandbyGroup();
-		group.setTitle("Test");
-		Date currentDate = new Date();
-		PlanningMsgDto msgDto = planningController.createMsgNotAvailable(group, currentDate);
-		assertNotNull(msgDto);
-	}
-
-	@Test
-	public void createMsgNumberOfPhasesTest() {
-		Map<Integer, PlanningPhaseDto> map = new HashMap<>();
-		map.put(1, new PlanningPhaseDto());
-		map.put(2, new PlanningPhaseDto());
-
-		StandbyScheduleBlueprintDto dto = new StandbyScheduleBlueprintDto();
-		dto.setValidFrom(new Date());
-		dto.setValidTo(new Date());
-
-		// success
-		PlanningMsgDto msgDto = planningController.createMsgNumberOfPhases(map, dto);
-		assertNotNull(msgDto);
-		assertTrue(msgDto.getMsg().startsWith("Durch wechselnde Gruppenmitglieder wurde(n)"));
-
-		// empty map
-		map = new HashMap<>();
-		msgDto = planningController.createMsgNumberOfPhases(map, dto);
-		assertNotNull(msgDto);
-		assertTrue(msgDto.getMsg().startsWith("Auf Grund fehlender Bereitschaften im gewählten Zeitraum,"));
-	}
-
-	@Test
-	public void createMsgGroupLeaderChangedTest() {
-		List<UserInStandbyGroup> lsUserInStandbyGroup = new ArrayList<UserInStandbyGroup>();
-		UserInStandbyGroup uisg = new UserInStandbyGroup();
-		User nextUser = new User();
-		nextUser.setFirstname("Next");
-		nextUser.setLastname("User");
-		uisg.setUser(nextUser);
-		lsUserInStandbyGroup.add(uisg);
-
-		User user = new User();
-		user.setFirstname("J.");
-		user.setLastname("Unit");
-		PlanningMsgDto msgDto = planningController.createMsgGroupLeaderChanged(user, lsUserInStandbyGroup);
-		assertNotNull(msgDto);
-	}
-
-	@Test
-	public void deleteScheduleBodiesByIdsTest() {
-
-		List<Long> lsIds = new ArrayList<>();
-		lsIds.add(1L);
-		lsIds.add(2L);
-
-		Mockito.doNothing().when(standbyScheduleBodyRepository).delete(1L);
-		try {
-			planningController.deleteScheduleBodiesByIds(lsIds);
-		} catch (Exception e) {
-			assertNull(e);
-		}
-
-		lsIds.add(3L);
-		Mockito.doThrow(new IllegalArgumentException()).when(standbyScheduleBodyRepository).delete(3L);
-		try {
-			planningController.deleteScheduleBodiesByIds(lsIds);
-		} catch (SpException e) {
-			assertNotNull(e);
-		}
-	}
-
-	@Test
-	public void validateInputForPlanCalculationTest() {
-		StandbyScheduleBlueprintDto standbyBlueprintDto = new StandbyScheduleBlueprintDto();
-		// [FAIL] TEST INVALID LIST : EMPTY
-		try {
-			planningController.validateInputForPlanCalculation(standbyBlueprintDto);
-		} catch (SpException e) {
-			assertNotNull(e);
-			assertEquals(ERROR_MSG_STANDBYLIST, e.getMessage());
-		}
-
-		// [FAIL] TEST INVALID LIST : UNKOWN ENTITY
-		when(standbyListRepository.exists(Mockito.anyLong())).thenReturn(false);
-		standbyBlueprintDto.setStandbyListId(1l);
-		try {
-			planningController.validateInputForPlanCalculation(standbyBlueprintDto);
-		} catch (SpException e) {
-			assertNotNull(e);
-			assertTrue(e.getMessage().startsWith(ERROR_MSG_MISSING_ENTITY));
-		}
-
-		// [FAIL] TEST INVALID GROUP : EMPTY
-		when(standbyListRepository.exists(Mockito.anyLong())).thenReturn(true);
-		standbyBlueprintDto.setStandbyListId(1l);
-		try {
-			planningController.validateInputForPlanCalculation(standbyBlueprintDto);
-		} catch (SpException e) {
-			assertNotNull(e);
-			assertEquals(ERROR_MSG_STANDBYGROUP, e.getMessage());
-		}
-
-		// [FAIL] TEST INVALID GROUP : UNKOWN ENTITY
-		when(standbyGroupRepository.exists(Mockito.anyLong())).thenReturn(false);
-		standbyBlueprintDto.setStandbyGroupId(1l);
-		try {
-			planningController.validateInputForPlanCalculation(standbyBlueprintDto);
-		} catch (SpException e) {
-			assertNotNull(e);
-			assertTrue(e.getMessage().startsWith(ERROR_MSG_MISSING_ENTITY));
-		}
-
-		// [FAIL] TEST INVALID VALID FROM : EMPTY
-		when(standbyGroupRepository.exists(Mockito.anyLong())).thenReturn(true);
-		try {
-			planningController.validateInputForPlanCalculation(standbyBlueprintDto);
-		} catch (SpException e) {
-			assertNotNull(e);
-			assertEquals(ERROR_MSG_VALID_FROM, e.getMessage());
-		}
-
-		// [FAIL] TEST INVALID VALID TO : EMPTY
-		standbyBlueprintDto.setValidFrom(new Date());
-		try {
-			planningController.validateInputForPlanCalculation(standbyBlueprintDto);
-		} catch (SpException e) {
-			assertNotNull(e);
-			assertEquals(ERROR_MSG_VALID_TO, e.getMessage());
-		}
-
-		// [SUCCESS] TEST VALID
-		standbyBlueprintDto.setValidTo(new Date());
-		try {
-			Boolean result = planningController.validateInputForPlanCalculation(standbyBlueprintDto);
-			assertTrue(result);
-		} catch (SpException e) {
-			assertNull(e);
-		}
-	}
-
-	@Test
-	public void isHolidayTest() {
-		StandbyGroup group = new StandbyGroup();
-
-		List<CalendarDay> lsCalendarDays = null;
-
-		// negative test - null value
-		when(calendarRepository.findValidByDate(Mockito.any(), Mockito.any())).thenReturn(lsCalendarDays);
-		Boolean result = planningController.isHoliday(new Date(), group);
-		assertTrue(!result);
-
-		// negative test - empty list
-		lsCalendarDays = new ArrayList<>();
-		when(calendarRepository.findValidByDate(Mockito.any(), Mockito.any())).thenReturn(lsCalendarDays);
-		result = planningController.isHoliday(new Date(), group);
-		assertTrue(!result);
-
-		// negative test - object in Ignore List
-		CalendarDay cal = new CalendarDay();
-		lsCalendarDays.add(cal);
-		when(calendarRepository.findValidByDate(Mockito.any(), Mockito.any())).thenReturn(lsCalendarDays);
-		group.getLsIgnoredCalendarDays().add(cal);
-		result = planningController.isHoliday(new Date(), group);
-		assertTrue(!result);
-
-		// positiv test
-		when(calendarRepository.findValidByDate(Mockito.any(), Mockito.any())).thenReturn(lsCalendarDays);
-		group.getLsIgnoredCalendarDays().remove(cal);
-		result = planningController.isHoliday(new Date(), group);
-		assertTrue(result);
-	}
-
-	@Test
-	public void getFittingDurationOfGroupTest() {
-		StandbyGroup group = new StandbyGroup();
-		Date date = new Date();
-		List<StandbyDuration> lsDuration = new ArrayList<>();
-		StandbyDuration result = null;
-
-		when(standbyDurationRepository.findDurationForValidFromDay(Mockito.any(), Mockito.any()))
-				.thenReturn(lsDuration);
-
-		// success
-		lsDuration.add(new StandbyDuration());
-		result = planningController.getFittingDurationOfGroup(group, date);
-		assertNotNull(result);
-
-		// failure
-		lsDuration = new ArrayList<>();
-		when(standbyDurationRepository.findDurationForValidFromDay(Mockito.any(), Mockito.any()))
-				.thenReturn(lsDuration);
-		result = planningController.getFittingDurationOfGroup(group, date);
-		assertNull(result);
-
-		when(standbyDurationRepository.findDurationForValidFromDay(Mockito.any(), Mockito.any())).thenReturn(null);
-		result = planningController.getFittingDurationOfGroup(group, date);
-		assertNull(result);
-
-	}
-
-	@Test
-	public void getFittingDurationByValidToTest() {
-		StandbyGroup group = new StandbyGroup();
-		Date date = new Date();
-		List<StandbyDuration> lsDuration = new ArrayList<>();
-		StandbyDuration result = null;
-
-		when(standbyDurationRepository.findDurationForValidToDay(Mockito.any(), Mockito.any())).thenReturn(lsDuration);
-
-		// success
-		lsDuration.add(new StandbyDuration());
-		result = planningController.getFittingDurationByValidTo(group, date);
-		assertNotNull(result);
-
-		// failure
-		lsDuration = new ArrayList<>();
-		when(standbyDurationRepository.findDurationForValidToDay(Mockito.any(), Mockito.any())).thenReturn(lsDuration);
-		result = planningController.getFittingDurationByValidTo(group, date);
-		assertNull(result);
-
-		when(standbyDurationRepository.findDurationForValidToDay(Mockito.any(), Mockito.any())).thenReturn(null);
-		result = planningController.getFittingDurationByValidTo(group, date);
-		assertNull(result);
-
-	}
-
-	@Test
-	public void resetCounterToNewPositionTest() {
-		int currentPosition = 0;
-		Long lastStartUserId = 1L;
-		List<UserInStandbyGroup> lsUserInGroup = new ArrayList<>();
-		UserInStandbyGroup uisg = new UserInStandbyGroup();
-		User user = new User();
-		user.setId(1L);
-		uisg.setUser(user);
-		lsUserInGroup.add(uisg);
-
-		uisg = new UserInStandbyGroup();
-		user = new User();
-		user.setId(2L);
-		uisg.setUser(user);
-		lsUserInGroup.add(uisg);
-
-		uisg = new UserInStandbyGroup();
-		user = new User();
-		user.setId(3L);
-		uisg.setUser(user);
-		lsUserInGroup.add(uisg);
-
-		Boolean isNextUserInNextCycle = false;
-		Boolean isNextUserInDuration = true;
-
-		PlanningBodyResultDto response = null;
-		response = planningController.resetCounterToNewPosition(currentPosition, lastStartUserId, lsUserInGroup,
-				isNextUserInNextCycle, isNextUserInDuration);
-		currentPosition = response.getNewPosition();
-		assertTrue(currentPosition == 1);
-
-		// not start user
-		response = planningController.resetCounterToNewPosition(1, 2L, lsUserInGroup, isNextUserInNextCycle,
-				isNextUserInDuration);
-		currentPosition = response.getNewPosition();
-		assertTrue(currentPosition == 2);
-
-		// test start from beginning because list ends
-		response = planningController.resetCounterToNewPosition(2, 2L, lsUserInGroup, isNextUserInNextCycle,
-				isNextUserInDuration);
-		currentPosition = response.getNewPosition();
-		assertTrue(currentPosition == 0);
-
-		// user at position but isNextUserInNextCycle = false
-		response = planningController.resetCounterToNewPosition(0, 2L, lsUserInGroup, isNextUserInNextCycle,
-				isNextUserInDuration);
-		currentPosition = response.getNewPosition();
-		assertTrue(currentPosition == 1);
-
-		// skip position because user at position and isNextUserInNextCycle = true
-		isNextUserInNextCycle = true;
-		response = planningController.resetCounterToNewPosition(0, 2L, lsUserInGroup, isNextUserInNextCycle,
-				isNextUserInDuration);
-		currentPosition = response.getNewPosition();
-		assertTrue(currentPosition == 2);
-
-		// next user in duration = false
-		isNextUserInDuration = false;
-		response = planningController.resetCounterToNewPosition(0, 2L, lsUserInGroup, isNextUserInNextCycle,
-				isNextUserInDuration);
-		currentPosition = response.getNewPosition();
-		assertTrue(currentPosition == 0);
-
-	}
-
-	@Test
-	public void getNextAvailablePositionTest() {
-		int currentPosition = 0;
-		List<UserInStandbyGroup> lsUserInGroup = new ArrayList<>();
-		lsUserInGroup.add(new UserInStandbyGroup());
-		lsUserInGroup.add(new UserInStandbyGroup());
-
-		currentPosition = planningController.getNextAvailablePosition(currentPosition, lsUserInGroup);
-		assertTrue(currentPosition == 1);
-
-		// start at first position because of end of list.
-		currentPosition = planningController.getNextAvailablePosition(currentPosition, lsUserInGroup);
-		assertTrue(currentPosition == 0);
-	}
-
-	@Test
-	public void getIndexOfLastPlannedUserTest() {
-		Long lastStartUserId = 1L;
-		List<UserInStandbyGroup> lsUserInGroup = new ArrayList<>();
-		UserInStandbyGroup uisg = new UserInStandbyGroup();
-		User user = new User();
-		user.setId(1L);
-		uisg.setUser(user);
-		lsUserInGroup.add(uisg);
-
-		uisg = new UserInStandbyGroup();
-		user = new User();
-		user.setId(2L);
-		uisg.setUser(user);
-		lsUserInGroup.add(uisg);
-
-		uisg = new UserInStandbyGroup();
-		user = new User();
-		user.setId(3L);
-		uisg.setUser(user);
-		lsUserInGroup.add(uisg);
-
-		int result = -1;
-		result = planningController.getIndexOfLastPlannedUser(lastStartUserId, lsUserInGroup);
-		assertTrue(result == 0);
-
-		lastStartUserId = 3L;
-		result = planningController.getIndexOfLastPlannedUser(lastStartUserId, lsUserInGroup);
-		assertTrue(result == 2);
-
-		lastStartUserId = 4L;
-		result = planningController.getIndexOfLastPlannedUser(lastStartUserId, lsUserInGroup);
-		assertTrue(result == -1);
-	}
-
-	@Test
-	public void logPhasesTest() {
-		try {
-			Map<Integer, PlanningPhaseDto> resultMap = new HashMap<>();
-			List<UserInStandbyGroup> lsUserInStandbyGroups = new ArrayList<>();
-			UserInStandbyGroup uisg = new UserInStandbyGroup();
-			uisg.setId(1l);
-			uisg.setStandbyGroup(new StandbyGroup());
-			User user = new User();
-			user.setFirstname("J.");
-			user.setLastname("Unit");
-			uisg.setUser(user);
-			lsUserInStandbyGroups.add(uisg);
-			user = new User();
-			user.setFirstname("Nr.");
-			user.setLastname("Zwei");
-			uisg.setUser(user);
-			lsUserInStandbyGroups.add(uisg);
-			PlanningPhaseDto dto = new PlanningPhaseDto(new Date(), new Date(), lsUserInStandbyGroups);
-			resultMap.put(1, dto);
-
-			planningController.logPhases(resultMap);
-		} catch (Exception e) {
-			assertNull(e);
-		}
-	}
-
-	@Test
-	public void replaceUserInPlanTest() {
-
-		StandbyScheduleActionDto actionDto = new StandbyScheduleActionDto();
-		actionDto.setCurrentUserId(1L);
-		actionDto.setNewUserId(2L);
-		actionDto.setScheduleBodyId(1L);
-		actionDto.setStandbyGroupId(1L);
-		actionDto.setStatusId(1L);
-		actionDto.setValidFrom(new Date());
-		actionDto.setValidTo(new Date());
-		String username = "JUnit";
-
-		List<StandbyScheduleBody> lsStandbyScheduleBodies = new ArrayList<>();
-		lsStandbyScheduleBodies.add(new StandbyScheduleBody());
-
-		when(standbyScheduleBodyRepository.findByUserAndGroupAndDateAndStatus(Mockito.anyLong(), Mockito.anyLong(),
-				Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(lsStandbyScheduleBodies);
-		when(standbyStatusRepository.findOne(Mockito.any())).thenReturn(new StandbyStatus());
-		when(userRepository.findOne(Mockito.any())).thenReturn(new User());
-		when(userRepository.findOne(Mockito.any())).thenReturn(new User());
-		when(standbyScheduleBodyRepository.save(Mockito.any(StandbyScheduleBody.class)))
-				.thenReturn(new StandbyScheduleBody());
-
-		// success
-		try {
-			when(userController.isUserInGroup(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), Mockito.any()))
-					.thenReturn(true);
-			planningController.replaceUserInPlan(actionDto, username);
-		} catch (Exception e) {
-			assertNull(e);
-		}
-
-		// test error handling
-		Mockito.doThrow(new IllegalArgumentException()).when(userRepository).findOne(Mockito.any());
-		try {
-			planningController.replaceUserInPlan(actionDto, username);
-		} catch (Exception e) {
-			assertNotNull(e);
-		}
-	}
-
-	@Test
-	public void splitScheduleBodyTest() {
-		Date defaultStartDate = DateHelper.getDate(2018, 10, 1, 16, 0, 0);
-		Date defaultEndDate = DateHelper.getDate(2018, 10, 1, 22, 0, 0);
-		Date defaultEndDateOverlapping = DateHelper.getDate(2018, 10, 2, 8, 0, 0);
-
-		StandbyScheduleBody body = new StandbyScheduleBody();
-		body.setValidFrom(defaultStartDate);
-		body.setValidTo(defaultStartDate);
-		Date from = defaultStartDate;
-		Date to = defaultStartDate;
-		User newUser = new User();
-		String modifiedBy = "JUnit";
-
-		// negative test - null pointer
-		try {
-			StandbyScheduleBody bodyNull = null;
-			planningController.splitScheduleBody(bodyNull, from, to, newUser, modifiedBy);
-		} catch (SpException e) {
-			assertNotNull(e);
-		}
-
-		// positive tests
-		when(standbyScheduleBodyRepository.save(Mockito.any(StandbyScheduleBody.class))).thenReturn(body);
-		try {
-			Boolean boolResult = false;
-
-			// test success - no interval
-			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);
-			assertTrue(boolResult);
-
-			// test success - same start and same end
-			body.setValidTo(defaultEndDate);
-			to = defaultEndDate;
-			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);
-			assertTrue(boolResult);
-
-			// test success - same start and earlier end
-			body.setValidTo(defaultEndDate);
-			to = DateHelper.getDate(2018, 10, 1, 18, 0, 0);
-			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);
-			assertTrue(boolResult);
-
-			// test success - same start and later end
-			body.setValidTo(defaultEndDate);
-			to = DateHelper.getDate(2018, 10, 1, 23, 0, 0);
-			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);
-			assertTrue(boolResult);
-
-			// test success - same start and overlaping end
-			body.setValidTo(defaultEndDate);
-			to = defaultEndDateOverlapping;
-			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);
-			assertTrue(boolResult);
-
-			// test success - later start and same end
-			body.setValidTo(defaultEndDate);
-			to = defaultEndDate;
-			from = DateHelper.getDate(2018, 10, 1, 19, 0, 0);
-			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);
-			assertTrue(boolResult);
-
-			// test success - later start and later end
-			body.setValidTo(defaultEndDate);
-			to = DateHelper.getDate(2018, 10, 1, 23, 0, 0);
-			from = DateHelper.getDate(2018, 10, 1, 19, 0, 0);
-			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);
-			assertTrue(boolResult);
-
-			// test success - later start and earlier end
-			body.setValidTo(defaultEndDate);
-			to = DateHelper.getDate(2018, 10, 1, 21, 0, 0);
-			from = DateHelper.getDate(2018, 10, 1, 19, 0, 0);
-			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);
-			assertTrue(boolResult);
-
-			// test success - overlaping start
-			body.setValidTo(defaultEndDate);
-			to = defaultEndDate;
-			from = DateHelper.getDate(2018, 9, 30, 19, 0, 0);
-			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);
-			assertTrue(boolResult);
-		} catch (Exception e) {
-			assertNull(e);
-		}
-	}
-
-	@Test
-	public void moveUserInPlanTest() {
-		StandbyScheduleActionDto actionDto = new StandbyScheduleActionDto();
-		actionDto.setScheduleBodyId(1L);
-		actionDto.setValidFrom(new Date());
-		actionDto.setValidTo(new Date());
-		actionDto.setNewUserId(1L);
-		actionDto.setStandbyGroupId(1L);
-		String username = "JUnit";
-
-		StandbyScheduleBody responseBody = new StandbyScheduleBody();
-		responseBody.setId(1L);
-		StandbyStatus status = new StandbyStatus();
-		status.setId(SpMsg.STATUS_PLANNING);
-		responseBody.setStatus(status);
-		StandbyGroup responseGroup = new StandbyGroup();
-		responseGroup.setId(1L);
-		responseBody.setStandbyGroup(responseGroup);
-		when(standbyScheduleBodyRepository.findOne(Mockito.any())).thenReturn(responseBody);
-		when(standbyGroupRepository.findOne(actionDto.getStandbyGroupId())).thenReturn(responseGroup);
-		when(standbyScheduleBodyRepository.save(Mockito.any(StandbyScheduleBody.class))).thenReturn(responseBody);
-
-		// test success - equal date
-		try {
-			when(validationController.startValidation(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),
-					Mockito.any())).thenReturn(new ArrayList<PlanningMsgDto>());
-			when(userController.isUserValid(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenReturn(true);
-			when(userController.isUserInGroup(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), Mockito.any()))
-					.thenReturn(true);
-			when(archiveController.createArchiveOnMove(Mockito.any(), Mockito.any())).thenReturn(true);
-			// when(mailRequestSendDate.sendMail(Mockito.any(), Mockito.any(),
-			// Mockito.any(), Mockito.any()))
-			// .thenReturn(null);
-
-			planningController.moveUserInPlan(actionDto, username);
-		} catch (Exception e) {
-			assertNull(e);
-		}
-
-		// test success - different date
-		actionDto.setValidTo(DateHelper.addDaysToDate(new Date(), 3));
-		try {
-			when(userController.isUserValid(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenReturn(true);
-			when(userController.isUserInGroup(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), Mockito.any()))
-					.thenReturn(true);
-			planningController.moveUserInPlan(actionDto, username);
-		} catch (Exception e) {
-			assertNull(e);
-		}
-
-		// test success - bigger from date
-		actionDto.setValidFrom(DateHelper.addDaysToDate(new Date(), 3));
-		actionDto.setValidTo(new Date());
-		try {
-			when(userController.isUserValid(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenReturn(true);
-			when(userController.isUserInGroup(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), Mockito.any()))
-					.thenReturn(true);
-			planningController.moveUserInPlan(actionDto, username);
-		} catch (Exception e) {
-			assertNull(e);
-		}
-
-		// test error handling
-		Mockito.doThrow(new IllegalArgumentException()).when(standbyScheduleBodyRepository).findOne(Mockito.any());
-		try {
-			planningController.moveUserInPlan(actionDto, username);
-		} catch (Exception e) {
-			assertNotNull(e);
-		}
-	}
-
-	/**
-	 * method to get a test data UserInStandbyGroup List.
-	 * 
-	 * @return
-	 */
-	private List<UserInStandbyGroup> getTestDataForUserInStandbyGroups() {
-		List<UserInStandbyGroup> lsUserInStandbyGroups = new ArrayList<>();
-		UserInStandbyGroup uisg = new UserInStandbyGroup();
-		uisg.setId(1l);
-		uisg.setStandbyGroup(new StandbyGroup());
-		uisg.setPosition(3);
-		User user = new User();
-		user.setId(1L);
-		user.setFirstname("J.");
-		user.setLastname("Unit");
-		uisg.setUser(user);
-		lsUserInStandbyGroups.add(uisg);
-		uisg = new UserInStandbyGroup();
-		uisg.setId(2l);
-		uisg.setStandbyGroup(new StandbyGroup());
-		uisg.setPosition(1);
-		user = new User();
-		user.setId(2L);
-		user.setFirstname("Nr.");
-		user.setLastname("Zwei");
-		uisg.setUser(user);
-		lsUserInStandbyGroups.add(uisg);
-		return lsUserInStandbyGroups;
-	}
-
-	@Test
-	public void calculateHolidayTest() {
-		StandbyGroup group = new StandbyGroup();
-		Date date = DateHelper.getDate(2018, 1, 1);
-		StandbyScheduleBody stbyBody = new StandbyScheduleBody();
-		StandbyScheduleBody resultExtend = new StandbyScheduleBody();
-		resultExtend.setId(1L);
-		StandbyScheduleBody resultPreDraw = new StandbyScheduleBody();
-		resultPreDraw.setId(2L);
-
-		try {
-			Mockito.doReturn(true).when(planningController).isHoliday(Mockito.any(Date.class),
-					Mockito.any(StandbyGroup.class));
-			Mockito.doReturn(resultExtend).when(planningController).calculateHolidayExtend(Mockito.any(), Mockito.any(),
-					Mockito.any());
-			Mockito.doReturn(resultPreDraw).when(planningController).calculateHolidayPreDraw(Mockito.any(),
-					Mockito.any(), Mockito.any());
-
-			// test success 01 - holiday extend
-			group.setExtendStandbyTime(true);
-			StandbyScheduleBody result = planningController.calculateHoliday(group, date, stbyBody);
-			assertNotNull(result);
-			assertTrue(result.getId() == 1);
-
-			// test success 02 - holiday pre draw
-			group.setExtendStandbyTime(false);
-			result = planningController.calculateHoliday(group, date, stbyBody);
-			assertTrue(result.getId() == 2);
-			assertNotNull(result);
-
-			// test success 03 - no holiday
-			Mockito.doReturn(false).when(planningController).isHoliday(Mockito.any(Date.class),
-					Mockito.any(StandbyGroup.class));
-			result = planningController.calculateHoliday(group, date, stbyBody);
-			assertNotNull(result);
-
-		} catch (Exception e) {
-			assertNull(e);
-		}
-	}
-
-	@Test
-	public void calculateHolidayExtendTest() {
-		StandbyGroup group = new StandbyGroup();
-		group.setExtendStandbyTime(false);
-		Date date = DateHelper.getDate(2018, 1, 1, 10, 0, 0);
-		StandbyScheduleBody stbyBody = new StandbyScheduleBody();
-
-		StandbyDuration standbyDuration = new StandbyDuration();
-		standbyDuration.setValidFrom(date);
-		standbyDuration.setValidFrom(DateHelper.addDaysToDate(date, 1));
-
-		List<StandbyDuration> lsStandbyDurationsNull = new ArrayList<>();
-		lsStandbyDurationsNull.add(null);
-
-		List<StandbyDuration> lsStandbyDurations = new ArrayList<>();
-		StandbyDuration stbyDuration = new StandbyDuration();
-		// after valid from of stbyBody
-		stbyDuration.setValidFrom(DateHelper.getDate(2018, 1, 1, 20, 0, 0));
-		stbyDuration.setValidTo(DateHelper.getDate(2018, 1, 1, 22, 0, 0));
-		lsStandbyDurations.add(stbyDuration);
-
-		stbyDuration = new StandbyDuration();
-		// before valid from of stbyBody
-		stbyDuration.setValidFrom(DateHelper.getDate(2018, 1, 1, 8, 0, 0));
-		stbyDuration.setValidTo(DateHelper.getDate(2018, 1, 1, 9, 0, 0));
-		lsStandbyDurations.add(stbyDuration);
-
-		try {
-			StandbyScheduleBody result = null;
-			// success 01 - test null return date before valid from
-			stbyBody = this.getStandbyScheduleBody();
-			Mockito.doReturn(null).when(planningController).getFittingDurationsOfGroup(Mockito.any(StandbyGroup.class),
-					Mockito.any(Date.class));
-			result = planningController.calculateHolidayExtend(group, date, stbyBody);
-			assertNotNull(result);
-
-			// success 02 - test null return of list element
-			stbyBody = this.getStandbyScheduleBody();
-			Mockito.doReturn(lsStandbyDurationsNull).when(planningController)
-					.getFittingDurationsOfGroup(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));
-			result = planningController.calculateHolidayExtend(group, date, stbyBody);
-			assertNotNull(result);
-
-			// success 03 - test null return of list element
-			stbyBody = this.getStandbyScheduleBody();
-			Mockito.doReturn(lsStandbyDurations).when(planningController)
-					.getFittingDurationsOfGroup(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));
-			result = planningController.calculateHolidayExtend(group, date, stbyBody);
-			assertNotNull(result);
-
-		} catch (Exception e) {
-			LOGGER.error(e, e);
-			assertNull(e);
-		}
-	}
-
-	@Test
-	public void calculateHolidayPreDrawTest() {
-		StandbyGroup group = new StandbyGroup();
-		Date date = DateHelper.getDate(2018, 1, 1, 10, 0, 0);
-		StandbyScheduleBody stbyBody = this.getStandbyScheduleBody();
-
-		List<StandbyDuration> lsStandbyDurationsNull = new ArrayList<>();
-		lsStandbyDurationsNull.add(null);
-
-		List<StandbyDuration> lsStandbyDurations = new ArrayList<>();
-		StandbyDuration stbyDuration = new StandbyDuration();
-		// after valid from of stbyBody
-		stbyDuration.setValidFrom(DateHelper.getDate(2018, 1, 1, 20, 0, 0));
-		stbyDuration.setValidTo(DateHelper.getDate(2018, 1, 1, 22, 0, 0));
-		lsStandbyDurations.add(stbyDuration);
-
-		stbyDuration = new StandbyDuration();
-		// before valid from of stbyBody
-		stbyDuration.setValidFrom(DateHelper.getDate(2018, 1, 1, 8, 0, 0));
-		stbyDuration.setValidTo(DateHelper.getDate(2018, 1, 1, 9, 0, 0));
-		lsStandbyDurations.add(stbyDuration);
-
-		try {
-			StandbyScheduleBody result = null;
-
-			// success 01 - test null return date before valid from
-			stbyBody = this.getStandbyScheduleBody();
-			Mockito.doReturn(null).when(planningController)
-					.getFittingDurationsByValidTo(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));
-			result = planningController.calculateHolidayPreDraw(group, date, stbyBody);
-			assertNotNull(result);
-
-			// success 02 - dur = null
-			stbyBody = this.getStandbyScheduleBody();
-			Mockito.doReturn(lsStandbyDurationsNull).when(planningController)
-					.getFittingDurationsByValidTo(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));
-			result = planningController.calculateHolidayPreDraw(group, date, stbyBody);
-			assertNotNull(result);
-
-			// success 03 - duration before stbyBody
-			stbyBody = this.getStandbyScheduleBody();
-			Mockito.doReturn(lsStandbyDurations).when(planningController)
-					.getFittingDurationsByValidTo(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));
-			result = planningController.calculateHolidayPreDraw(group, date, stbyBody);
-			assertNotNull(result);
-
-			// success 04 - duration after stbyBody
-			stbyBody = this.getStandbyScheduleBody();
-			Mockito.doReturn(lsStandbyDurations).when(planningController)
-					.getFittingDurationsByValidTo(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));
-			result = planningController.calculateHolidayPreDraw(group, DateHelper.getDate(2018, 1, 1, 23, 0, 0),
-					stbyBody);
-			assertNotNull(result);
-
-		} catch (Exception e) {
-			LOGGER.error(e, e);
-			assertNull(e);
-		}
-	}
-
-	private StandbyScheduleBody getStandbyScheduleBody() {
-		StandbyScheduleBody stbyBody = new StandbyScheduleBody();
-		stbyBody.setValidFrom(DateHelper.getDate(2018, 1, 1, 12, 0, 0));
-		stbyBody.setValidTo(DateHelper.getDate(2018, 1, 1, 18, 0, 0));
-		User user = new User();
-		user.setFirstname("J.");
-		user.setLastname("Unit");
-		stbyBody.setUser(user);
-		return stbyBody;
-	}
-}
+/********************************************************************************

+ * Copyright (c) 2018 Mettenmeier GmbH 

+ *

+ * See the NOTICE file(s) distributed with this work for additional 

+ * information regarding copyright ownership.

+ *

+ * This program and the accompanying materials are made available under the 

+ * terms of the Eclipse Public License 2.0 which is available at

+ * http://www.eclipse.org/legal/epl-2.0

+ *

+ * SPDX-License-Identifier: EPL-2.0 

+ ********************************************************************************/

+package org.eclipse.openk.sp.controller.planning;

+

+import static org.junit.Assert.assertEquals;

+import static org.junit.Assert.assertFalse;

+import static org.junit.Assert.assertNotNull;

+import static org.junit.Assert.assertNull;

+import static org.junit.Assert.assertTrue;

+import static org.mockito.Mockito.when;

+

+import java.util.ArrayList;

+import java.util.Date;

+import java.util.HashMap;

+import java.util.List;

+import java.util.Map;

+

+import org.apache.log4j.Logger;

+import org.eclipse.openk.sp.controller.UserController;

+import org.eclipse.openk.sp.controller.validation.ValidationController;

+import org.eclipse.openk.sp.db.dao.CalendarRepository;

+import org.eclipse.openk.sp.db.dao.StandbyDurationRepository;

+import org.eclipse.openk.sp.db.dao.StandbyGroupRepository;

+import org.eclipse.openk.sp.db.dao.StandbyListRepository;

+import org.eclipse.openk.sp.db.dao.StandbyScheduleBodyRepository;

+import org.eclipse.openk.sp.db.dao.StandbyStatusRepository;

+import org.eclipse.openk.sp.db.dao.UserInStandbyGroupRepository;

+import org.eclipse.openk.sp.db.dao.UserRepository;

+import org.eclipse.openk.sp.db.model.CalendarDay;

+import org.eclipse.openk.sp.db.model.StandbyDuration;

+import org.eclipse.openk.sp.db.model.StandbyGroup;

+import org.eclipse.openk.sp.db.model.StandbyScheduleBody;

+import org.eclipse.openk.sp.db.model.StandbyStatus;

+import org.eclipse.openk.sp.db.model.User;

+import org.eclipse.openk.sp.db.model.UserInStandbyGroup;

+import org.eclipse.openk.sp.dto.StandbyScheduleBlueprintDto;

+import org.eclipse.openk.sp.dto.planning.PlanningBodyResultDto;

+import org.eclipse.openk.sp.dto.planning.PlanningMsgDto;

+import org.eclipse.openk.sp.dto.planning.PlanningPhaseDto;

+import org.eclipse.openk.sp.dto.planning.StandbyScheduleActionDto;

+import org.eclipse.openk.sp.exceptions.SpException;

+import org.eclipse.openk.sp.mail.MailRequest;

+import org.eclipse.openk.sp.util.DateHelper;

+import org.eclipse.openk.sp.util.SpMsg;

+import org.junit.Test;

+import org.junit.runner.RunWith;

+import org.mockito.InjectMocks;

+import org.mockito.Mock;

+import org.mockito.Mockito;

+import org.mockito.Spy;

+import org.mockito.runners.MockitoJUnitRunner;

+

+@RunWith(MockitoJUnitRunner.class)

+public class PlanningControllerTest extends PlanningController {

+	protected static final Logger LOGGER = Logger.getLogger(PlanningControllerTest.class);

+

+	private static final String ERROR_MSG_MISSING_ENTITY = "Eines der folgenden Entities kann nicht gefunden werden:";

+	private static final String ERROR_MSG_STANDBYLIST = "Es fehlt der folgendende Einagebeparameter : StandbyList";

+	private static final String ERROR_MSG_STANDBYGROUP = "Es fehlt der folgendende Einagebeparameter : StandbyGroup";

+	private static final String ERROR_MSG_VALID_FROM = "Es fehlt der folgendende Einagebeparameter : validFrom";

+	private static final String ERROR_MSG_VALID_TO = "Es fehlt der folgendende Einagebeparameter : validTo";

+

+	@InjectMocks

+	@Spy

+	PlanningController planningController;

+

+	@Mock

+	private StandbyGroupRepository standbyGroupRepository;

+

+	@Mock

+	private StandbyListRepository standbyListRepository;

+

+	@Mock

+	private StandbyDurationRepository standbyDurationRepository;

+

+	@Mock

+	private StandbyStatusRepository standbyStatusRepository;

+

+	@Mock

+	private StandbyScheduleBodyRepository standbyScheduleBodyRepository;

+

+	@Mock

+	private UserRepository userRepository;

+

+	@Mock

+	private CalendarRepository calendarRepository;

+

+	@Mock

+	private UserController userController;

+

+	@Mock

+	private ValidationController validationController;

+

+	@Mock

+	private ArchiveController archiveController;

+

+	@Mock

+	private MailRequest mailRequest;

+

+	@Mock

+	private UserInStandbyGroupRepository uisgRepository;

+

+	@Test

+	public void calculatePlanTest() throws SpException {

+		assertNotNull(new Boolean(true));

+	}

+

+	@Test

+	public void startPlanningTest() throws SpException {

+		String username = "JUnit";

+		StandbyScheduleBlueprintDto standbyBlueprintDto = new StandbyScheduleBlueprintDto();

+		standbyBlueprintDto.setStandbyGroupId(1L);

+		standbyBlueprintDto.setStandbyListId(1L);

+		standbyBlueprintDto.setStartIdOfUser(1L);

+		standbyBlueprintDto.setValidFrom(DateHelper.getDate(2018, 1, 1, 8, 0, 0));

+		standbyBlueprintDto.setValidTo(DateHelper.getDate(2018, 1, 1, 16, 0, 0));

+

+		List<UserInStandbyGroup> lsUserInStandbyGroup = new ArrayList<>();

+		User user1 = new User();

+		user1.setFirstname("J.");

+		user1.setLastname("Unit");

+		UserInStandbyGroup uisg = new UserInStandbyGroup();

+		uisg.setUser(user1);

+

+		Map<Integer, PlanningPhaseDto> planningPhaseMap = new HashMap<>();

+		PlanningPhaseDto planningPhaseDto = new PlanningPhaseDto();

+		planningPhaseDto.setStartDate(DateHelper.getDate(2018, 1, 1, 0, 0, 0));

+		planningPhaseDto.setEndDate(DateHelper.getDate(2018, 1, 31, 0, 0, 0));

+		planningPhaseDto.setLsUsers(lsUserInStandbyGroup);

+		planningPhaseMap.put(1, planningPhaseDto);

+

+		try {

+			// success test 01 - validInput

+			Mockito.doReturn(true).when(planningController).validateInputForPlanCalculation(standbyBlueprintDto);

+			Mockito.doReturn(planningPhaseMap).when(planningController).calculatePlanningPhaseMap(standbyBlueprintDto);

+			Mockito.doNothing().when(planningController).calculatePlanForPhase(Mockito.any(), Mockito.any(),

+					Mockito.any());

+			planningController.startPlanning(standbyBlueprintDto, username);

+

+			// success test 02 - invalidInput

+			Mockito.doReturn(false).when(planningController).validateInputForPlanCalculation(standbyBlueprintDto);

+			Mockito.doReturn(planningPhaseMap).when(planningController).calculatePlanningPhaseMap(standbyBlueprintDto);

+			Mockito.doNothing().when(planningController).calculatePlanForPhase(Mockito.any(), Mockito.any(),

+					Mockito.any());

+			planningController.startPlanning(standbyBlueprintDto, username);

+		} catch (SpException e) {

+			assertNull(e);

+		}

+

+		// negative test 01

+		try {

+			Mockito.doThrow(new SpException()).when(planningController)

+					.validateInputForPlanCalculation(standbyBlueprintDto);

+			planningController.startPlanning(standbyBlueprintDto, username);

+		} catch (SpException e) {

+			assertNotNull(e);

+		}

+

+		// negative test 02

+		try {

+			Mockito.doThrow(new IllegalArgumentException()).when(standbyGroupRepository).findOne(Mockito.any());

+			planningController.startPlanning(standbyBlueprintDto, username);

+		} catch (SpException e) {

+			assertNotNull(e);

+		}

+	}

+

+	@Test

+	public void calculatePlanForPhaseTest() {

+		PlanningPhaseDto dto = new PlanningPhaseDto();

+		List<UserInStandbyGroup> lsUserInStandbyGroup = this.getTestDataForUserInStandbyGroups();

+		dto.setLsUsers(lsUserInStandbyGroup);

+

+		dto.setStartDate(new Date());

+		dto.setEndDate(DateHelper.addDaysToDate(new Date(), 7));

+		Long lastStartUserId = 1L;

+		String username = "JUnit";

+

+		when(standbyScheduleBodyRepository.save(Mockito.any(StandbyScheduleBody.class)))

+				.thenReturn(new StandbyScheduleBody());

+

+		when(userRepository.findOne(Mockito.any())).thenReturn(lsUserInStandbyGroup.get(0).getUser());

+

+		Mockito.doNothing().when(planningController).changeOrDeleteExistingBodies(Mockito.any(), Mockito.any(),

+				Mockito.any(), Mockito.any(), Mockito.any());

+

+		try {

+			planningController.calculatePlanForPhase(dto, lastStartUserId, username);

+		} catch (Exception e) {

+			LOGGER.error(e, e);

+			assertNull(e);

+		}

+	}

+

+	@Test

+	public void calculatePlanningPhaseMapTest() {

+		Map<Integer, PlanningPhaseDto> planningPhaseMap = new HashMap<>();

+		StandbyScheduleBlueprintDto standbyBlueprintDto = new StandbyScheduleBlueprintDto();

+		standbyBlueprintDto.setStandbyGroupId(1L);

+		standbyBlueprintDto.setStandbyListId(1L);

+		standbyBlueprintDto.setStartIdOfUser(1L);

+		standbyBlueprintDto.setValidFrom(DateHelper.getDate(2018, 1, 1, 8, 0, 0));

+		standbyBlueprintDto.setValidTo(DateHelper.getDate(2018, 1, 9, 16, 0, 0));

+

+		List<UserInStandbyGroup> lsUserInStandbyGroupsEmpty = new ArrayList<>();

+		List<UserInStandbyGroup> lsUserInStandbyGroups = new ArrayList<>();

+		UserInStandbyGroup uisg = new UserInStandbyGroup();

+		User user = new User();

+		uisg.setUser(user);

+		lsUserInStandbyGroups.add(uisg);

+		user = new User();

+		uisg.setUser(user);

+		lsUserInStandbyGroups.add(uisg);

+

+		try {

+			// [SUCCESS] returning null list for lsUserInGroup

+			when(uisgRepository.findUserForInterval(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(null);

+			planningPhaseMap = planningController.calculatePlanningPhaseMap(standbyBlueprintDto);

+			assertNotNull(planningPhaseMap);

+			assertTrue(planningPhaseMap.isEmpty());

+

+			// [SUCCESS] returning empty list for lsUserInGroup

+			when(uisgRepository.findUserForInterval(Mockito.any(), Mockito.any(), Mockito.any()))

+					.thenReturn(lsUserInStandbyGroupsEmpty);

+			planningPhaseMap = planningController.calculatePlanningPhaseMap(standbyBlueprintDto);

+			assertNotNull(planningPhaseMap);

+			assertTrue(planningPhaseMap.isEmpty());

+

+			// [SUCCESS] returning list for lsUserInGroup

+			when(uisgRepository.findUserForInterval(Mockito.any(), Mockito.any(), Mockito.any()))

+					.thenReturn(lsUserInStandbyGroups);

+			planningPhaseMap = planningController.calculatePlanningPhaseMap(standbyBlueprintDto);

+			assertNotNull(planningPhaseMap);

+			assertFalse(planningPhaseMap.isEmpty());

+

+		} catch (Exception e) {

+			LOGGER.error(e, e);

+			assertNull(e);

+		}

+	}

+

+	@Test

+	public void createScheduleBodyEntryTest() {

+		Date startDate = new Date();

+		Date currentDate = new Date();

+		Date lastDate = new Date();

+		int currentPosition = 0;

+		String username = "JUnit";

+		Long lastUserId = 1L;

+		List<UserInStandbyGroup> lsUserInStandbyGroup = this.getTestDataForUserInStandbyGroups();

+

+		List<StandbyDuration> lsDuration = new ArrayList<>();

+		StandbyDuration dur = new StandbyDuration();

+		dur.setId(1L);

+		dur.setNextUserInNextDuration(true);

+		dur.setValidDayFrom(1);

+		dur.setValidDayTo(1);

+		dur.setValidFrom(DateHelper.getDate(2018, 10, 1));

+		dur.setValidFrom(DateHelper.getDate(2018, 10, 31));

+		lsDuration.add(dur);

+

+		when(standbyDurationRepository.findDurationForValidFromDay(Mockito.any(), Mockito.any()))

+				.thenReturn(lsDuration);

+		when(standbyScheduleBodyRepository.save(Mockito.any(StandbyScheduleBody.class)))

+				.thenReturn(new StandbyScheduleBody());

+

+		// covered days = 1

+		try {

+			PlanningBodyResultDto dto = planningController.calculateScheduleBodyEntries(lsUserInStandbyGroup, startDate,

+					currentDate, lastDate, currentPosition, username, lastUserId);

+			assertNotNull(dto);

+		} catch (Exception e) {

+			assertNotNull(e);

+		}

+

+		// covered days > 1

+		lsDuration.get(0).setValidDayTo(3);

+		lastDate = DateHelper.addDaysToDate(new Date(), 5);

+		try {

+			PlanningBodyResultDto dto = planningController.calculateScheduleBodyEntries(lsUserInStandbyGroup, startDate,

+					currentDate, lastDate, currentPosition, username, lastUserId);

+			assertNotNull(dto);

+		} catch (Exception e) {

+			assertNotNull(e);

+		}

+

+		// date after current

+		try {

+			currentDate = DateHelper.addDaysToDate(new Date(), 1);

+			lastDate = DateHelper.addDaysToDate(new Date(), 1);

+			PlanningBodyResultDto dto = planningController.calculateScheduleBodyEntries(lsUserInStandbyGroup, startDate,

+					currentDate, lastDate, currentPosition, username, lastUserId);

+			assertNotNull(dto);

+		} catch (Exception e) {

+			assertNotNull(e);

+		}

+

+		// fitting duration = false

+		when(standbyDurationRepository.findDurationForValidFromDay(Mockito.any(), Mockito.any())).thenReturn(null);

+		try {

+			PlanningBodyResultDto dto = planningController.calculateScheduleBodyEntries(lsUserInStandbyGroup, startDate,

+					currentDate, lastDate, currentPosition, username, lastUserId);

+			assertNotNull(dto);

+			assertTrue(

+					dto.getLsMsg().get(0).getMsg().contains("wurde kein aktiver Zeitraum für folgenden Tag gefunden"));

+		} catch (Exception e) {

+			assertNotNull(e);

+		}

+	}

+

+	public PlanningBodyResultDto calculateScheduleBodyEntries(List<UserInStandbyGroup> lsUserInGroup, Date currentDate,

+			Date lastDate, int currentPosition, String username) {

+		StandbyGroup group = lsUserInGroup.get(0).getStandbyGroup();

+		PlanningBodyResultDto resultObj = new PlanningBodyResultDto();

+		StandbyDuration fittingDuration = this.getFittingDurationOfGroup(group, currentDate);

+		if (fittingDuration != null) {

+			int intStartDay = fittingDuration.getValidDayFrom();

+			int intEndDay = fittingDuration.getValidDayTo();

+			int coveredDays = DateHelper.calculateDifferenceOfDays(intStartDay, intEndDay, new Date(), new Date());

+			Date nextDay = null;

+

+			if (coveredDays == 0) {

+				// single entry with no over night duration

+				LOGGER.debug("A day was found that just cover a single day.");

+				StandbyScheduleBody stbyBody = this.createScheduleBodyObject(group, username, currentDate,

+						lsUserInGroup.get(currentPosition).getUser(), fittingDuration,

+						PlanningController.TXT_AUTOMATIC_PLANNING);

+				standbyScheduleBodyRepository.save(stbyBody);

+				resultObj.getLsMsg().add(createMsgSavingBody(stbyBody));

+			} else {

+				// 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)) {

+						String warning = "Für das Datum (" + currentDate

+								+ ") wird kein Eintrag erzeugt, da der Folgetag den definierten Zeitraum überschereitet.";

+						resultObj.getLsMsg()

+								.add(new PlanningMsgDto(warning, PlanningMsgDto.WARN, PlanningMsgDto.CSS_WARN));

+						resultObj.setTempDate(nextDay);

+						resultObj.setNewPosition(currentPosition);

+						return resultObj;

+					} else {

+						List<StandbyScheduleBody> lsScheduleBodies = this.createOverlappingScheduleBodyObjects(group,

+								username, currentDate, lsUserInGroup.get(currentPosition).getUser(), fittingDuration, i,

+								coveredDays);

+						for (StandbyScheduleBody stbyBody : lsScheduleBodies) {

+							standbyScheduleBodyRepository.save(stbyBody);

+							resultObj.getLsMsg().add(createMsgSavingBody(stbyBody));

+							resultObj.setTempDate(nextDay);

+						}

+						resultObj.setNewPosition(currentPosition);

+						resultObj.setTempDate(nextDay);

+						currentDate = resultObj.getTempDate();

+					}

+				}

+			}

+			resultObj.setTempDate(nextDay);

+			resultObj.setCurrentDuration(fittingDuration);

+		} else {

+			resultObj.setTempDate(DateHelper.addDaysToDate(currentDate, 1));

+			resultObj.getLsMsg().add(this.createMsgNotAvailable(group, currentDate));

+		}

+		return resultObj;

+	}

+

+	@Test

+	public void createMsgExtendHolidayTest() {

+		StandbyScheduleBody stbyBody = new StandbyScheduleBody();

+		User user = new User();

+		user.setFirstname("J.");

+		user.setLastname("Unit");

+		stbyBody.setUser(user);

+		Date date = new Date();

+		Boolean isStandbyTimeExtension = true;

+

+		// positive test - extend

+		PlanningMsgDto dto = planningController.createMsgExtendHoliday(stbyBody, date, isStandbyTimeExtension);

+		assertNotNull(dto);

+		assertTrue(dto.getMsg().endsWith("verlängert werden."));

+

+		// negative test - pre

+		isStandbyTimeExtension = false;

+		dto = planningController.createMsgExtendHoliday(stbyBody, date, isStandbyTimeExtension);

+		assertNotNull(dto);

+		assertTrue(dto.getMsg().endsWith("vorgezogen werden."));

+	}

+

+	@Test

+	public void createMsgStartOfPhaseTest() {

+		List<UserInStandbyGroup> lsUserInStandbyGroup = this.getTestDataForUserInStandbyGroups();

+		Integer phaseId = 1;

+		PlanningPhaseDto phase = new PlanningPhaseDto();

+		phase.setEndDate(new Date());

+		phase.setStartDate(new Date());

+		phase.setLsUsers(lsUserInStandbyGroup);

+		try {

+			List<PlanningMsgDto> lsMsgDto = planningController.createMsgStartOfPhase(phaseId, phase);

+			assertNotNull(lsMsgDto);

+		} catch (Exception e) {

+			assertNull(e);

+		}

+	}

+

+	@Test

+	public void createMsgEndOfPhaseTest() {

+		Integer phaseId = 1;

+		PlanningMsgDto msgDto = planningController.createMsgEndOfPhase(phaseId);

+		assertNotNull(msgDto);

+	}

+

+	@Test

+	public void createMsgSavingBodyTest() {

+		StandbyScheduleBody stbyBody = new StandbyScheduleBody();

+		User user = new User();

+		user.setFirstname("J.");

+		user.setLastname("Unit");

+		stbyBody.setUser(user);

+		stbyBody.setValidFrom(new Date());

+		stbyBody.setValidTo(new Date());

+		PlanningMsgDto msgDto = planningController.createMsgSavingBody(stbyBody);

+		assertNotNull(msgDto);

+	}

+

+	@Test

+	public void createMsgNotAvailableTest() {

+		StandbyGroup group = new StandbyGroup();

+		group.setTitle("Test");

+		Date currentDate = new Date();

+		PlanningMsgDto msgDto = planningController.createMsgNotAvailable(group, currentDate);

+		assertNotNull(msgDto);

+	}

+

+	@Test

+	public void createMsgNumberOfPhasesTest() {

+		Map<Integer, PlanningPhaseDto> map = new HashMap<>();

+		map.put(1, new PlanningPhaseDto());

+		map.put(2, new PlanningPhaseDto());

+

+		StandbyScheduleBlueprintDto dto = new StandbyScheduleBlueprintDto();

+		dto.setValidFrom(new Date());

+		dto.setValidTo(new Date());

+

+		// success

+		PlanningMsgDto msgDto = planningController.createMsgNumberOfPhases(map, dto);

+		assertNotNull(msgDto);

+		assertTrue(msgDto.getMsg().startsWith("Durch wechselnde Gruppenmitglieder wurde(n)"));

+

+		// empty map

+		map = new HashMap<>();

+		msgDto = planningController.createMsgNumberOfPhases(map, dto);

+		assertNotNull(msgDto);

+		assertTrue(msgDto.getMsg().startsWith("Auf Grund fehlender Bereitschaften im gewählten Zeitraum,"));

+	}

+

+	@Test

+	public void createMsgGroupLeaderChangedTest() {

+		List<UserInStandbyGroup> lsUserInStandbyGroup = new ArrayList<UserInStandbyGroup>();

+		UserInStandbyGroup uisg = new UserInStandbyGroup();

+		User nextUser = new User();

+		nextUser.setFirstname("Next");

+		nextUser.setLastname("User");

+		uisg.setUser(nextUser);

+		lsUserInStandbyGroup.add(uisg);

+

+		User user = new User();

+		user.setFirstname("J.");

+		user.setLastname("Unit");

+		PlanningMsgDto msgDto = planningController.createMsgGroupLeaderChanged(user, lsUserInStandbyGroup);

+		assertNotNull(msgDto);

+	}

+

+	@Test

+	public void deleteScheduleBodiesByIdsTest() {

+

+		List<Long> lsIds = new ArrayList<>();

+		lsIds.add(1L);

+		lsIds.add(2L);

+

+		Mockito.doNothing().when(standbyScheduleBodyRepository).delete(1L);

+		try {

+			planningController.deleteScheduleBodiesByIds(lsIds);

+		} catch (Exception e) {

+			assertNull(e);

+		}

+

+		lsIds.add(3L);

+		Mockito.doThrow(new IllegalArgumentException()).when(standbyScheduleBodyRepository).delete(3L);

+		try {

+			planningController.deleteScheduleBodiesByIds(lsIds);

+		} catch (SpException e) {

+			assertNotNull(e);

+		}

+	}

+

+	@Test

+	public void validateInputForPlanCalculationTest() {

+		StandbyScheduleBlueprintDto standbyBlueprintDto = new StandbyScheduleBlueprintDto();

+		// [FAIL] TEST INVALID LIST : EMPTY

+		try {

+			planningController.validateInputForPlanCalculation(standbyBlueprintDto);

+		} catch (SpException e) {

+			assertNotNull(e);

+			assertEquals(ERROR_MSG_STANDBYLIST, e.getMessage());

+		}

+

+		// [FAIL] TEST INVALID LIST : UNKOWN ENTITY

+		when(standbyListRepository.exists(Mockito.anyLong())).thenReturn(false);

+		standbyBlueprintDto.setStandbyListId(1l);

+		try {

+			planningController.validateInputForPlanCalculation(standbyBlueprintDto);

+		} catch (SpException e) {

+			assertNotNull(e);

+			assertTrue(e.getMessage().startsWith(ERROR_MSG_MISSING_ENTITY));

+		}

+

+		// [FAIL] TEST INVALID GROUP : EMPTY

+		when(standbyListRepository.exists(Mockito.anyLong())).thenReturn(true);

+		standbyBlueprintDto.setStandbyListId(1l);

+		try {

+			planningController.validateInputForPlanCalculation(standbyBlueprintDto);

+		} catch (SpException e) {

+			assertNotNull(e);

+			assertEquals(ERROR_MSG_STANDBYGROUP, e.getMessage());

+		}

+

+		// [FAIL] TEST INVALID GROUP : UNKOWN ENTITY

+		when(standbyGroupRepository.exists(Mockito.anyLong())).thenReturn(false);

+		standbyBlueprintDto.setStandbyGroupId(1l);

+		try {

+			planningController.validateInputForPlanCalculation(standbyBlueprintDto);

+		} catch (SpException e) {

+			assertNotNull(e);

+			assertTrue(e.getMessage().startsWith(ERROR_MSG_MISSING_ENTITY));

+		}

+

+		// [FAIL] TEST INVALID VALID FROM : EMPTY

+		when(standbyGroupRepository.exists(Mockito.anyLong())).thenReturn(true);

+		try {

+			planningController.validateInputForPlanCalculation(standbyBlueprintDto);

+		} catch (SpException e) {

+			assertNotNull(e);

+			assertEquals(ERROR_MSG_VALID_FROM, e.getMessage());

+		}

+

+		// [FAIL] TEST INVALID VALID TO : EMPTY

+		standbyBlueprintDto.setValidFrom(new Date());

+		try {

+			planningController.validateInputForPlanCalculation(standbyBlueprintDto);

+		} catch (SpException e) {

+			assertNotNull(e);

+			assertEquals(ERROR_MSG_VALID_TO, e.getMessage());

+		}

+

+		// [SUCCESS] TEST VALID

+		standbyBlueprintDto.setValidTo(new Date());

+		try {

+			Boolean result = planningController.validateInputForPlanCalculation(standbyBlueprintDto);

+			assertTrue(result);

+		} catch (SpException e) {

+			assertNull(e);

+		}

+	}

+

+	@Test

+	public void isHolidayTest() {

+		StandbyGroup group = new StandbyGroup();

+

+		List<CalendarDay> lsCalendarDays = null;

+

+		// negative test - null value

+		when(calendarRepository.findValidByDate(Mockito.any(), Mockito.any())).thenReturn(lsCalendarDays);

+		Boolean result = planningController.isHoliday(new Date(), group);

+		assertTrue(!result);

+

+		// negative test - empty list

+		lsCalendarDays = new ArrayList<>();

+		when(calendarRepository.findValidByDate(Mockito.any(), Mockito.any())).thenReturn(lsCalendarDays);

+		result = planningController.isHoliday(new Date(), group);

+		assertTrue(!result);

+

+		// negative test - object in Ignore List

+		CalendarDay cal = new CalendarDay();

+		lsCalendarDays.add(cal);

+		when(calendarRepository.findValidByDate(Mockito.any(), Mockito.any())).thenReturn(lsCalendarDays);

+		group.getLsIgnoredCalendarDays().add(cal);

+		result = planningController.isHoliday(new Date(), group);

+		assertTrue(!result);

+

+		// positiv test

+		when(calendarRepository.findValidByDate(Mockito.any(), Mockito.any())).thenReturn(lsCalendarDays);

+		group.getLsIgnoredCalendarDays().remove(cal);

+		result = planningController.isHoliday(new Date(), group);

+		assertTrue(result);

+	}

+

+	@Test

+	public void getFittingDurationOfGroupTest() {

+		StandbyGroup group = new StandbyGroup();

+		Date date = new Date();

+		List<StandbyDuration> lsDuration = new ArrayList<>();

+		StandbyDuration result = null;

+

+		when(standbyDurationRepository.findDurationForValidFromDay(Mockito.any(), Mockito.any()))

+				.thenReturn(lsDuration);

+

+		// success

+		lsDuration.add(new StandbyDuration());

+		result = planningController.getFittingDurationOfGroup(group, date);

+		assertNotNull(result);

+

+		// failure

+		lsDuration = new ArrayList<>();

+		when(standbyDurationRepository.findDurationForValidFromDay(Mockito.any(), Mockito.any()))

+				.thenReturn(lsDuration);

+		result = planningController.getFittingDurationOfGroup(group, date);

+		assertNull(result);

+

+		when(standbyDurationRepository.findDurationForValidFromDay(Mockito.any(), Mockito.any())).thenReturn(null);

+		result = planningController.getFittingDurationOfGroup(group, date);

+		assertNull(result);

+

+	}

+

+	@Test

+	public void getFittingDurationByValidToTest() {

+		StandbyGroup group = new StandbyGroup();

+		Date date = new Date();

+		List<StandbyDuration> lsDuration = new ArrayList<>();

+		StandbyDuration result = null;

+

+		when(standbyDurationRepository.findDurationForValidToDay(Mockito.any(), Mockito.any())).thenReturn(lsDuration);

+

+		// success

+		lsDuration.add(new StandbyDuration());

+		result = planningController.getFittingDurationByValidTo(group, date);

+		assertNotNull(result);

+

+		// failure

+		lsDuration = new ArrayList<>();

+		when(standbyDurationRepository.findDurationForValidToDay(Mockito.any(), Mockito.any())).thenReturn(lsDuration);

+		result = planningController.getFittingDurationByValidTo(group, date);

+		assertNull(result);

+

+		when(standbyDurationRepository.findDurationForValidToDay(Mockito.any(), Mockito.any())).thenReturn(null);

+		result = planningController.getFittingDurationByValidTo(group, date);

+		assertNull(result);

+

+	}

+

+	@Test

+	public void resetCounterToNewPositionTest() {

+		int currentPosition = 0;

+		Long lastStartUserId = 1L;

+		List<UserInStandbyGroup> lsUserInGroup = new ArrayList<>();

+		UserInStandbyGroup uisg = new UserInStandbyGroup();

+		User user = new User();

+		user.setId(1L);

+		uisg.setUser(user);

+		lsUserInGroup.add(uisg);

+

+		uisg = new UserInStandbyGroup();

+		user = new User();

+		user.setId(2L);

+		uisg.setUser(user);

+		lsUserInGroup.add(uisg);

+

+		uisg = new UserInStandbyGroup();

+		user = new User();

+		user.setId(3L);

+		uisg.setUser(user);

+		lsUserInGroup.add(uisg);

+

+		Boolean isNextUserInNextCycle = false;

+		Boolean isNextUserInDuration = true;

+

+		PlanningBodyResultDto response = null;

+		response = planningController.resetCounterToNewPosition(currentPosition, lastStartUserId, lsUserInGroup,

+				isNextUserInNextCycle, isNextUserInDuration);

+		currentPosition = response.getNewPosition();

+		assertTrue(currentPosition == 1);

+

+		// not start user

+		response = planningController.resetCounterToNewPosition(1, 2L, lsUserInGroup, isNextUserInNextCycle,

+				isNextUserInDuration);

+		currentPosition = response.getNewPosition();

+		assertTrue(currentPosition == 2);

+

+		// test start from beginning because list ends

+		response = planningController.resetCounterToNewPosition(2, 2L, lsUserInGroup, isNextUserInNextCycle,

+				isNextUserInDuration);

+		currentPosition = response.getNewPosition();

+		assertTrue(currentPosition == 0);

+

+		// user at position but isNextUserInNextCycle = false

+		response = planningController.resetCounterToNewPosition(0, 2L, lsUserInGroup, isNextUserInNextCycle,

+				isNextUserInDuration);

+		currentPosition = response.getNewPosition();

+		assertTrue(currentPosition == 1);

+

+		// skip position because user at position and isNextUserInNextCycle = true

+		isNextUserInNextCycle = true;

+		response = planningController.resetCounterToNewPosition(0, 2L, lsUserInGroup, isNextUserInNextCycle,

+				isNextUserInDuration);

+		currentPosition = response.getNewPosition();

+		assertTrue(currentPosition == 2);

+

+		// next user in duration = false

+		isNextUserInDuration = false;

+		response = planningController.resetCounterToNewPosition(0, 2L, lsUserInGroup, isNextUserInNextCycle,

+				isNextUserInDuration);

+		currentPosition = response.getNewPosition();

+		assertTrue(currentPosition == 0);

+

+	}

+

+	@Test

+	public void getNextAvailablePositionTest() {

+		int currentPosition = 0;

+		List<UserInStandbyGroup> lsUserInGroup = new ArrayList<>();

+		lsUserInGroup.add(new UserInStandbyGroup());

+		lsUserInGroup.add(new UserInStandbyGroup());

+

+		currentPosition = planningController.getNextAvailablePosition(currentPosition, lsUserInGroup);

+		assertTrue(currentPosition == 1);

+

+		// start at first position because of end of list.

+		currentPosition = planningController.getNextAvailablePosition(currentPosition, lsUserInGroup);

+		assertTrue(currentPosition == 0);

+	}

+

+	@Test

+	public void getIndexOfLastPlannedUserTest() {

+		Long lastStartUserId = 1L;

+		List<UserInStandbyGroup> lsUserInGroup = new ArrayList<>();

+		UserInStandbyGroup uisg = new UserInStandbyGroup();

+		User user = new User();

+		user.setId(1L);

+		uisg.setUser(user);

+		lsUserInGroup.add(uisg);

+

+		uisg = new UserInStandbyGroup();

+		user = new User();

+		user.setId(2L);

+		uisg.setUser(user);

+		lsUserInGroup.add(uisg);

+

+		uisg = new UserInStandbyGroup();

+		user = new User();

+		user.setId(3L);

+		uisg.setUser(user);

+		lsUserInGroup.add(uisg);

+

+		int result = -1;

+		result = planningController.getIndexOfLastPlannedUser(lastStartUserId, lsUserInGroup);

+		assertTrue(result == 0);

+

+		lastStartUserId = 3L;

+		result = planningController.getIndexOfLastPlannedUser(lastStartUserId, lsUserInGroup);

+		assertTrue(result == 2);

+

+		lastStartUserId = 4L;

+		result = planningController.getIndexOfLastPlannedUser(lastStartUserId, lsUserInGroup);

+		assertTrue(result == -1);

+	}

+

+	@Test

+	public void logPhasesTest() {

+		try {

+			Map<Integer, PlanningPhaseDto> resultMap = new HashMap<>();

+			List<UserInStandbyGroup> lsUserInStandbyGroups = new ArrayList<>();

+			UserInStandbyGroup uisg = new UserInStandbyGroup();

+			uisg.setId(1l);

+			uisg.setStandbyGroup(new StandbyGroup());

+			User user = new User();

+			user.setFirstname("J.");

+			user.setLastname("Unit");

+			uisg.setUser(user);

+			lsUserInStandbyGroups.add(uisg);

+			user = new User();

+			user.setFirstname("Nr.");

+			user.setLastname("Zwei");

+			uisg.setUser(user);

+			lsUserInStandbyGroups.add(uisg);

+			PlanningPhaseDto dto = new PlanningPhaseDto(new Date(), new Date(), lsUserInStandbyGroups);

+			resultMap.put(1, dto);

+

+			planningController.logPhases(resultMap);

+		} catch (Exception e) {

+			assertNull(e);

+		}

+	}

+

+	@Test

+	public void replaceUserInPlanTest() {

+

+		StandbyScheduleActionDto actionDto = new StandbyScheduleActionDto();

+		actionDto.setCurrentUserId(1L);

+		actionDto.setNewUserId(2L);

+		actionDto.setScheduleBodyId(1L);

+		actionDto.setStandbyGroupId(1L);

+		actionDto.setStatusId(1L);

+		actionDto.setValidFrom(new Date());

+		actionDto.setValidTo(new Date());

+		String username = "JUnit";

+

+		List<StandbyScheduleBody> lsStandbyScheduleBodies = new ArrayList<>();

+		lsStandbyScheduleBodies.add(new StandbyScheduleBody());

+

+		when(standbyScheduleBodyRepository.findByUserAndGroupAndDateAndStatus(Mockito.anyLong(), Mockito.anyLong(),

+				Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(lsStandbyScheduleBodies);

+		when(standbyStatusRepository.findOne(Mockito.any())).thenReturn(new StandbyStatus());

+		when(userRepository.findOne(Mockito.any())).thenReturn(new User());

+		when(userRepository.findOne(Mockito.any())).thenReturn(new User());

+		when(standbyScheduleBodyRepository.save(Mockito.any(StandbyScheduleBody.class)))

+				.thenReturn(new StandbyScheduleBody());

+

+		// success

+		try {

+			when(userController.isUserInGroup(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), Mockito.any()))

+					.thenReturn(true);

+			planningController.replaceUserInPlan(actionDto, username);

+		} catch (Exception e) {

+			assertNull(e);

+		}

+

+		// test error handling

+		Mockito.doThrow(new IllegalArgumentException()).when(userRepository).findOne(Mockito.any());

+		try {

+			planningController.replaceUserInPlan(actionDto, username);

+		} catch (Exception e) {

+			assertNotNull(e);

+		}

+	}

+

+	@Test

+	public void splitScheduleBodyTest() {

+		Date defaultStartDate = DateHelper.getDate(2018, 10, 1, 16, 0, 0);

+		Date defaultEndDate = DateHelper.getDate(2018, 10, 1, 22, 0, 0);

+		Date defaultEndDateOverlapping = DateHelper.getDate(2018, 10, 2, 8, 0, 0);

+

+		StandbyScheduleBody body = new StandbyScheduleBody();

+		body.setValidFrom(defaultStartDate);

+		body.setValidTo(defaultStartDate);

+		Date from = defaultStartDate;

+		Date to = defaultStartDate;

+		User newUser = new User();

+		String modifiedBy = "JUnit";

+

+		// negative test - null pointer

+		try {

+			StandbyScheduleBody bodyNull = null;

+			planningController.splitScheduleBody(bodyNull, from, to, newUser, modifiedBy);

+		} catch (SpException e) {

+			assertNotNull(e);

+		}

+

+		// positive tests

+		when(standbyScheduleBodyRepository.save(Mockito.any(StandbyScheduleBody.class))).thenReturn(body);

+		try {

+			Boolean boolResult = false;

+

+			// test success - no interval

+			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);

+			assertTrue(boolResult);

+

+			// test success - same start and same end

+			body.setValidTo(defaultEndDate);

+			to = defaultEndDate;

+			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);

+			assertTrue(boolResult);

+

+			// test success - same start and earlier end

+			body.setValidTo(defaultEndDate);

+			to = DateHelper.getDate(2018, 10, 1, 18, 0, 0);

+			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);

+			assertTrue(boolResult);

+

+			// test success - same start and later end

+			body.setValidTo(defaultEndDate);

+			to = DateHelper.getDate(2018, 10, 1, 23, 0, 0);

+			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);

+			assertTrue(boolResult);

+

+			// test success - same start and overlaping end

+			body.setValidTo(defaultEndDate);

+			to = defaultEndDateOverlapping;

+			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);

+			assertTrue(boolResult);

+

+			// test success - later start and same end

+			body.setValidTo(defaultEndDate);

+			to = defaultEndDate;

+			from = DateHelper.getDate(2018, 10, 1, 19, 0, 0);

+			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);

+			assertTrue(boolResult);

+

+			// test success - later start and later end

+			body.setValidTo(defaultEndDate);

+			to = DateHelper.getDate(2018, 10, 1, 23, 0, 0);

+			from = DateHelper.getDate(2018, 10, 1, 19, 0, 0);

+			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);

+			assertTrue(boolResult);

+

+			// test success - later start and earlier end

+			body.setValidTo(defaultEndDate);

+			to = DateHelper.getDate(2018, 10, 1, 21, 0, 0);

+			from = DateHelper.getDate(2018, 10, 1, 19, 0, 0);

+			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);

+			assertTrue(boolResult);

+

+			// test success - overlaping start

+			body.setValidTo(defaultEndDate);

+			to = defaultEndDate;

+			from = DateHelper.getDate(2018, 9, 30, 19, 0, 0);

+			boolResult = planningController.splitScheduleBody(body, from, to, newUser, modifiedBy);

+			assertTrue(boolResult);

+		} catch (Exception e) {

+			assertNull(e);

+		}

+	}

+

+	@Test

+	public void moveUserInPlanTest() {

+		StandbyScheduleActionDto actionDto = new StandbyScheduleActionDto();

+		actionDto.setScheduleBodyId(1L);

+		actionDto.setValidFrom(new Date());

+		actionDto.setValidTo(new Date());

+		actionDto.setNewUserId(1L);

+		actionDto.setStandbyGroupId(1L);

+		String username = "JUnit";

+

+		StandbyScheduleBody responseBody = new StandbyScheduleBody();

+		responseBody.setId(1L);

+		StandbyStatus status = new StandbyStatus();

+		status.setId(SpMsg.STATUS_PLANNING);

+		responseBody.setStatus(status);

+		StandbyGroup responseGroup = new StandbyGroup();

+		responseGroup.setId(1L);

+		responseBody.setStandbyGroup(responseGroup);

+		when(standbyScheduleBodyRepository.findOne(Mockito.any())).thenReturn(responseBody);

+		when(standbyGroupRepository.findOne(actionDto.getStandbyGroupId())).thenReturn(responseGroup);

+		when(standbyScheduleBodyRepository.save(Mockito.any(StandbyScheduleBody.class))).thenReturn(responseBody);

+

+		// test success - equal date

+		try {

+			when(validationController.startValidation(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),

+					Mockito.any(), Mockito.any())).thenReturn(new ArrayList<PlanningMsgDto>());

+			when(userController.isUserValid(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenReturn(true);

+			when(userController.isUserInGroup(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), Mockito.any()))

+					.thenReturn(true);

+			when(archiveController.createArchiveOnMove(Mockito.any(), Mockito.any())).thenReturn(true);

+			// when(mailRequestSendDate.sendMail(Mockito.any(), Mockito.any(),

+			// Mockito.any(), Mockito.any()))

+			// .thenReturn(null);

+

+			planningController.moveUserInPlan(actionDto, username);

+		} catch (Exception e) {

+			assertNull(e);

+		}

+

+		// test success - different date

+		actionDto.setValidTo(DateHelper.addDaysToDate(new Date(), 3));

+		try {

+			when(userController.isUserValid(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenReturn(true);

+			when(userController.isUserInGroup(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), Mockito.any()))

+					.thenReturn(true);

+			planningController.moveUserInPlan(actionDto, username);

+		} catch (Exception e) {

+			assertNull(e);

+		}

+

+		// test success - bigger from date

+		actionDto.setValidFrom(DateHelper.addDaysToDate(new Date(), 3));

+		actionDto.setValidTo(new Date());

+		try {

+			when(userController.isUserValid(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenReturn(true);

+			when(userController.isUserInGroup(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), Mockito.any()))

+					.thenReturn(true);

+			planningController.moveUserInPlan(actionDto, username);

+		} catch (Exception e) {

+			assertNull(e);

+		}

+

+		// test error handling

+		Mockito.doThrow(new IllegalArgumentException()).when(standbyScheduleBodyRepository).findOne(Mockito.any());

+		try {

+			planningController.moveUserInPlan(actionDto, username);

+		} catch (Exception e) {

+			assertNotNull(e);

+		}

+	}

+

+	/**

+	 * method to get a test data UserInStandbyGroup List.

+	 * 

+	 * @return

+	 */

+	private List<UserInStandbyGroup> getTestDataForUserInStandbyGroups() {

+		List<UserInStandbyGroup> lsUserInStandbyGroups = new ArrayList<>();

+		UserInStandbyGroup uisg = new UserInStandbyGroup();

+		uisg.setId(1l);

+		uisg.setStandbyGroup(new StandbyGroup());

+		uisg.setPosition(3);

+		User user = new User();

+		user.setId(1L);

+		user.setFirstname("J.");

+		user.setLastname("Unit");

+		uisg.setUser(user);

+		lsUserInStandbyGroups.add(uisg);

+		uisg = new UserInStandbyGroup();

+		uisg.setId(2l);

+		uisg.setStandbyGroup(new StandbyGroup());

+		uisg.setPosition(1);

+		user = new User();

+		user.setId(2L);

+		user.setFirstname("Nr.");

+		user.setLastname("Zwei");

+		uisg.setUser(user);

+		lsUserInStandbyGroups.add(uisg);

+		return lsUserInStandbyGroups;

+	}

+

+	@Test

+	public void calculateHolidayTest() {

+		StandbyGroup group = new StandbyGroup();

+		Date date = DateHelper.getDate(2018, 1, 1);

+		StandbyScheduleBody stbyBody = new StandbyScheduleBody();

+		StandbyScheduleBody resultExtend = new StandbyScheduleBody();

+		resultExtend.setId(1L);

+		StandbyScheduleBody resultPreDraw = new StandbyScheduleBody();

+		resultPreDraw.setId(2L);

+

+		try {

+			Mockito.doReturn(true).when(planningController).isHoliday(Mockito.any(Date.class),

+					Mockito.any(StandbyGroup.class));

+			Mockito.doReturn(resultExtend).when(planningController).calculateHolidayExtend(Mockito.any(), Mockito.any(),

+					Mockito.any());

+			Mockito.doReturn(resultPreDraw).when(planningController).calculateHolidayPreDraw(Mockito.any(),

+					Mockito.any(), Mockito.any());

+

+			// test success 01 - holiday extend

+			group.setExtendStandbyTime(true);

+			StandbyScheduleBody result = planningController.calculateHoliday(group, date, stbyBody);

+			assertNotNull(result);

+			assertTrue(result.getId() == 1);

+

+			// test success 02 - holiday pre draw

+			group.setExtendStandbyTime(false);

+			result = planningController.calculateHoliday(group, date, stbyBody);

+			assertTrue(result.getId() == 2);

+			assertNotNull(result);

+

+			// test success 03 - no holiday

+			Mockito.doReturn(false).when(planningController).isHoliday(Mockito.any(Date.class),

+					Mockito.any(StandbyGroup.class));

+			result = planningController.calculateHoliday(group, date, stbyBody);

+			assertNotNull(result);

+

+		} catch (Exception e) {

+			assertNull(e);

+		}

+	}

+

+	@Test

+	public void calculateHolidayExtendTest() {

+		StandbyGroup group = new StandbyGroup();

+		group.setExtendStandbyTime(false);

+		Date date = DateHelper.getDate(2018, 1, 1, 10, 0, 0);

+		StandbyScheduleBody stbyBody = new StandbyScheduleBody();

+

+		StandbyDuration standbyDuration = new StandbyDuration();

+		standbyDuration.setValidFrom(date);

+		standbyDuration.setValidFrom(DateHelper.addDaysToDate(date, 1));

+

+		List<StandbyDuration> lsStandbyDurationsNull = new ArrayList<>();

+		lsStandbyDurationsNull.add(null);

+

+		List<StandbyDuration> lsStandbyDurations = new ArrayList<>();

+		StandbyDuration stbyDuration = new StandbyDuration();

+		// after valid from of stbyBody

+		stbyDuration.setValidFrom(DateHelper.getDate(2018, 1, 1, 20, 0, 0));

+		stbyDuration.setValidTo(DateHelper.getDate(2018, 1, 1, 22, 0, 0));

+		lsStandbyDurations.add(stbyDuration);

+

+		stbyDuration = new StandbyDuration();

+		// before valid from of stbyBody

+		stbyDuration.setValidFrom(DateHelper.getDate(2018, 1, 1, 8, 0, 0));

+		stbyDuration.setValidTo(DateHelper.getDate(2018, 1, 1, 9, 0, 0));

+		lsStandbyDurations.add(stbyDuration);

+

+		try {

+			StandbyScheduleBody result = null;

+			// success 01 - test null return date before valid from

+			stbyBody = this.getStandbyScheduleBody();

+			Mockito.doReturn(null).when(planningController).getFittingDurationsOfGroup(Mockito.any(StandbyGroup.class),

+					Mockito.any(Date.class));

+			result = planningController.calculateHolidayExtend(group, date, stbyBody);

+			assertNotNull(result);

+

+			// success 02 - test null return of list element

+			stbyBody = this.getStandbyScheduleBody();

+			Mockito.doReturn(lsStandbyDurationsNull).when(planningController)

+					.getFittingDurationsOfGroup(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));

+			result = planningController.calculateHolidayExtend(group, date, stbyBody);

+			assertNotNull(result);

+

+			// success 03 - test null return of list element

+			stbyBody = this.getStandbyScheduleBody();

+			Mockito.doReturn(lsStandbyDurations).when(planningController)

+					.getFittingDurationsOfGroup(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));

+			result = planningController.calculateHolidayExtend(group, date, stbyBody);

+			assertNotNull(result);

+

+		} catch (Exception e) {

+			LOGGER.error(e, e);

+			assertNull(e);

+		}

+	}

+

+	@Test

+	public void calculateHolidayPreDrawTest() {

+		StandbyGroup group = new StandbyGroup();

+		Date date = DateHelper.getDate(2018, 1, 1, 10, 0, 0);

+		StandbyScheduleBody stbyBody = this.getStandbyScheduleBody();

+

+		List<StandbyDuration> lsStandbyDurationsNull = new ArrayList<>();

+		lsStandbyDurationsNull.add(null);

+

+		List<StandbyDuration> lsStandbyDurations = new ArrayList<>();

+		StandbyDuration stbyDuration = new StandbyDuration();

+		// after valid from of stbyBody

+		stbyDuration.setValidFrom(DateHelper.getDate(2018, 1, 1, 20, 0, 0));

+		stbyDuration.setValidTo(DateHelper.getDate(2018, 1, 1, 22, 0, 0));

+		lsStandbyDurations.add(stbyDuration);

+

+		stbyDuration = new StandbyDuration();

+		// before valid from of stbyBody

+		stbyDuration.setValidFrom(DateHelper.getDate(2018, 1, 1, 8, 0, 0));

+		stbyDuration.setValidTo(DateHelper.getDate(2018, 1, 1, 9, 0, 0));

+		lsStandbyDurations.add(stbyDuration);

+

+		try {

+			StandbyScheduleBody result = null;

+

+			// success 01 - test null return date before valid from

+			stbyBody = this.getStandbyScheduleBody();

+			Mockito.doReturn(null).when(planningController)

+					.getFittingDurationsByValidTo(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));

+			result = planningController.calculateHolidayPreDraw(group, date, stbyBody);

+			assertNotNull(result);

+

+			// success 02 - dur = null

+			stbyBody = this.getStandbyScheduleBody();

+			Mockito.doReturn(lsStandbyDurationsNull).when(planningController)

+					.getFittingDurationsByValidTo(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));

+			result = planningController.calculateHolidayPreDraw(group, date, stbyBody);

+			assertNotNull(result);

+

+			// success 03 - duration before stbyBody

+			stbyBody = this.getStandbyScheduleBody();

+			Mockito.doReturn(lsStandbyDurations).when(planningController)

+					.getFittingDurationsByValidTo(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));

+			result = planningController.calculateHolidayPreDraw(group, date, stbyBody);

+			assertNotNull(result);

+

+			// success 04 - duration after stbyBody

+			stbyBody = this.getStandbyScheduleBody();

+			Mockito.doReturn(lsStandbyDurations).when(planningController)

+					.getFittingDurationsByValidTo(Mockito.any(StandbyGroup.class), Mockito.any(Date.class));

+			result = planningController.calculateHolidayPreDraw(group, DateHelper.getDate(2018, 1, 1, 23, 0, 0),

+					stbyBody);

+			assertNotNull(result);

+

+		} catch (Exception e) {

+			LOGGER.error(e, e);

+			assertNull(e);

+		}

+	}

+

+	private StandbyScheduleBody getStandbyScheduleBody() {

+		StandbyScheduleBody stbyBody = new StandbyScheduleBody();

+		stbyBody.setValidFrom(DateHelper.getDate(2018, 1, 1, 12, 0, 0));

+		stbyBody.setValidTo(DateHelper.getDate(2018, 1, 1, 18, 0, 0));

+		User user = new User();

+		user.setFirstname("J.");

+		user.setLastname("Unit");

+		stbyBody.setUser(user);

+		return stbyBody;

+	}

+}

diff --git a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/ValidationControllerTest.java b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/ValidationControllerTest.java
index e8a4de7..d831272 100644
--- a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/ValidationControllerTest.java
+++ b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/ValidationControllerTest.java
@@ -28,11 +28,9 @@
 import org.eclipse.openk.sp.db.model.StandbyGroup;
 import org.eclipse.openk.sp.db.model.StandbyList;
 import org.eclipse.openk.sp.db.model.StandbyListHasStandbyGroup;
-import org.eclipse.openk.sp.db.model.User;
 import org.eclipse.openk.sp.dto.ValidationDto;
 import org.eclipse.openk.sp.dto.planning.PlanningMsgDto;
 import org.eclipse.openk.sp.dto.planning.PlanningMsgResponseDto;
-import org.eclipse.openk.sp.dto.planning.StandbyScheduleActionDto;
 import org.eclipse.openk.sp.exceptions.SpException;
 import org.eclipse.openk.sp.util.DateHelper;
 import org.junit.Test;
@@ -91,18 +89,18 @@
 		Mockito.when(appContext.containsBean(Mockito.anyString())).thenReturn(true);
 		Mockito.when(appContext.getBean(Mockito.anyString())).thenReturn(groupCoverageValidator);
 		Mockito.when(groupCoverageValidator.execute(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),
-				Mockito.any())).thenReturn(new ArrayList<>());
+				Mockito.any(), Mockito.any())).thenReturn(new ArrayList<>());
 
 		try {
 			// positive test with existing bean
 			List<PlanningMsgDto> lsResult = validatonController.startValidation(from, till, lsStandbyGroups,
-					lsValidationBeanNames, statusId);
+					lsValidationBeanNames, statusId, null);
 			assertNotNull(lsResult);
 
 			// positive test without existing bean
 			Mockito.when(appContext.containsBean(Mockito.anyString())).thenReturn(false);
-			lsResult = validatonController.startValidation(from, till, lsStandbyGroups, lsValidationBeanNames,
-					statusId);
+			lsResult = validatonController.startValidation(from, till, lsStandbyGroups, lsValidationBeanNames, statusId,
+					null);
 			assertNotNull(lsResult);
 		} catch (Exception e) {
 			LOGGER.error(e, e);
@@ -114,7 +112,7 @@
 			Mockito.when(appContext.containsBean(Mockito.anyString())).thenReturn(true);
 			Mockito.when(appContext.getBean(Mockito.anyString())).thenThrow(new BeanDefinitionStoreException("test"));
 			List<PlanningMsgDto> lsResult = validatonController.startValidation(from, till, lsStandbyGroups,
-					lsValidationBeanNames, statusId);
+					lsValidationBeanNames, statusId, null);
 		} catch (Exception e) {
 			LOGGER.error(e, e);
 			assertNotNull(e);
@@ -125,7 +123,7 @@
 	@Test
 	public void startValidationWithDtoTest() {
 		StandbyList sbList = new StandbyList();
-//		List<StandbyGroup> lsStandbyGroups = new ArrayList<>();
+		// List<StandbyGroup> lsStandbyGroups = new ArrayList<>();
 		List<StandbyListHasStandbyGroup> lsStandbyListHasStandbyGroup = new ArrayList<>();
 		StandbyGroup group = new StandbyGroup();
 
@@ -184,38 +182,4 @@
 			assertNotNull(e);
 		}
 	}
-
-	@Test
-	public void validatePlanningActionInputTest() {
-		StandbyScheduleActionDto actionDto = new StandbyScheduleActionDto();
-		try {
-			Mockito.when(userController.isUserValid(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenReturn(false);
-			Mockito.when(
-					userController.isUserInGroup(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), Mockito.any()))
-					.thenReturn(false);
-			Mockito.when(userRepository.findOne(Mockito.anyLong())).thenReturn(new User());
-			Mockito.when(standbyGroupRepository.findOne(Mockito.anyLong())).thenReturn(new StandbyGroup());
-
-			// success test 1 (invalid path)
-			List<PlanningMsgDto> lsMsg = validatonController.validatePlanningActionInput(actionDto);
-			assertNotNull(lsMsg);
-
-			// success test 2 (valid path)
-			Mockito.when(userController.isUserValid(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenReturn(true);
-			Mockito.when(
-					userController.isUserInGroup(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), Mockito.any()))
-					.thenReturn(true);
-			lsMsg = validatonController.validatePlanningActionInput(actionDto);
-			assertNotNull(lsMsg);
-
-		} catch (Exception e) {
-			assertNull(e);
-		}
-
-		// failure test 1
-		try {
-		} catch (Exception e) {
-			assertNotNull(e);
-		}
-	}
 }
diff --git a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/DoublePlannedValidatorTest.java b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/DoublePlannedValidatorTest.java
index 7201bf9..5058610 100644
--- a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/DoublePlannedValidatorTest.java
+++ b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/DoublePlannedValidatorTest.java
@@ -120,14 +120,14 @@
 		Mockito.when(scheduleBodyRepository.findByUserHittingDateInterval(Mockito.any(), Mockito.any(), Mockito.any()))
 				.thenReturn(lsAlternativeScheduleBodies);
 		List<PlanningMsgDto> planningMsgDtos = doublePlannedValidator.execute(from, till, group1, lsStandbyGroups,
-				statusId);
+				statusId, null);
 		assertNotNull(planningMsgDtos);
 
 		// positive test - without group
 		Mockito.when(scheduleBodyRepository.findByUserHittingDateInterval(Mockito.any(), Mockito.any(), Mockito.any()))
 				.thenReturn(null);
 		List<PlanningMsgDto> planningMsgDtos2 = doublePlannedValidator.execute(from, till, group1, lsStandbyGroups,
-				statusId);
+				statusId, null);
 		assertNotNull(planningMsgDtos2);
 	}
 }
diff --git a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/GroupCoverageValidatorTest.java b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/GroupCoverageValidatorTest.java
index cea7530..0d47987 100644
--- a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/GroupCoverageValidatorTest.java
+++ b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/GroupCoverageValidatorTest.java
@@ -64,12 +64,12 @@
 		// positive test - with holiday
 		Mockito.when(planningController.isHoliday(Mockito.any(), Mockito.any())).thenReturn(true);
 		List<PlanningMsgDto> planningMsgDtos = groupCoverageValidator.execute(from, till, group, lsStandbyGroups,
-				statusId);
+				statusId, null);
 		assertNotNull(planningMsgDtos);
 
 		// positive test - without holiday
 		Mockito.when(planningController.isHoliday(Mockito.any(), Mockito.any())).thenReturn(false);
-		planningMsgDtos = groupCoverageValidator.execute(from, till, group, lsStandbyGroups, statusId);
+		planningMsgDtos = groupCoverageValidator.execute(from, till, group, lsStandbyGroups, statusId, null);
 		assertNotNull(planningMsgDtos);
 	}
 
diff --git a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/PlaceholderStandbyUserValidatorTest.java b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/PlaceholderStandbyUserValidatorTest.java
index 97007ed..20f83e8 100644
--- a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/PlaceholderStandbyUserValidatorTest.java
+++ b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/PlaceholderStandbyUserValidatorTest.java
@@ -132,7 +132,7 @@
 			Mockito.when(scheduleBodyRepository.findByGroupAndDateAndStatus(Mockito.any(), Mockito.any(), Mockito.any(),
 					Mockito.any())).thenReturn(lsScheduleBodies);
 			List<PlanningMsgDto> planningMsgDtos = placeholderUserValidator.execute(from, till, group, lsStandbyGroups,
-					statusId);
+					statusId, null);
 			assertNotNull(planningMsgDtos);
 		} catch (Exception e) {
 			assertNull(e);
@@ -143,7 +143,7 @@
 			when(fileHelper.getProperty(Mockito.any(), Mockito.any())).thenThrow(new IOException());
 			Mockito.when(scheduleBodyRepository.findByGroupAndDateAndStatus(Mockito.any(), Mockito.any(), Mockito.any(),
 					Mockito.any())).thenReturn(lsScheduleBodies);
-			placeholderUserValidator.execute(from, till, group, lsStandbyGroups, statusId);
+			placeholderUserValidator.execute(from, till, group, lsStandbyGroups, statusId, null);
 		} catch (Exception e) {
 			assertNotNull(e);
 		}
diff --git a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableForGroupValidatorTest.java b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableForGroupValidatorTest.java
new file mode 100644
index 0000000..776b020
--- /dev/null
+++ b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableForGroupValidatorTest.java
@@ -0,0 +1,116 @@
+/********************************************************************************
+ * Copyright (c) 2018 Mettenmeier GmbH 
+ *
+ * See the NOTICE file(s) distributed with this work for additional 
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the 
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0 
+ ********************************************************************************/
+package org.eclipse.openk.sp.controller.validation.validator;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.eclipse.openk.sp.controller.UserController;
+import org.eclipse.openk.sp.db.dao.StandbyGroupRepository;
+import org.eclipse.openk.sp.db.dao.UserRepository;
+import org.eclipse.openk.sp.db.model.StandbyGroup;
+import org.eclipse.openk.sp.db.model.StandbyStatus;
+import org.eclipse.openk.sp.db.model.User;
+import org.eclipse.openk.sp.dto.planning.PlanningMsgDto;
+import org.eclipse.openk.sp.exceptions.SpException;
+import org.eclipse.openk.sp.util.DateHelper;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/** Class to validate if all time slots are set for a group. */
+@RunWith(MockitoJUnitRunner.class)
+public class UserAvailableForGroupValidatorTest {
+	protected static final Logger LOGGER = Logger.getLogger(UserAvailableForGroupValidatorTest.class);
+	Properties p = new Properties();
+
+	@Mock
+	private UserController userController;
+
+	@Mock
+	private UserRepository userRepository;
+
+	@Mock
+	private StandbyGroupRepository standbyGroupRepository;
+
+	@InjectMocks
+	UserAvailableForGroupValidator userAvailableForGroupValidator;
+
+	@Before
+	public void init() {
+		p = new Properties();
+		p.setProperty("placeholder.standby.user.ids", "1,2,3,4");
+	}
+
+	@Test
+	public void executeTest() throws SpException {
+
+		Date from = DateHelper.getDate(2018, 9, 9);
+		Date till = DateHelper.getDate(2018, 9, 10);
+		StandbyGroup group = new StandbyGroup();
+		group.setTitle("title");
+
+		StandbyStatus status = new StandbyStatus();
+		status.setId(1L);
+		status.setTitle("TestEbene");
+
+		List<StandbyGroup> lsStandbyGroups = new ArrayList<>();
+		lsStandbyGroups.add(group);
+		lsStandbyGroups.add(group);
+		Long statusId = new Long(1);
+
+		User user1 = new User();
+		user1.setId(1L);
+		user1.setFirstname("First");
+		user1.setLastname("LastName");
+
+		// positive test
+		try {
+
+			Mockito.when(userController.isUserInGroup(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+					.thenReturn(true);
+			Mockito.when(userRepository.findOne(Mockito.any())).thenReturn(user1);
+			Mockito.when(standbyGroupRepository.findOne(Mockito.any())).thenReturn(group);
+			List<PlanningMsgDto> planningMsgDtos = userAvailableForGroupValidator.execute(from, till, group, lsStandbyGroups,
+					statusId, null);
+			assertNotNull(planningMsgDtos);
+		} catch (Exception e) {
+			assertNull(e);
+		}
+
+		// negative test
+		try {
+			Mockito.when(userController.isUserInGroup(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+					.thenReturn(false);
+			Mockito.when(userRepository.findOne(Mockito.any())).thenReturn(user1);
+			Mockito.when(standbyGroupRepository.findOne(Mockito.any())).thenReturn(group);
+			List<PlanningMsgDto> planningMsgDtos = userAvailableForGroupValidator.execute(from, till, group, lsStandbyGroups,
+					statusId, null);
+			assertNotNull(planningMsgDtos);
+			assertTrue(planningMsgDtos.size() == 1);
+		} catch (Exception e) {
+			assertNotNull(e);
+		}
+	}
+}
diff --git a/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableValidatorTest.java b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableValidatorTest.java
new file mode 100644
index 0000000..e3a067f
--- /dev/null
+++ b/oKBereitschaftsplanungBackend/src/test/java/org/eclipse/openk/sp/controller/validation/validator/UserAvailableValidatorTest.java
@@ -0,0 +1,110 @@
+/********************************************************************************
+ * Copyright (c) 2018 Mettenmeier GmbH 
+ *
+ * See the NOTICE file(s) distributed with this work for additional 
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the 
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0 
+ ********************************************************************************/
+package org.eclipse.openk.sp.controller.validation.validator;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.eclipse.openk.sp.controller.UserController;
+import org.eclipse.openk.sp.db.dao.UserRepository;
+import org.eclipse.openk.sp.db.model.StandbyGroup;
+import org.eclipse.openk.sp.db.model.StandbyStatus;
+import org.eclipse.openk.sp.db.model.User;
+import org.eclipse.openk.sp.dto.planning.PlanningMsgDto;
+import org.eclipse.openk.sp.exceptions.SpException;
+import org.eclipse.openk.sp.util.DateHelper;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/** Class to validate if all time slots are set for a group. */
+@RunWith(MockitoJUnitRunner.class)
+public class UserAvailableValidatorTest {
+	protected static final Logger LOGGER = Logger.getLogger(UserAvailableValidatorTest.class);
+	Properties p = new Properties();
+
+	@Mock
+	private UserController userController;
+
+	@Mock
+	private UserRepository userRepository;
+
+	@InjectMocks
+	UserAvailableValidator userAvailableValidator;
+
+	@Before
+	public void init() {
+		p = new Properties();
+		p.setProperty("placeholder.standby.user.ids", "1,2,3,4");
+	}
+
+	@Test
+	public void executeTest() throws SpException {
+
+		Date from = DateHelper.getDate(2018, 9, 9);
+		Date till = DateHelper.getDate(2018, 9, 10);
+		StandbyGroup group = new StandbyGroup();
+		group.setTitle("title");
+
+		StandbyStatus status = new StandbyStatus();
+		status.setId(1L);
+		status.setTitle("TestEbene");
+
+		List<StandbyGroup> lsStandbyGroups = new ArrayList<>();
+		lsStandbyGroups.add(group);
+		lsStandbyGroups.add(group);
+		Long statusId = new Long(1);
+
+		User user1 = new User();
+		user1.setId(1L);
+		user1.setFirstname("First");
+		user1.setLastname("LastName");
+
+		// positive test
+		try {
+
+			Mockito.when(userController.isUserInGroup(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+					.thenReturn(true);
+			Mockito.when(userRepository.findOne(Mockito.any())).thenReturn(user1);
+			List<PlanningMsgDto> planningMsgDtos = userAvailableValidator.execute(from, till, group, lsStandbyGroups,
+					statusId, null);
+			assertNotNull(planningMsgDtos);
+		} catch (Exception e) {
+			assertNull(e);
+		}
+
+		// negative test
+		try {
+			Mockito.when(userController.isUserInGroup(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+					.thenReturn(false);
+			Mockito.when(userRepository.findOne(Mockito.any())).thenReturn(user1);
+			List<PlanningMsgDto> planningMsgDtos = userAvailableValidator.execute(from, till, group, lsStandbyGroups,
+					statusId, null);
+			assertNotNull(planningMsgDtos);
+			assertTrue(planningMsgDtos.size() == 1);
+		} catch (Exception e) {
+			assertNotNull(e);
+		}
+	}
+}