public List<Teacher> findAll() {
   return teacherRepository
       .findAll()
       .parallelStream()
       .map(TeacherDomain::toModel)
       .collect(Collectors.toList());
 }
  public Teacher findOneById(Long id) {
    if (id == null) {
      throw new IllegalArgumentException(
          "Cannot find a " + Teacher.class.getName() + " with a null id.");
    }
    TeacherDomain domain = teacherRepository.findOne(id);

    if (domain == null) {
      throw new TeacherResourceNotFoundException(
          "No " + Teacher.class.getName() + " found for id :" + id);
    }

    return domain.toModel();
  }
  public Teacher create(Teacher model) {
    if (model == null) {
      throw new IllegalArgumentException("Cannot persist a null " + Teacher.class.getName());
    }
    if (model.getId() != null) {
      throw new AlreadyDefinedInOnNonPersistedEntity(
          "Cannot persist a " + Teacher.class.getName() + " which already has an ID.");
    }
    TeacherDomain domain = new TeacherDomain(model);
    domain = teacherRepository.saveAndFlush(domain);
    model.setId(domain.getId());

    return domain.toModel();
  }
  public Email addEmail(Long teacherId, Email model) {
    if (teacherId == null) {
      throw new IllegalArgumentException(
          "Cannot find a " + Teacher.class.getName() + " with a null id.");
    }
    if (model == null) {
      throw new IllegalArgumentException("Cannot persist a null " + Email.class.getName());
    }
    if (model.getId() != null) {
      throw new AlreadyDefinedInOnNonPersistedEntity(
          "Cannot persist a " + Email.class.getName() + " which already has an ID.");
    }

    model = emailManager.create(model);

    Teacher fetched = findOneById(teacherId);
    fetched.getContact().addEmail(model);
    teacherRepository.saveAndFlush(new TeacherDomain(fetched));
    return model;
  }