@Override
  public boolean doWork(Message message) {

    try {
      // either create and insert a new payload:
      // JSONObject json_out = new JSONObject();
      // json_out.put("processed", true);
      // message.setPayload(json_out);

      // or work on the existing one:
      JSONObject tweet = message.getPayload();

      if (processTweet(tweet)) {
        JSONObject result = new JSONObject();
        result.put("tweet_id", tweet.getLong("id"));
        result.put("date_posted", tweet.getLong("date_posted"));
        if (tweet.has("images")) result.put("images", tweet.getJSONArray("images"));
        if (tweet.has("coordinates") && !tweet.isNull("coordinates"))
          result.put("coordinates", tweet.getJSONObject("coordinates"));
        message.setPayload(result);

        return true;
      } else {
        return false;
      }
    } catch (JSONException e) {
      log.error("JSONException: " + e);
      logConn.error("JSONException: " + e);
      return false;
    }
  }
  /**
   * This is a helper method extracts and validates the information contained in the schema stub for
   * this schema.
   *
   * @param schemaStub The schema stub to extract information from and validate.
   * @throws JSONException This exception is thrown if there is an error processing the provided
   *     JSON schemaStub.
   */
  private void setSchemaStub(String schemaStub) throws JSONException {
    JSONObject jo = new JSONObject(schemaStub);
    SchemaUtils.checkValidKeysEx(jo, VALID_KEYS);

    JSONObject tempTime = jo.getJSONObject(FIELD_TIME);
    SchemaUtils.checkValidKeys(jo, VALID_TIME_KEYS);

    this.from = tempTime.getLong(FIELD_TIME_FROM);
    this.to = tempTime.getLong(FIELD_TIME_TO);
  }
Esempio n. 3
0
  public void verifyHsSingleTask(JSONObject info, Task task) throws JSONException {
    assertEquals("incorrect number of elements", 9, info.length());

    verifyTaskGeneric(
        task,
        info.getString("id"),
        info.getString("state"),
        info.getString("type"),
        info.getString("successfulAttempt"),
        info.getLong("startTime"),
        info.getLong("finishTime"),
        info.getLong("elapsedTime"),
        (float) info.getDouble("progress"));
  }
Esempio n. 4
0
  public static FinancialAccounting fromJSON(JSONObject jObj) throws JSONException, ParseException {
    if (jObj.has("result") && nullStringToNull(jObj, "result") != null) {
      jObj = jObj.getJSONObject("result");
    }

    final FinancialAccounting financialAccounting =
        new FinancialAccounting.Builder().revision(jObj.getLong("revision")).build();

    if (!jObj.isNull("items")) {
      final List<FinancialAccountingItem> items = new ArrayList<FinancialAccountingItem>();

      final JSONArray jItems = jObj.getJSONArray("items");

      for (int i = 0; i < jItems.length(); i++) {
        final JSONObject jItem = jItems.getJSONObject(i);

        final FinancialAccountingItem financialAccountingItem =
            FinancialAccountingItem.fromJSON(jItem);

        items.add(financialAccountingItem);
      }

      financialAccounting.setItems(items);
    }

    return financialAccounting;
  }
Esempio n. 5
0
 public void verifyClusterInfo(JSONObject json) throws JSONException, Exception {
   assertEquals("incorrect number of elements", 1, json.length());
   JSONObject info = json.getJSONObject("clusterInfo");
   assertEquals("incorrect number of elements", 10, info.length());
   verifyClusterGeneric(
       info.getLong("id"),
       info.getLong("startedOn"),
       info.getString("state"),
       info.getString("haState"),
       info.getString("hadoopVersionBuiltOn"),
       info.getString("hadoopBuildVersion"),
       info.getString("hadoopVersion"),
       info.getString("resourceManagerVersionBuiltOn"),
       info.getString("resourceManagerBuildVersion"),
       info.getString("resourceManagerVersion"));
 }
Esempio n. 6
0
 /** @return the population. */
 public Long getPopulation() {
   try {
     if (data.has(ToponymProperty.population.name())) {
       return data.getLong(ToponymProperty.population.name());
     } else {
       return null;
     }
   } catch (JSONException e) {
     throw new IllegalStateException(
         String.format("Unable to parse %s form %s", ToponymProperty.population, data));
   }
 }
 @PUT
 @GraphTransactional
 public Response setSort(JSONObject sortValues) {
   return NoExRun.wrap(
           () -> {
             graphElementOperator.setSortDate(
                 new Date(sortValues.getLong("sortDate")),
                 new Date(sortValues.getLong("moveDate")));
             return Response.ok().build();
           })
       .get();
 }
Esempio n. 8
0
  public void verifyHsJobTaskCounters(JSONObject info, Task task) throws JSONException {

    assertEquals("incorrect number of elements", 2, info.length());

    WebServicesTestUtils.checkStringMatch(
        "id", MRApps.toString(task.getID()), info.getString("id"));
    // just do simple verification of fields - not data is correct
    // in the fields
    JSONArray counterGroups = info.getJSONArray("taskCounterGroup");
    for (int i = 0; i < counterGroups.length(); i++) {
      JSONObject counterGroup = counterGroups.getJSONObject(i);
      String name = counterGroup.getString("counterGroupName");
      assertTrue("name not set", (name != null && !name.isEmpty()));
      JSONArray counters = counterGroup.getJSONArray("counter");
      for (int j = 0; j < counters.length(); j++) {
        JSONObject counter = counters.getJSONObject(j);
        String counterName = counter.getString("name");
        assertTrue("name not set", (counterName != null && !counterName.isEmpty()));
        long value = counter.getLong("value");
        assertTrue("value  >= 0", value >= 0);
      }
    }
  }