Search in sources :

Example 16 with Sysprop

use of com.erudika.para.core.Sysprop in project scoold by Erudika.

the class SettingsController method resetPasswordAndUpdate.

private boolean resetPasswordAndUpdate(User u, String pass, String newpass) {
    if (u != null && !StringUtils.isBlank(pass) && !StringUtils.isBlank(newpass) && u.getIdentityProvider().equals("generic")) {
        Sysprop s = utils.getParaClient().read(u.getEmail());
        if (s != null && Utils.bcryptMatches(pass, (String) s.getProperty(Config._PASSWORD))) {
            String hashed = Utils.bcrypt(newpass);
            s.addProperty(Config._PASSWORD, hashed);
            u.setPassword(hashed);
            utils.getParaClient().update(s);
            return true;
        }
    }
    return false;
}
Also used : Sysprop(com.erudika.para.core.Sysprop)

Example 17 with Sysprop

use of com.erudika.para.core.Sysprop in project scoold by Erudika.

the class TermsController method edit.

@PostMapping
public String edit(@RequestParam String termshtml, HttpServletRequest req, Model model) {
    if (!utils.isAuthenticated(req) || !utils.isAdmin(utils.getAuthUser(req))) {
        return "redirect:" + TERMSLINK;
    }
    Sysprop terms = new Sysprop("template" + Config.SEPARATOR + "terms");
    if (StringUtils.isBlank(termshtml)) {
        utils.getParaClient().delete(terms);
    } else {
        terms.addProperty("html", termshtml);
        utils.getParaClient().create(terms);
    }
    return "redirect:" + TERMSLINK;
}
Also used : Sysprop(com.erudika.para.core.Sysprop) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 18 with Sysprop

use of com.erudika.para.core.Sysprop in project scoold by Erudika.

the class LanguageUtils method updateTranslationProgressMap.

/**
	 * Updates the progress for all languages.
	 * @param langCode the 2-letter language code
	 * @param value {@link #PLUS}, {@link #MINUS} or the total percent of completion (0-100)
	 */
private void updateTranslationProgressMap(String langCode, int value) {
    if (getDefaultLanguageCode().equals(langCode)) {
        return;
    }
    double defsize = getDefaultLanguage().size();
    double approved = value;
    Map<String, Integer> progress = getTranslationProgressMap();
    Integer percent = progress.get(langCode);
    if (value == PLUS) {
        approved = Math.round(percent * (defsize / 100) + 1);
    } else if (value == MINUS) {
        approved = Math.round(percent * (defsize / 100) - 1);
    }
    // allow 3 identical words per language (i.e. Email, etc)
    if (approved >= defsize - 3) {
        approved = defsize;
    }
    if (((int) defsize) == 0) {
        progress.put(langCode, 0);
    } else {
        progress.put(langCode, (int) ((approved / defsize) * 100));
    }
    if (percent < 100 && !percent.equals(progress.get(langCode))) {
        Sysprop s = new Sysprop(progressKey);
        for (Map.Entry<String, Integer> entry : progress.entrySet()) {
            s.addProperty(entry.getKey(), entry.getValue());
        }
        pc.create(s);
    }
}
Also used : Sysprop(com.erudika.para.core.Sysprop) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap)

Example 19 with Sysprop

use of com.erudika.para.core.Sysprop in project scoold by Erudika.

the class LanguageUtils method approveTranslation.

/**
	 * Approves a translation for a given language.
	 * @param langCode the 2-letter language code
	 * @param key the translation key
	 * @param value the translated string
	 * @return true if the operation was successful
	 */
public boolean approveTranslation(String langCode, String key, String value) {
    if (langCode == null || key == null || value == null || getDefaultLanguageCode().equals(langCode)) {
        return false;
    }
    Sysprop s = pc.read(keyPrefix.concat(langCode));
    if (s != null && !value.equals(s.getProperty(key))) {
        s.addProperty(key, value);
        pc.update(s);
        updateTranslationProgressMap(langCode, PLUS);
        return true;
    }
    return false;
}
Also used : Sysprop(com.erudika.para.core.Sysprop)

Example 20 with Sysprop

use of com.erudika.para.core.Sysprop in project scoold by Erudika.

the class LanguageUtils method getTranslationProgressMap.

/**
	 * Returns a map of language codes and the percentage of translated string for that language.
	 * @return a map indicating translation progress
	 */
public Map<String, Integer> getTranslationProgressMap() {
    Sysprop progress = pc.read(progressKey);
    Map<String, Integer> progressMap = new HashMap<String, Integer>(ALL_LOCALES.size());
    boolean isMissing = progress == null;
    if (isMissing) {
        progress = new Sysprop(progressKey);
        progress.addProperty(getDefaultLanguageCode(), 100);
    }
    for (String langCode : ALL_LOCALES.keySet()) {
        Object percent = progress.getProperties().get(langCode);
        if (percent != null && percent instanceof Number) {
            progressMap.put(langCode, (Integer) percent);
        } else {
            progressMap.put(langCode, 0);
        }
    }
    if (isMissing) {
        pc.create(progress);
    }
    return progressMap;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Sysprop(com.erudika.para.core.Sysprop)

Aggregations

Sysprop (com.erudika.para.core.Sysprop)32 HashMap (java.util.HashMap)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 Map (java.util.Map)6 ParaObject (com.erudika.para.core.ParaObject)5 Profile (com.erudika.scoold.core.Profile)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 LinkedHashMap (java.util.LinkedHashMap)4 Pager (com.erudika.para.core.utils.Pager)3 TreeMap (java.util.TreeMap)3 User (com.erudika.para.core.User)2 ConfigValue (com.typesafe.config.ConfigValue)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ParaClient (com.erudika.para.client.ParaClient)1 App (com.erudika.para.core.App)1 Tag (com.erudika.para.core.Tag)1 Webhook (com.erudika.para.core.Webhook)1 Config (com.erudika.para.core.utils.Config)1