@Override
  public List<LaboratoryDto> getLaboratories(
      SectionDto sectionDto, YearDto yearDto, SemesterDto semesterDto) {
    Section section = modelMapper.map(sectionDto, Section.class);
    Year year = modelMapper.map(yearDto, Year.class);
    Semester semester = modelMapper.map(semesterDto, Semester.class);

    List<Laboratory> laboratories = laboratoryDao.getLaboratories(section, year, semester);

    return modelMapper.map(laboratories, new TypeToken<List<LaboratoryDto>>() {}.getType());
  }
  @Override
  public void updateLaboratory(LaboratoryDto laboratoryDto) throws ServiceEntityNotFoundException {
    try {
      Laboratory laboratory = laboratoryDao.getLaboratoryById(laboratoryDto.getId());
      boolean studentsNeedUpdate = studentsNeedUpdate(laboratory, laboratoryDto);
      updateLaboratoryFields(laboratory, laboratoryDto);

      laboratoryDao.updateLaboratory(laboratory);

      if (studentsNeedUpdate) {
        laboratory.getStudents().clear();

        List<Student> students =
            studentDao.getStudents(
                laboratory.getSection(),
                laboratory.getYear(),
                laboratory.getSemester(),
                laboratory.getGroup(),
                laboratory.getSubgroup());
        laboratory.setStudents(students);
      }

    } catch (DaoEntityNotFoundException e) {
      LOGGER.debug("DaoEntityNotFoundException");
      throw new ServiceEntityNotFoundException(e);
    }
  }
  @Override
  public LaboratoryDto getLaboratoryById(int id) throws ServiceEntityNotFoundException {
    try {
      Laboratory laboratory = laboratoryDao.getLaboratoryById(id);

      return modelMapper.map(laboratory, LaboratoryDto.class);
    } catch (DaoEntityNotFoundException e) {
      LOGGER.debug("DaoEntityNotFoundException");
      throw new ServiceEntityNotFoundException(e);
    }
  }
 @Override
 public void deleteLaboratory(int id) throws ServiceEntityNotFoundException {
   try {
     gradeDao.deleteGradesByLaboratory(id);
     attendanceDao.deleteAttendancesByLaboratory(id);
     documentDao.deleteDocumentsByLaboratory(id);
     laboratoryDao.deleteLaboratoryById(id);
     noteDao.deleteNotesByLaboratory(id);
   } catch (DaoEntityNotFoundException e) {
     LOGGER.debug("DaoEntityNotFoundException");
     throw new ServiceEntityNotFoundException(e);
   }
 }
  @Override
  public void saveLaboratory(LaboratoryDto laboratoryDto)
      throws ServiceEntityNotFoundException, ServiceEntityAlreadyExistsException {
    Laboratory laboratory = modelMapper.map(laboratoryDto, Laboratory.class);

    try {
      populateLaboratoryFields(laboratory);

      laboratoryDao.saveLaboratory(laboratory);
    } catch (DaoEntityNotFoundException e) {
      LOGGER.debug("DaoEntityNotFoundException");
      throw new ServiceEntityNotFoundException(e);
    } catch (DaoEntityAlreadyExistsException e) {
      LOGGER.debug("DaoEntityAlreadyExistsException");
      throw new ServiceEntityAlreadyExistsException(e);
    }
  }
 @Override
 public List<Laboratory> getAllLaboratories() {
   return laboratoryDao.getAllLaboratories();
 }