[Bug #1132] Remove DayType enum in BaseCalendar
* Change message to show to user about the type of day * DayType enum is removed as it is not needed anymore FEA: ItEr75S04BugFixing
This commit is contained in:
parent
e910538d05
commit
6b746221ec
5 changed files with 32 additions and 134 deletions
|
|
@ -154,10 +154,6 @@ public class BaseCalendar extends IntegrationEntity implements ICalendar,
|
|||
|
||||
private Integer lastSequenceCode = 0;
|
||||
|
||||
public enum DayType {
|
||||
NORMAL, ZERO_HOURS, OWN_EXCEPTION, ANCESTOR_EXCEPTION
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for hibernate. Do not use!
|
||||
*/
|
||||
|
|
@ -633,20 +629,6 @@ public class BaseCalendar extends IntegrationEntity implements ICalendar,
|
|||
return copy;
|
||||
}
|
||||
|
||||
public DayType getType(LocalDate date) {
|
||||
CalendarException exceptionDay = getExceptionDay(date);
|
||||
if (exceptionDay != null) {
|
||||
if (getOwnExceptionDay(date) != null) {
|
||||
return DayType.OWN_EXCEPTION;
|
||||
}
|
||||
return DayType.ANCESTOR_EXCEPTION;
|
||||
}
|
||||
if (getCapacityOn(PartialDay.wholeDay(date)).isZero()) {
|
||||
return DayType.ZERO_HOURS;
|
||||
}
|
||||
return DayType.NORMAL;
|
||||
}
|
||||
|
||||
public List<CalendarData> getCalendarDataVersions() {
|
||||
return Collections.unmodifiableList(calendarDataVersions);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ import org.joda.time.LocalDate;
|
|||
import org.junit.Test;
|
||||
import org.navalplanner.business.calendars.entities.AvailabilityTimeLine;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar.DayType;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData.Days;
|
||||
import org.navalplanner.business.calendars.entities.CalendarException;
|
||||
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
|
||||
|
|
@ -545,31 +544,6 @@ public class BaseCalendarTest {
|
|||
nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
BaseCalendar calendar = createChristmasCalendar();
|
||||
|
||||
assertThat(calendar.getType(MONDAY_LOCAL_DATE), equalTo(DayType.NORMAL));
|
||||
assertThat(calendar.getType(SUNDAY_LOCAL_DATE),
|
||||
equalTo(DayType.ZERO_HOURS));
|
||||
assertThat(calendar.getType(CHRISTMAS_DAY_LOCAL_DATE),
|
||||
equalTo(DayType.OWN_EXCEPTION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTypeDerivedCalendar() {
|
||||
BaseCalendar calendar = createChristmasCalendar();
|
||||
BaseCalendar derived = calendar.newDerivedCalendar();
|
||||
|
||||
assertThat(derived.getType(MONDAY_LOCAL_DATE), equalTo(DayType.NORMAL));
|
||||
assertThat(derived.getType(SUNDAY_LOCAL_DATE), equalTo(DayType.ZERO_HOURS));
|
||||
assertThat(derived.getType(CHRISTMAS_DAY_LOCAL_DATE),
|
||||
equalTo(DayType.ANCESTOR_EXCEPTION));
|
||||
|
||||
assertThat(calendar.getType(CHRISTMAS_DAY_LOCAL_DATE),
|
||||
equalTo(DayType.OWN_EXCEPTION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetParent() {
|
||||
BaseCalendar calendar = createBasicCalendar();
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import java.util.Map;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar.DayType;
|
||||
import org.navalplanner.business.calendars.entities.CalendarAvailability;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData.Days;
|
||||
|
|
@ -573,67 +572,28 @@ public abstract class BaseCalendarEditionController extends
|
|||
reloadSelectDayInformation();
|
||||
}
|
||||
|
||||
private Map<DayType, List<Integer>> getDaysCurrentMonthByType() {
|
||||
LocalDate currentDate = new LocalDate(baseCalendarModel
|
||||
.getSelectedDay());
|
||||
|
||||
LocalDate minDate = currentDate.dayOfMonth().withMinimumValue();
|
||||
LocalDate maxDate = currentDate.dayOfMonth().withMaximumValue();
|
||||
|
||||
List<Integer> ancestorExceptionsDays = new ArrayList<Integer>();
|
||||
List<Integer> ownExceptionDays = new ArrayList<Integer>();
|
||||
List<Integer> zeroHoursDays = new ArrayList<Integer>();
|
||||
List<Integer> normalDays = new ArrayList<Integer>();
|
||||
|
||||
for (LocalDate date = minDate; date.compareTo(maxDate) <= 0; date = date
|
||||
.plusDays(1)) {
|
||||
DayType typeOfDay = baseCalendarModel.getTypeOfDay(date);
|
||||
if (typeOfDay != null) {
|
||||
switch (typeOfDay) {
|
||||
case ANCESTOR_EXCEPTION:
|
||||
ancestorExceptionsDays.add(date.getDayOfMonth());
|
||||
break;
|
||||
case OWN_EXCEPTION:
|
||||
ownExceptionDays.add(date.getDayOfMonth());
|
||||
break;
|
||||
case ZERO_HOURS:
|
||||
zeroHoursDays.add(date.getDayOfMonth());
|
||||
break;
|
||||
case NORMAL:
|
||||
default:
|
||||
normalDays.add(date.getDayOfMonth());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<DayType, List<Integer>> result = new HashMap<DayType, List<Integer>>();
|
||||
|
||||
result.put(DayType.ANCESTOR_EXCEPTION, ancestorExceptionsDays);
|
||||
result.put(DayType.OWN_EXCEPTION, ownExceptionDays);
|
||||
result.put(DayType.ZERO_HOURS, zeroHoursDays);
|
||||
result.put(DayType.NORMAL, normalDays);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getTypeOfDay() {
|
||||
DayType typeOfDay = baseCalendarModel.getTypeOfDay();
|
||||
if (typeOfDay == null) {
|
||||
BaseCalendar calendar = baseCalendarModel.getBaseCalendar();
|
||||
if (calendar == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
switch (typeOfDay) {
|
||||
case ANCESTOR_EXCEPTION:
|
||||
return _("Derived exception");
|
||||
case OWN_EXCEPTION:
|
||||
return _("Exception");
|
||||
case ZERO_HOURS:
|
||||
return _("Not working day");
|
||||
case NORMAL:
|
||||
default:
|
||||
return _("Normal");
|
||||
LocalDate date = baseCalendarModel.getSelectedDay();
|
||||
CalendarException exceptionDay = calendar.getExceptionDay(date);
|
||||
if (exceptionDay != null) {
|
||||
if (calendar.getOwnExceptionDay(date) != null) {
|
||||
return _("Exception: {0}", exceptionDay.getType().getName());
|
||||
} else {
|
||||
return _("Exception: {0} (Inh)", exceptionDay.getType()
|
||||
.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (calendar.getCapacityOn(PartialDay.wholeDay(date)).isZero()) {
|
||||
return _("Not working day");
|
||||
}
|
||||
|
||||
return _("Normal");
|
||||
}
|
||||
|
||||
public String getWorkableTime() {
|
||||
|
|
@ -1276,11 +1236,7 @@ public abstract class BaseCalendarEditionController extends
|
|||
}
|
||||
|
||||
public boolean isOwnExceptionDay() {
|
||||
DayType typeOfDay = baseCalendarModel.getTypeOfDay();
|
||||
if ((typeOfDay != null) && (typeOfDay.equals(DayType.OWN_EXCEPTION))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return baseCalendarModel.isOwnExceptionDay();
|
||||
}
|
||||
|
||||
public boolean isNotOwnExceptionDay() {
|
||||
|
|
|
|||
|
|
@ -36,12 +36,11 @@ import org.navalplanner.business.calendars.daos.ICalendarExceptionTypeDAO;
|
|||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.calendars.entities.CalendarAvailability;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData.Days;
|
||||
import org.navalplanner.business.calendars.entities.CalendarException;
|
||||
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
|
||||
import org.navalplanner.business.calendars.entities.Capacity;
|
||||
import org.navalplanner.business.calendars.entities.ResourceCalendar;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar.DayType;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData.Days;
|
||||
import org.navalplanner.business.common.IntegrationEntity;
|
||||
import org.navalplanner.business.common.daos.IConfigurationDAO;
|
||||
import org.navalplanner.business.common.entities.Configuration;
|
||||
|
|
@ -283,30 +282,12 @@ public class BaseCalendarModel extends IntegrationEntityModel implements
|
|||
return getBaseCalendar().getCapacityWithOvertime(selectedDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DayType getTypeOfDay() {
|
||||
if (getBaseCalendar() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getBaseCalendar().getType(selectedDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DayType getTypeOfDay(LocalDate date) {
|
||||
if (getBaseCalendar() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getBaseCalendar().getType(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createException(CalendarExceptionType type,
|
||||
LocalDate startDate, LocalDate endDate, Capacity capacity) {
|
||||
for (LocalDate date = startDate; date.compareTo(endDate) <= 0; date = date
|
||||
.plusDays(1)) {
|
||||
if (getTypeOfDay(date).equals(DayType.OWN_EXCEPTION)) {
|
||||
if (baseCalendar.getOwnExceptionDay(date) != null) {
|
||||
getBaseCalendar().updateExceptionDay(date, capacity, type);
|
||||
} else {
|
||||
CalendarException day = CalendarException.create("", date,
|
||||
|
|
@ -734,7 +715,7 @@ public class BaseCalendarModel extends IntegrationEntityModel implements
|
|||
for (LocalDate date = new LocalDate(startDate); date
|
||||
.compareTo(new LocalDate(endDate)) <= 0; date = date
|
||||
.plusDays(1)) {
|
||||
if (getTypeOfDay(date).equals(DayType.OWN_EXCEPTION)) {
|
||||
if (baseCalendar.getOwnExceptionDay(date) != null) {
|
||||
if (type == null) {
|
||||
getBaseCalendar().removeExceptionDay(date);
|
||||
} else {
|
||||
|
|
@ -876,4 +857,12 @@ public class BaseCalendarModel extends IntegrationEntityModel implements
|
|||
baseCalendarDAO.checkIsReferencedByOtherEntities(calendar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwnExceptionDay() {
|
||||
if (baseCalendar != null) {
|
||||
return (baseCalendar.getOwnExceptionDay(selectedDate) != null);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,11 +29,10 @@ import org.joda.time.LocalDate;
|
|||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.calendars.entities.CalendarAvailability;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData.Days;
|
||||
import org.navalplanner.business.calendars.entities.CalendarException;
|
||||
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
|
||||
import org.navalplanner.business.calendars.entities.Capacity;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar.DayType;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData.Days;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.web.common.IIntegrationEntityModel;
|
||||
|
|
@ -108,10 +107,6 @@ public interface IBaseCalendarModel extends IIntegrationEntityModel {
|
|||
|
||||
LocalDate getSelectedDay();
|
||||
|
||||
DayType getTypeOfDay();
|
||||
|
||||
DayType getTypeOfDay(LocalDate date);
|
||||
|
||||
EffortDuration getWorkableTime();
|
||||
|
||||
Capacity getWorkableCapacity();
|
||||
|
|
@ -225,4 +220,6 @@ public interface IBaseCalendarModel extends IIntegrationEntityModel {
|
|||
void checkAndChangeStartDate(CalendarData version, Date date)
|
||||
throws ValidationException;
|
||||
|
||||
boolean isOwnExceptionDay();
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue