コード例 #1
0
  public void convertStatesAndMerge(StateTraverser tasks) throws NoCountryFoundException {
    Integer numberOfCountriesWithoutStates = 0;
    for (Map.Entry<Place, List<Place>> entry :
        tasks.getWorkflowHelperWrapper().getGeoPlanetStates().entrySet()) {
      Place country = entry.getKey();
      List<Place> states = entry.getValue();

      List<Country> results = countryDtoService.query("name = '" + country.getName() + "'");

      if (results.isEmpty()) {
        throw new NoCountryFoundException(country);
      }

      Country countryDto = results.get(0);
      if ((states.isEmpty() && countryDto.getHasStates())
          || (!states.isEmpty() && !countryDto.getHasStates())) {
        countryDto.setHasStates(!states.isEmpty());
        countryDto = countryDtoService.merge(countryDto);
      }

      if (states.isEmpty()) {
        numberOfCountriesWithoutStates++;
      }

      for (Place state : states) {
        State stateDto = new State();

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

        if (queryCheck.isEmpty()) {
          stateDto.setName(state.getName());
          stateDto.setCountry(countryDto);

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

        stateDto = queryCheck.get(0);

        stateDto.setCountry(countryDto);
        stateDto.setDateLastModified(new Date());
        stateDto.setIsDeleted(false);

        stateDto = merge(stateDto);

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

    log.info("numberOfCountriesWithoutStates: " + numberOfCountriesWithoutStates);
  }
コード例 #2
0
  public void replicateToMongoDB(StateTraverser tasks) {
    List<State> states = tasks.getWorkflowHelperWrapper().getAllEntities();

    for (State state : states) {
      MongoState mongoState = new MongoState();

      mongoState.setName(state.getName());
      mongoState.setId(state.getPk());

      MongoCountry country = countryMongoDao.find(state.getCountry().getPk());

      mongoState.setCountry(country);

      mongoState.setId(state.getPk());

      stateMongoDao.merge(mongoState);
    }
  }