Пример #1
0
  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;
  }
Пример #2
0
 public void removeEmail(Long emailId) {
   emailManager.delete(emailId);
 }