コード例 #1
0
  /**
   * This method is used by the updatePerson method to sync a person before updating it on the
   * database. When updating only specific fields, other fields will be set to null, this method
   * makes sure that the old values of the attributes that will not be updated remain in the
   * database.
   *
   * @param oldPerson The person that was retrieved from the database. It contains the old
   *     information of a person.
   * @param updatedPerson The person containing only the attributes that will be updated.
   * @return A person with updated information but also keeping its old attributes
   */
  public static Person syncPerson(Person oldPerson, Person updatedPerson) {
    updatedPerson.setPersonId(oldPerson.getPersonId());
    updatedPerson.setMeasures(
        oldPerson.getMeasures()); // Prevent Measures to be lost when updating a person

    if (updatedPerson.getFirstname() == null) updatedPerson.setFirstname(oldPerson.getFirstname());

    if (updatedPerson.getLastname() == null) updatedPerson.setLastname(oldPerson.getLastname());

    if (updatedPerson.getBirthdate() == null) updatedPerson.setBirthdate(oldPerson.getBirthdate());

    return updatedPerson;
  }