Search in sources :

Example 1 with Sysprop

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

the class LanguageUtils method disapproveTranslation.

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

Example 2 with Sysprop

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

the class LanguageUtils method writeLanguage.

/**
	 * Persists the language map to a file. Overwrites any existing files.
	 * @param langCode the 2-letter language code
	 * @param lang the language map
	 * @param writeToDatabase true if you want the language map to be stored in the DB as well
	 */
public void writeLanguage(String langCode, Map<String, String> lang, boolean writeToDatabase) {
    if (lang == null || lang.isEmpty() || StringUtils.isBlank(langCode) || !ALL_LOCALES.containsKey(langCode)) {
        return;
    }
    writeLanguageToFile(langCode, lang);
    if (writeToDatabase) {
        // this will overwrite a saved language map!
        Sysprop s = new Sysprop(keyPrefix.concat(langCode));
        Map<String, String> dlang = getDefaultLanguage();
        for (Map.Entry<String, String> entry : dlang.entrySet()) {
            String key = entry.getKey();
            if (lang.containsKey(key)) {
                s.addProperty(key, lang.get(key));
            } else {
                s.addProperty(key, 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 3 with Sysprop

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

the class ApiController method createSpace.

@PostMapping("/spaces")
public Sysprop createSpace(HttpServletRequest req, HttpServletResponse res) {
    Map<String, Object> entity = readEntity(req);
    if (entity.isEmpty()) {
        badReq("Missing request body.");
    }
    String name = (String) entity.get(Config._NAME);
    if (StringUtils.isBlank(name)) {
        badReq("Property 'name' cannot be blank.");
        return null;
    }
    if (pc.read(utils.getSpaceId(name)) != null) {
        badReq("Space already exists.");
        return null;
    }
    Sysprop s = utils.buildSpaceObject(name);
    res.setStatus(HttpStatus.CREATED.value());
    return pc.create(s);
}
Also used : Sysprop(com.erudika.para.core.Sysprop) ParaObject(com.erudika.para.core.ParaObject) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with Sysprop

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

the class AboutController method edit.

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

Example 5 with Sysprop

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

the class AdminController method removeSpace.

@PostMapping("/remove-space")
public String removeSpace(@RequestParam String space, HttpServletRequest req, HttpServletResponse res) {
    Profile authUser = utils.getAuthUser(req);
    if (!StringUtils.isBlank(space) && utils.isAdmin(authUser)) {
        Sysprop s = new Sysprop(utils.getSpaceId(space));
        pc.delete(s);
        authUser.getSpaces().remove(space);
        authUser.update();
        utils.getAllSpaces().remove(s);
    }
    if (utils.isAjaxRequest(req)) {
        res.setStatus(200);
        return "space";
    } else {
        return "redirect:" + ADMINLINK;
    }
}
Also used : Sysprop(com.erudika.para.core.Sysprop) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

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