Beispiel #1
0
  @SuppressWarnings("unchecked")
  private Sysprop fetchFxRatesJSON() {
    Map<String, Object> map = new HashMap<String, Object>();
    Sysprop s = new Sysprop();
    ObjectReader reader = ParaObjectUtils.getJsonReader(Map.class);

    try {
      CloseableHttpClient http = HttpClients.createDefault();
      HttpGet httpGet = new HttpGet(SERVICE_URL);
      HttpResponse res = http.execute(httpGet);
      HttpEntity entity = res.getEntity();

      if (entity != null && Utils.isJsonType(entity.getContentType().getValue())) {
        JsonNode jsonNode = reader.readTree(entity.getContent());
        if (jsonNode != null) {
          JsonNode rates = jsonNode.get("rates");
          if (rates != null) {
            map = reader.treeToValue(rates, Map.class);
            s.setId(FXRATES_KEY);
            s.setProperties(map);
            //						s.addProperty("fetched", Utils.formatDate("dd MM yyyy HH:mm", Locale.UK));
            dao.create(s);
          }
        }
        EntityUtils.consume(entity);
      }
      logger.debug("Fetched rates from OpenExchange for {}.", new Date().toString());
    } catch (Exception e) {
      logger.error("TimerTask failed: {}", e);
    }
    return s;
  }
Beispiel #2
0
 @Override
 public String toString() {
   return ParaObjectUtils.toJSON(this);
 }
Beispiel #3
0
 /**
  * Add an object to nest inside the linker object. Used for joining queries when searching objects
  * in a many-to-many relationship.
  *
  * @param obj object
  */
 public void addNestedObject(ParaObject obj) {
   if (obj != null) {
     getNstd().add(ParaObjectUtils.getAnnotatedFields(obj, false));
   }
 }