ScheduleConverters { @NonNull static <T extends ScheduleData> Schedule<T> convert(@NonNull FullSchedule entry) throws JsonException, IllegalArgumentException, ClassCastException { Schedule.Builder<T> scheduleBuilder = createScheduleBuilder(entry.schedule.data, entry.schedule.scheduleType); scheduleBuilder = scheduleBuilder.setId(entry.schedule.scheduleId) .setMetadata(entry.schedule.metadata) .setGroup(entry.schedule.group) .setEnd(entry.schedule.scheduleEnd) .setStart(entry.schedule.scheduleStart) .setLimit(entry.schedule.limit) .setPriority(entry.schedule.priority) .setInterval(entry.schedule.interval, TimeUnit.MILLISECONDS) .setEditGracePeriod(entry.schedule.editGracePeriod, TimeUnit.MILLISECONDS) .setAudience(entry.schedule.audience); ScheduleDelay.Builder delayBuilder = ScheduleDelay.newBuilder() .setAppState(entry.schedule.appState) .setRegionId(entry.schedule.regionId) .setScreens(entry.schedule.screens) .setSeconds(entry.schedule.seconds); for (TriggerEntity entity : entry.triggers) { if (entity.isCancellation) { delayBuilder.addCancellationTrigger(convert(entity)); } else { scheduleBuilder.addTrigger(convert(entity)); } } return scheduleBuilder.setDelay(delayBuilder.build()).build(); }    }
@Test public void testConvert() throws JsonException { List<Schedule<? extends ScheduleData>> scheduleList = new ArrayList<>(); JsonMap actionsMap = JsonMap.newBuilder() .put("cool", "story") .build(); scheduleList.add(Schedule.newBuilder(new Actions(actionsMap)) .setId("actions!") .setGroup("some-group") .setLimit(100) .setPriority(2) .setInterval(100, TimeUnit.SECONDS) .setEnd(1000) .setStart(1) .setMetadata(JsonMap.newBuilder() .put("some-key", "some-value") .build()) .setEditGracePeriod(1000, TimeUnit.DAYS) .addTrigger(Triggers.newAppInitTriggerBuilder().setGoal(1).build()) .build()); InAppMessage message = InAppMessage.newBuilder() .setDisplayContent(new CustomDisplayContent(JsonMap.EMPTY_MAP.toJsonValue())) .build(); scheduleList.add(Schedule.newBuilder(message) .setId("message!") .addTrigger(Triggers.newAppInitTriggerBuilder().setGoal(1).build()) .build()); List<FullSchedule> storageSchedules = ScheduleConverters.convertSchedules(scheduleList); assertEquals(2, storageSchedules.size()); assertEquals(scheduleList.get(0), ScheduleConverters.convert(storageSchedules.get(0))); assertEquals(scheduleList.get(1), ScheduleConverters.convert(storageSchedules.get(1))); }