@Test public void should_map_with_day_type_days_in_week() throws Exception { CalendarRecurrence recurrence = new CalendarRecurrence.Builder() .withMonths(Calendar.JANUARY, Calendar.FEBRUARY) .withHours(HoursTimeFormat.parse("1")) .withMinutes(MinutesTimeFormat.parse("2")) .withDaysInWeek(Calendar.MONDAY, Calendar.THURSDAY) .build(); Trigger trigger = new Trigger.Builder() .withRecurrence(recurrence) .build(); JobForm form = formFactory.givenJobFormBuilderWithValues() .withTrigger(trigger) .build(); mapperUnderTest.mapFormOnEntity(form, formEntity); JobCalendarTriggerEntity calendarTrigger = formEntity.getCalendarTrigger(); assertThat(calendarTrigger.getMonths(), hasItems(Calendar.JANUARY + 1, Calendar.FEBRUARY + 1)); assertThat(calendarTrigger.getHours(), is("1")); assertThat(calendarTrigger.getMinutes(), is("2")); assertThat(calendarTrigger.getDaysType(), is("WEEK")); assertThat(calendarTrigger.getWeekDays(), hasItems(Calendar.MONDAY, Calendar.THURSDAY)); assertThat(calendarTrigger.getMonthDays(), is("")); }
@Override public void mapFormOnEntity(JobForm form, JobFormEntity entity) { Trigger trigger = form.getTrigger(); CalendarRecurrence recurrence = (CalendarRecurrence) trigger.getRecurrence(); JobCalendarTriggerEntity calendarTrigger = new JobCalendarTriggerEntity(); calendarTrigger.setCalendarName(trigger.getCalendarName()); mapCommonTriggerFieldsOnEntity(form, calendarTrigger); DaysType daysType = recurrence.getDaysType(); if (daysType == null) { calendarTrigger.setDaysType("ALL"); calendarTrigger.setWeekDays(Collections.<Integer>emptySet()); calendarTrigger.setMonthDays(""); } else if (daysType instanceof DaysInWeek) { DaysInWeek daysInWeek = (DaysInWeek) daysType; calendarTrigger.setWeekDays(daysInWeek.getDays()); calendarTrigger.setDaysType("WEEK"); calendarTrigger.setMonthDays(""); } else if (daysType instanceof DaysInMonth) { DaysInMonth type = (DaysInMonth) daysType; calendarTrigger.setMonthDays(type.toString()); calendarTrigger.setDaysType("MONTH"); calendarTrigger.setWeekDays(Collections.<Integer>emptySet()); } EndDate endDate = trigger.getEndDate(); if (endDate instanceof UntilEndDate) { UntilEndDate date = (UntilEndDate) endDate; mapEndDate(date, calendarTrigger); } calendarTrigger.setMinutes(recurrence.getMinutes().toString()); calendarTrigger.setHours(recurrence.getHours().toString()); calendarTrigger.setMonths(mapMonthsToEntity(recurrence.getMonths())); entity.setCalendarTrigger(calendarTrigger); }
JobCalendarTriggerMapper extends BaseTriggerMapper { @Override public void mapFormOnEntity(JobForm form, JobFormEntity entity) { Trigger trigger = form.getTrigger(); CalendarRecurrence recurrence = (CalendarRecurrence) trigger.getRecurrence(); JobCalendarTriggerEntity calendarTrigger = new JobCalendarTriggerEntity(); calendarTrigger.setCalendarName(trigger.getCalendarName()); mapCommonTriggerFieldsOnEntity(form, calendarTrigger); DaysType daysType = recurrence.getDaysType(); if (daysType == null) { calendarTrigger.setDaysType("ALL"); calendarTrigger.setWeekDays(Collections.<Integer>emptySet()); calendarTrigger.setMonthDays(""); } else if (daysType instanceof DaysInWeek) { DaysInWeek daysInWeek = (DaysInWeek) daysType; calendarTrigger.setWeekDays(daysInWeek.getDays()); calendarTrigger.setDaysType("WEEK"); calendarTrigger.setMonthDays(""); } else if (daysType instanceof DaysInMonth) { DaysInMonth type = (DaysInMonth) daysType; calendarTrigger.setMonthDays(type.toString()); calendarTrigger.setDaysType("MONTH"); calendarTrigger.setWeekDays(Collections.<Integer>emptySet()); } EndDate endDate = trigger.getEndDate(); if (endDate instanceof UntilEndDate) { UntilEndDate date = (UntilEndDate) endDate; mapEndDate(date, calendarTrigger); } calendarTrigger.setMinutes(recurrence.getMinutes().toString()); calendarTrigger.setHours(recurrence.getHours().toString()); calendarTrigger.setMonths(mapMonthsToEntity(recurrence.getMonths())); entity.setCalendarTrigger(calendarTrigger); } }
JobCalendarTriggerMapper extends BaseTriggerMapper { @Override public void mapFormOnEntity(JobForm form, JobFormEntity entity) { Trigger trigger = form.getTrigger(); CalendarRecurrence recurrence = (CalendarRecurrence) trigger.getRecurrence(); JobCalendarTriggerEntity calendarTrigger = new JobCalendarTriggerEntity(); calendarTrigger.setCalendarName(trigger.getCalendarName()); mapCommonTriggerFieldsOnEntity(form, calendarTrigger); DaysType daysType = recurrence.getDaysType(); if (daysType == null) { calendarTrigger.setDaysType("ALL"); calendarTrigger.setWeekDays(Collections.<Integer>emptySet()); calendarTrigger.setMonthDays(""); } else if (daysType instanceof DaysInWeek) { DaysInWeek daysInWeek = (DaysInWeek) daysType; calendarTrigger.setWeekDays(daysInWeek.getDays()); calendarTrigger.setDaysType("WEEK"); calendarTrigger.setMonthDays(""); } else if (daysType instanceof DaysInMonth) { DaysInMonth type = (DaysInMonth) daysType; calendarTrigger.setMonthDays(type.toString()); calendarTrigger.setDaysType("MONTH"); calendarTrigger.setWeekDays(Collections.<Integer>emptySet()); } EndDate endDate = trigger.getEndDate(); if (endDate instanceof UntilEndDate) { UntilEndDate date = (UntilEndDate) endDate; mapEndDate(date, calendarTrigger); } calendarTrigger.setMinutes(recurrence.getMinutes().toString()); calendarTrigger.setHours(recurrence.getHours().toString()); calendarTrigger.setMonths(mapMonthsToEntity(recurrence.getMonths())); entity.setCalendarTrigger(calendarTrigger); }  }
JobCalendarTriggerMapper extends BaseTriggerMapper { @Override public void mapFormOnEntity(JobForm form, JobFormEntity entity) { Trigger trigger = form.getTrigger(); CalendarRecurrence recurrence = (CalendarRecurrence) trigger.getRecurrence(); JobCalendarTriggerEntity calendarTrigger = new JobCalendarTriggerEntity(); calendarTrigger.setCalendarName(trigger.getCalendarName()); mapCommonTriggerFieldsOnEntity(form, calendarTrigger); DaysType daysType = recurrence.getDaysType(); if (daysType == null) { calendarTrigger.setDaysType("ALL"); calendarTrigger.setWeekDays(Collections.<Integer>emptySet()); calendarTrigger.setMonthDays(""); } else if (daysType instanceof DaysInWeek) { DaysInWeek daysInWeek = (DaysInWeek) daysType; calendarTrigger.setWeekDays(daysInWeek.getDays()); calendarTrigger.setDaysType("WEEK"); calendarTrigger.setMonthDays(""); } else if (daysType instanceof DaysInMonth) { DaysInMonth type = (DaysInMonth) daysType; calendarTrigger.setMonthDays(type.toString()); calendarTrigger.setDaysType("MONTH"); calendarTrigger.setWeekDays(Collections.<Integer>emptySet()); } EndDate endDate = trigger.getEndDate(); if (endDate instanceof UntilEndDate) { UntilEndDate date = (UntilEndDate) endDate; mapEndDate(date, calendarTrigger); } calendarTrigger.setMinutes(recurrence.getMinutes().toString()); calendarTrigger.setHours(recurrence.getHours().toString()); calendarTrigger.setMonths(mapMonthsToEntity(recurrence.getMonths())); entity.setCalendarTrigger(calendarTrigger); }  @Override void mapFormOnEntity(JobForm form, JobFormEntity entity); @Override void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity); }
JobCalendarTriggerMapper extends BaseTriggerMapper { @Override public void mapFormOnEntity(JobForm form, JobFormEntity entity) { Trigger trigger = form.getTrigger(); CalendarRecurrence recurrence = (CalendarRecurrence) trigger.getRecurrence(); JobCalendarTriggerEntity calendarTrigger = new JobCalendarTriggerEntity(); calendarTrigger.setCalendarName(trigger.getCalendarName()); mapCommonTriggerFieldsOnEntity(form, calendarTrigger); DaysType daysType = recurrence.getDaysType(); if (daysType == null) { calendarTrigger.setDaysType("ALL"); calendarTrigger.setWeekDays(Collections.<Integer>emptySet()); calendarTrigger.setMonthDays(""); } else if (daysType instanceof DaysInWeek) { DaysInWeek daysInWeek = (DaysInWeek) daysType; calendarTrigger.setWeekDays(daysInWeek.getDays()); calendarTrigger.setDaysType("WEEK"); calendarTrigger.setMonthDays(""); } else if (daysType instanceof DaysInMonth) { DaysInMonth type = (DaysInMonth) daysType; calendarTrigger.setMonthDays(type.toString()); calendarTrigger.setDaysType("MONTH"); calendarTrigger.setWeekDays(Collections.<Integer>emptySet()); } EndDate endDate = trigger.getEndDate(); if (endDate instanceof UntilEndDate) { UntilEndDate date = (UntilEndDate) endDate; mapEndDate(date, calendarTrigger); } calendarTrigger.setMinutes(recurrence.getMinutes().toString()); calendarTrigger.setHours(recurrence.getHours().toString()); calendarTrigger.setMonths(mapMonthsToEntity(recurrence.getMonths())); entity.setCalendarTrigger(calendarTrigger); }  @Override void mapFormOnEntity(JobForm form, JobFormEntity entity); @Override void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity);  }