示例#1
0
  /* (non-Javadoc)
   * @see com.welocally.geodb.services.util.JsonStoreLoader#loadSingle(org.json.JSONObject, int, int, java.io.StringWriter)
   */
  public void loadSingle(
      JSONObject deal, Integer count, Integer commitEvery, StringWriter sw, String endpoint)
      throws JSONException, IOException {
    logger.debug("adding document:" + deal.getString("_id"));

    URL solrUrl = new URL(endpoint);

    JSONObject doc = welocallyJSONUtils.makeIndexableDeal(deal);
    JSONObject solrCommand = new JSONObject("{\"add\": {\"doc\":" + doc.toString() + "}}");

    ByteArrayInputStream bais = new ByteArrayInputStream(solrCommand.toString().getBytes());
    BufferedReader newReader = new BufferedReader(new InputStreamReader(bais));

    postData(newReader, sw, solrUrl);

    // commit only every x docs
    if (count % commitEvery == 0) {
      logger.debug("commit");
      commit(sw, solrUrl);
      sw.flush();
      sw.close();
      sw = new StringWriter();
    }

    loadMonitor.increment();
  }
  @Override
  public void doCommand(JSONObject command) throws CommandException {
    try {
      loadMonitor.reset();
      JSONArray urls = command.getJSONArray("sourceUrls");

      String[] sourceUrls = new String[urls.length()];
      for (int i = 0; i < urls.length(); i++) {
        sourceUrls[i] = urls.getString(i);
      }
      JSONArray placesAll = getPlaces(sourceUrls);
      loadES(
          placesAll,
          command.getString("targetIndex"),
          command.getString("targetCollection"),
          JsonDatabase.EntityType.PLACE);

      loadDynamo(placesAll, 1000, command.getString("targetCollection"));

    } catch (DbException e) {
      logger.error(e);
      throw new CommandException(e);
    } catch (JSONException e) {
      logger.error(e);
      throw new CommandException(e);
    }
  }
示例#3
0
  /* (non-Javadoc)
   * @see com.welocally.geodb.services.util.JsonStoreLoader#loadSingle(org.json.JSONObject, int, int, java.io.StringWriter)
   */
  public void deleteAll(String endpoint) throws JSONException, IOException {
    logger.debug("deleting all documents");

    URL solrUrl = new URL(endpoint);
    // <delete><query>*:*</query></delete>
    JSONObject solrCommand = new JSONObject("{\"delete\": {\"query\":\"*:*\"}}");
    StringWriter sw = new StringWriter();
    ByteArrayInputStream bais = new ByteArrayInputStream(solrCommand.toString().getBytes());
    BufferedReader newReader = new BufferedReader(new InputStreamReader(bais));

    postData(newReader, sw, solrUrl);

    commit(sw, solrUrl);
    sw.flush();
    sw.close();

    loadMonitor.increment();
  }
示例#4
0
  @Override
  public void doCommand(JSONObject command) throws CommandException {
    try {
      loadMonitor.reset();
      deleteAll(command.getString("endpoint"));
      load(
          command.getString("file"),
          command.getInt("maxRecords"),
          command.getInt("commitEvery"),
          command.getString("endpoint"));

    } catch (DbException e) {
      logger.error(e);
      throw new CommandException(e);
    } catch (JSONException e) {
      logger.error(e);
      throw new CommandException(e);
    } catch (IOException e) {
      logger.error(e);
      throw new CommandException(e);
    }
  }