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;
}
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);
}
}
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);
}
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;
}
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;
}
}
Aggregations