/**
   * Merge POIs in parameters to those already in the database.
   *
   * @param remotePois The POIs to merge.
   */
  public void mergeFromOsmPois(List<Poi> remotePois) {
    List<Poi> toMergePois = new ArrayList<>();

    Map<String, Poi> remotePoisMap = new HashMap<>();
    // Map remote Poi backend Ids
    for (Poi poi : remotePois) {
      remotePoisMap.put(poi.getBackendId(), poi);
    }

    // List matching Pois
    List<Poi> localPois = poiDao.queryForBackendIds(remotePoisMap.keySet());

    Map<String, Poi> localPoisMap = new HashMap<>();
    // Map matching local Pois
    for (Poi localPoi : localPois) {
      localPoisMap.put(localPoi.getBackendId(), localPoi);
    }

    // Browse remote pois
    for (Poi remotePoi : remotePois) {
      Poi localPoi = localPoisMap.get(remotePoi.getBackendId());
      Long localVersion = -1L;
      // If localPoi is versioned
      if (localPoi != null && localPoi.getVersion() != null) {
        localVersion = Long.valueOf(localPoi.getVersion());
      }
      // Compute version delta
      if (Long.valueOf(remotePoi.getVersion()) > localVersion) {
        // Remote version is newer, override existing one
        if (localPoi != null) {
          remotePoi.setId(localPoi.getId());
        }
        // This Poi should be updated
        toMergePois.add(remotePoi);
      }
    }

    // savePois of either new or existing Pois
    savePois(toMergePois);
  }