private boolean studentsNeedUpdate(Laboratory laboratory, LaboratoryDto laboratoryDto) {
    boolean groupMatches = laboratory.getGroup().getName().equals(laboratoryDto.getGroup());
    boolean subgroupMathces =
        laboratory.getSubgroup().getName().equals(laboratoryDto.getSubgroup());

    return !(subgroupMathces && groupMatches);
  }
  @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);
    }
  }
  private void updateLaboratoryFields(Laboratory laboratory, LaboratoryDto laboratoryDto)
      throws DaoEntityNotFoundException {

    String compressedFields = laboratoryDto.getFormProfessorDto().getCompressedFields();
    String pnc = compressedFields.replaceAll("\\)", " ").replaceAll("\\(", " ").split(" ")[0];

    Hour from = hourDao.getHourByValue(laboratoryDto.getFrom());
    Hour to = hourDao.getHourByValue(laboratoryDto.getTo());
    Professor professor = professorDao.getProfessorByPnc(pnc);
    Room room = roomDao.getRoomByName(laboratoryDto.getRoom());
    Day day = dayDao.getDayByValue(laboratoryDto.getDay());
    Section section = sectionDao.getSectionByName(laboratoryDto.getSection());
    Group group = groupDao.getGroupByName(laboratoryDto.getGroup());
    Subgroup subgroup = subgroupDao.getSubgroupByName(laboratoryDto.getSubgroup());
    Year year = yearDao.getYearByValue(laboratoryDto.getYear());
    Semester semester = semesterDao.getSemesterByValue(laboratoryDto.getSemester());
    WeeklyOccurrence weeklyOccurrence =
        weeklyOccurrenceDao.getWeeklyOccurrenceByName(laboratoryDto.getWeeklyOccurrence());

    laboratory.setFrom(from);
    laboratory.setTo(to);
    laboratory.setProfessor(professor);
    laboratory.setRoom(room);
    laboratory.setDay(day);
    laboratory.setSection(section);
    laboratory.setGroup(group);
    laboratory.setSubgroup(subgroup);
    laboratory.setYear(year);
    laboratory.setSemester(semester);
    laboratory.setWeeklyOccurrence(weeklyOccurrence);
  }