@Test public void should_map_calendar_trigger_with_all_type() throws Exception { JobCalendarTriggerEntity calendarTrigger = new JobCalendarTriggerEntity(); calendarTrigger.setMonths(new HashSet<>(Arrays.asList(Calendar.FEBRUARY + 1))); calendarTrigger.setMinutes("30"); calendarTrigger.setHours("3"); calendarTrigger.setDaysType("ALL"); calendarTrigger.setEndDate(formFactory.provideEndDateSrc()); formEntity.setCalendarTrigger(calendarTrigger); JobForm.Builder jobFormBuilder = formFactory.givenJobFormBuilderWithValues(); mapperUnderTest.mapEntityOnForm(jobFormBuilder, formEntity); JobForm expected = jobFormBuilder.build(); Trigger trigger = expected.getTrigger(); CalendarRecurrence calendarRecurrence = (CalendarRecurrence) trigger.getRecurrence(); UntilEndDate endDate = (UntilEndDate) trigger.getEndDate(); assertThat(calendarRecurrence.getMinutes().toString(), is("30")); assertThat(calendarRecurrence.getHours().toString(), is("3")); assertThat(calendarRecurrence.getMonths(), hasItems(Calendar.FEBRUARY)); DaysInWeek daysType = (DaysInWeek) calendarRecurrence.getDaysType(); assertThat(daysType.getDays(), hasItems(Calendar.SUNDAY, Calendar.MONDAY, Calendar.TUESDAY, Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY)); }
@Override public void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity) { JobCalendarTriggerEntity calendarTrigger = entity.getCalendarTrigger(); CalendarRecurrence.Builder recurrenceBuilder = new CalendarRecurrence.Builder() .withMinutes(MinutesTimeFormat.parse(calendarTrigger.getMinutes())) .withHours(HoursTimeFormat.parse(calendarTrigger.getHours())) .withMonths(mapMonthsToData(calendarTrigger.getMonths())); String daysType = calendarTrigger.getDaysType(); if ("ALL".equals(daysType)) { recurrenceBuilder.withDaysInWeek(ALL_WEEK_DAYS); } else if ("WEEK".equals(daysType)) { recurrenceBuilder.withDaysInWeek(calendarTrigger.getWeekDays()); } else if ("MONTH".equals(daysType)) { recurrenceBuilder.withDaysInMonth(DaysInMonth.valueOf(calendarTrigger.getMonthDays())); } CalendarRecurrence calendarRecurrence = recurrenceBuilder.build(); Trigger.CalendarTriggerBuilder triggerBuilder = new Trigger.Builder() .withCalendarName(calendarTrigger.getCalendarName()) .withRecurrence(calendarRecurrence); Date endDate = null; String endDateString = calendarTrigger.getEndDate(); if (endDateString != null) { endDate = parseDate(endDateString); } if (endDate != null) { triggerBuilder.withEndDate(new UntilEndDate(endDate)); } Trigger trigger = triggerBuilder.build(); form.withTrigger(trigger); }
JobCalendarTriggerMapper extends BaseTriggerMapper { @Override public void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity) { JobCalendarTriggerEntity calendarTrigger = entity.getCalendarTrigger(); CalendarRecurrence.Builder recurrenceBuilder = new CalendarRecurrence.Builder() .withMinutes(MinutesTimeFormat.parse(calendarTrigger.getMinutes())) .withHours(HoursTimeFormat.parse(calendarTrigger.getHours())) .withMonths(mapMonthsToData(calendarTrigger.getMonths())); String daysType = calendarTrigger.getDaysType(); if ("ALL".equals(daysType)) { recurrenceBuilder.withDaysInWeek(ALL_WEEK_DAYS); } else if ("WEEK".equals(daysType)) { recurrenceBuilder.withDaysInWeek(calendarTrigger.getWeekDays()); } else if ("MONTH".equals(daysType)) { recurrenceBuilder.withDaysInMonth(DaysInMonth.valueOf(calendarTrigger.getMonthDays())); } CalendarRecurrence calendarRecurrence = recurrenceBuilder.build(); Trigger.CalendarTriggerBuilder triggerBuilder = new Trigger.Builder() .withCalendarName(calendarTrigger.getCalendarName()) .withRecurrence(calendarRecurrence); Date endDate = null; String endDateString = calendarTrigger.getEndDate(); if (endDateString != null) { endDate = parseDate(endDateString); } if (endDate != null) { triggerBuilder.withEndDate(new UntilEndDate(endDate)); } Trigger trigger = triggerBuilder.build(); form.withTrigger(trigger); } }
JobCalendarTriggerMapper extends BaseTriggerMapper { @Override public void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity) { JobCalendarTriggerEntity calendarTrigger = entity.getCalendarTrigger(); CalendarRecurrence.Builder recurrenceBuilder = new CalendarRecurrence.Builder() .withMinutes(MinutesTimeFormat.parse(calendarTrigger.getMinutes())) .withHours(HoursTimeFormat.parse(calendarTrigger.getHours())) .withMonths(mapMonthsToData(calendarTrigger.getMonths())); String daysType = calendarTrigger.getDaysType(); if ("ALL".equals(daysType)) { recurrenceBuilder.withDaysInWeek(ALL_WEEK_DAYS); } else if ("WEEK".equals(daysType)) { recurrenceBuilder.withDaysInWeek(calendarTrigger.getWeekDays()); } else if ("MONTH".equals(daysType)) { recurrenceBuilder.withDaysInMonth(DaysInMonth.valueOf(calendarTrigger.getMonthDays())); } CalendarRecurrence calendarRecurrence = recurrenceBuilder.build(); Trigger.CalendarTriggerBuilder triggerBuilder = new Trigger.Builder() .withCalendarName(calendarTrigger.getCalendarName()) .withRecurrence(calendarRecurrence); Date endDate = null; String endDateString = calendarTrigger.getEndDate(); if (endDateString != null) { endDate = parseDate(endDateString); } if (endDate != null) { triggerBuilder.withEndDate(new UntilEndDate(endDate)); } Trigger trigger = triggerBuilder.build(); form.withTrigger(trigger); }  }
JobCalendarTriggerMapper extends BaseTriggerMapper { @Override public void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity) { JobCalendarTriggerEntity calendarTrigger = entity.getCalendarTrigger(); CalendarRecurrence.Builder recurrenceBuilder = new CalendarRecurrence.Builder() .withMinutes(MinutesTimeFormat.parse(calendarTrigger.getMinutes())) .withHours(HoursTimeFormat.parse(calendarTrigger.getHours())) .withMonths(mapMonthsToData(calendarTrigger.getMonths())); String daysType = calendarTrigger.getDaysType(); if ("ALL".equals(daysType)) { recurrenceBuilder.withDaysInWeek(ALL_WEEK_DAYS); } else if ("WEEK".equals(daysType)) { recurrenceBuilder.withDaysInWeek(calendarTrigger.getWeekDays()); } else if ("MONTH".equals(daysType)) { recurrenceBuilder.withDaysInMonth(DaysInMonth.valueOf(calendarTrigger.getMonthDays())); } CalendarRecurrence calendarRecurrence = recurrenceBuilder.build(); Trigger.CalendarTriggerBuilder triggerBuilder = new Trigger.Builder() .withCalendarName(calendarTrigger.getCalendarName()) .withRecurrence(calendarRecurrence); Date endDate = null; String endDateString = calendarTrigger.getEndDate(); if (endDateString != null) { endDate = parseDate(endDateString); } if (endDate != null) { triggerBuilder.withEndDate(new UntilEndDate(endDate)); } Trigger trigger = triggerBuilder.build(); form.withTrigger(trigger); }  @Override void mapFormOnEntity(JobForm form, JobFormEntity entity); @Override void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity); }
JobCalendarTriggerMapper extends BaseTriggerMapper { @Override public void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity) { JobCalendarTriggerEntity calendarTrigger = entity.getCalendarTrigger(); CalendarRecurrence.Builder recurrenceBuilder = new CalendarRecurrence.Builder() .withMinutes(MinutesTimeFormat.parse(calendarTrigger.getMinutes())) .withHours(HoursTimeFormat.parse(calendarTrigger.getHours())) .withMonths(mapMonthsToData(calendarTrigger.getMonths())); String daysType = calendarTrigger.getDaysType(); if ("ALL".equals(daysType)) { recurrenceBuilder.withDaysInWeek(ALL_WEEK_DAYS); } else if ("WEEK".equals(daysType)) { recurrenceBuilder.withDaysInWeek(calendarTrigger.getWeekDays()); } else if ("MONTH".equals(daysType)) { recurrenceBuilder.withDaysInMonth(DaysInMonth.valueOf(calendarTrigger.getMonthDays())); } CalendarRecurrence calendarRecurrence = recurrenceBuilder.build(); Trigger.CalendarTriggerBuilder triggerBuilder = new Trigger.Builder() .withCalendarName(calendarTrigger.getCalendarName()) .withRecurrence(calendarRecurrence); Date endDate = null; String endDateString = calendarTrigger.getEndDate(); if (endDateString != null) { endDate = parseDate(endDateString); } if (endDate != null) { triggerBuilder.withEndDate(new UntilEndDate(endDate)); } Trigger trigger = triggerBuilder.build(); form.withTrigger(trigger); }  @Override void mapFormOnEntity(JobForm form, JobFormEntity entity); @Override void mapEntityOnForm(JobForm.Builder form, JobFormEntity entity);  }