private void saveClasses(List<ClassScheduleDataHolder> dataHolderList) { for (ClassScheduleDataHolder dataHolder : dataHolderList) { UnisantaApplication.Log_i("Verificando horário de: " + dataHolder.subjectName); Subject subject = subjectRepository.findByOriginalIdAndSchoolYear( Long.parseLong(dataHolder.id), actualSchoolYear); if (subject != null) { subject.setNickName(dataHolder.subjectName.replace("- DP", "").trim()); subjectRepository.saveSubject(subject); Time start = new Time(dataHolder.startTime); Time end = new Time(dataHolder.endTime); int weekDay = getWeekDay(dataHolder.weekDay); ClassSchedule classSchedule = classesRepository.findBySubjectAndDateTime(subject, weekDay, start, end); // Não existe, preciso criar e salvar if (classSchedule == null) { classSchedule = ClassScheduleFactory.createClassSchedule( weekDay, dataHolder.classroom, subject, start, end, actualSchoolYear); subject.setDP(dataHolder.isDP); subjectRepository.saveSubject(subject); classesRepository.saveClassSchedule(classSchedule); } } else { UnisantaApplication.Log_e("Não encontrei a matéria de: " + dataHolder.subjectName); } } }
@Override public ClassSchedule findBySubjectAndDateTime( Subject subject, int weekDay, Time start, Time end) { List<ClassSchedule> classes = ClassSchedule.find( ClassSchedule.class, "subject = ? and week_day = ? " + "and start_hour = ? and start_minute = ? " + "and end_hour = ? and end_minute = ?", Long.toString(subject.getId()), Integer.toString(weekDay), Integer.toString(start.getHour()), Integer.toString(start.getMinute()), Integer.toString(end.getHour()), Integer.toString(end.getMinute())); if (classes.size() > 0) return classes.get(0); return null; }