Package com.erudika.para.core

Examples of com.erudika.para.core.Sysprop


  @Override
  public Double convertCurrency(Number amount, String from, String to) {
    if (amount == null || StringUtils.isBlank(from) || StringUtils.isBlank(to)) {
      return 0.0;
    }
    Sysprop s = dao.read(FXRATES_KEY);
    if (s == null) {
      s = fetchFxRatesJSON();
    } else if ((Utils.timestamp() - s.getTimestamp()) > REFRESH_AFTER) {
      // lazy refresh fx rates
      Utils.asyncExecute(new Runnable() {
        public void run() {
          fetchFxRatesJSON();
        }
      });
    }

    double ratio = 1.0;

    if (s.hasProperty(from) && s.hasProperty(to)) {
      Double f = NumberUtils.toDouble(s.getProperty(from).toString(), 1.0);
      Double t = NumberUtils.toDouble(s.getProperty(to).toString(), 1.0);
      ratio = t / f;
    }
    return amount.doubleValue() * ratio;
  }
 
View Full Code Here


  }

  @SuppressWarnings("unchecked")
  private Sysprop fetchFxRatesJSON() {
    Map<String, Object> map = new HashMap<String, Object>();
    Sysprop s = new Sysprop();
    ObjectReader reader = Utils.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);
View Full Code Here

    }
    if (search == null || dao == null) {
      return getDefaultLanguage();
    }

    Sysprop s = dao.read(appid, keyPrefix.concat(langCode));
    TreeMap<String, String> lang = new TreeMap<String, String>();

    if (s == null || s.getProperties().isEmpty()) {
      Map<String, Object> terms = new HashMap<String, Object>();
      terms.put("locale", langCode);
      terms.put("approved", true);
      List<Translation> tlist = search.findTerms(appid, Utils.type(Translation.class), terms, true);

      Sysprop saved = new Sysprop(keyPrefix.concat(langCode));
      lang.putAll(getDefaultLanguage())// copy default langmap
      int approved = 0;

      for (Translation trans : tlist) {
        lang.put(trans.getThekey(), trans.getValue());
        saved.addProperty(trans.getThekey(), trans.getValue());
        approved++;
      }
      if (approved > 0) {
        updateTranslationProgressMap(appid, langCode, approved);
      }
View Full Code Here

        StringUtils.isBlank(langCode) || !allLocales.containsKey(langCode)) {
      return;
    }

    // this will overwrite a saved language map!
    Sysprop s = new Sysprop(keyPrefix.concat(langCode));
    Map<String, String> dlang = getDefaultLanguage();
    int approved = 0;

    for (String key : dlang.keySet()) {
      if (lang.containsKey(key)) {
        s.addProperty(key, lang.get(key));
        if (!dlang.get(key).equals(lang.get(key))) {
          approved++;
        }
      } else {
        s.addProperty(key, dlang.get(key));
      }
    }
    if (approved > 0) {
      updateTranslationProgressMap(appid, langCode, approved);
    }
View Full Code Here

   */
  public Map<String, Integer> getTranslationProgressMap(String appid) {
    if (dao == null) {
      return progressMap;
    }
    Sysprop progress = getProgressMap(appid);

    Map<String, Object> props = progress.getProperties();
    for (String key : props.keySet()) {
      progressMap.put(key, (Integer) props.get(key));
    }

    return progressMap;
View Full Code Here

   */
  public boolean approveTranslation(String appid, String langCode, String key, String value) {
    if (langCode == null || key == null || value == null || getDefaultLanguageCode().equals(langCode)) {
      return false;
    }
    Sysprop s = dao.read(appid, keyPrefix.concat(langCode));

    if (s != null && !value.equals(s.getProperty(key))) {
      s.addProperty(key, value);
      dao.update(appid, s);
      updateTranslationProgressMap(appid, langCode, PLUS);
      return true;
    }
    return false;
View Full Code Here

   */
  public boolean disapproveTranslation(String appid, String langCode, String key) {
    if (langCode == null || key == null || getDefaultLanguageCode().equals(langCode)) {
      return false;
    }
    Sysprop s = dao.read(appid, keyPrefix.concat(langCode));
    String defStr = getDefaultLanguage().get(key);

    if (s != null && !defStr.equals(s.getProperty(key))) {
      s.addProperty(key, defStr);
      dao.update(appid, s);
      updateTranslationProgressMap(appid, langCode, MINUS);
      return true;
    }
    return false;
View Full Code Here

    }

    double defsize = getDefaultLanguage().size();
    double approved = value;

    Sysprop progress = getProgressMap(appid);

    if (value == PLUS) {
      approved = Math.round((Integer) progress.getProperty(langCode) * (defsize / 100) + 1);
    } else if (value == MINUS) {
      approved = Math.round((Integer) progress.getProperty(langCode) * (defsize / 100) - 1);
    }

    if (approved > defsize) {
      approved = defsize;
    }

    if (defsize == 0) {
      progress.addProperty(langCode, 0);
    } else {
      progress.addProperty(langCode, (int) ((approved / defsize) * 100));
    }
    dao.update(appid, progress);
  }
View Full Code Here

    }
    dao.update(appid, progress);
  }

  private Sysprop getProgressMap(String appid) {
    Sysprop progress = dao.read(appid, progressKey);
    if (progress == null) {
      progress = new Sysprop(progressKey);
      for (String key : progressMap.keySet()) {
        progress.addProperty(key, progressMap.get(key));
      }
      progress.addProperty(getDefaultLanguageCode(), 100);
      dao.create(appid, progress);
    }
    return progress;
  }
View Full Code Here

  @Override
  public Double convertCurrency(Number amount, String from, String to) {
    if (amount == null || StringUtils.isBlank(from) || StringUtils.isBlank(to)) {
      return 0.0;
    }
    Sysprop s = dao.read(Config.FXRATES_KEY);
    if (s == null) {
      s = fetchFxRatesJSON();
    } else if ((Utils.timestamp() - s.getTimestamp()) > REFRESH_AFTER) {
      // lazy refresh fx rates
      Utils.asyncExecute(new Runnable() {
        public void run() {
          fetchFxRatesJSON();
        }
      });
    }

    double ratio = 1.0;

    if (s.hasProperty(from) && s.hasProperty(to)) {
      Double f = NumberUtils.toDouble(s.getProperty(from).toString(), 1.0);
      Double t = NumberUtils.toDouble(s.getProperty(to).toString(), 1.0);
      ratio = t / f;
    }
    return amount.doubleValue() * ratio;
  }
 
View Full Code Here

TOP

Related Classes of com.erudika.para.core.Sysprop

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.