Exemplo n.º 1
0
  public Address addAddress(Long teacherId, Address 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 " + Address.class.getName());
    }
    if (model.getId() != null) {
      throw new AlreadyDefinedInOnNonPersistedEntity(
          "Cannot persist a " + Address.class.getName() + " which already has an ID.");
    }

    model = addressManager.create(model);

    Teacher fetched = findOneById(teacherId);
    fetched.getContact().addAddress(model);
    teacherRepository.saveAndFlush(new TeacherDomain(fetched));
    return model;
  }
Exemplo n.º 2
0
 public void removeAddress(Long addressId) {
   addressManager.delete(addressId);
 }