public void convertCitiesAndMerge(CityTraverser tasks) throws NoStateFoundException {
    Integer numberOfStatesWithoutCities = 0;
    for (Map.Entry<Place, List<Place>> entry :
        tasks.getWorkflowHelperWrapper().getGeoPlanetCities().entrySet()) {
      Place state = entry.getKey();
      List<Place> cities = entry.getValue();

      List<State> results =
          stateDtoService.query("name = '" + state.getName().replaceAll("'", "''") + "'");

      if (results.isEmpty()) {
        throw new NoStateFoundException(state);
      }

      State stateDto = results.get(0);

      if (cities.isEmpty()) {
        numberOfStatesWithoutCities++;
      }

      for (Place city : cities) {
        City cityDto = new City();

        List<City> queryCheck = query("name = '" + city.getName().replaceAll("'", "''") + "'");

        if (queryCheck.isEmpty()) {
          cityDto.setName(city.getName());
          cityDto.setState(stateDto);
          cityDto.setCountry(stateDto.getCountry());

          add(cityDto);
          tasks.getWorkflowHelperWrapper().getAllEntities().add(cityDto);
          continue;
        }

        cityDto = queryCheck.get(0);

        cityDto.setCountry(stateDto.getCountry());
        cityDto.setState(stateDto);
        cityDto.setDateLastModified(new Date());
        cityDto.setIsDeleted(false);

        cityDto = merge(cityDto);

        tasks.getWorkflowHelperWrapper().getAllEntities().add(cityDto);
      }
    }

    log.info("numberOfStatesWithoutCities: " + numberOfStatesWithoutCities);
  }
  public void replicateToMongoDB(CityTraverser tasks) {
    List<City> cities = tasks.getWorkflowHelperWrapper().getAllEntities();

    for (City city : cities) {
      MongoCity mongoCity = new MongoCity();

      mongoCity.setName(city.getName());
      mongoCity.setId(city.getPk());

      MongoState state = stateMongoDao.find(city.getState().getPk());
      MongoCountry country = countryMongoDao.find(city.getCountry().getPk());

      mongoCity.setState(state);
      mongoCity.setCountry(country);

      mongoCity.setId(city.getPk());

      cityMongoDao.merge(mongoCity);
    }
  }