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; }