use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.
the class UserManagerImpl method setUserCharset.
@Override
public void setUserCharset(Identity identity, String charset) {
PropertyManager pm = PropertyManager.getInstance();
Property p = pm.findProperty(identity, null, null, null, CHARSET);
if (p != null) {
p.setStringValue(charset);
pm.updateProperty(p);
} else {
Property newP = pm.createUserPropertyInstance(identity, null, CHARSET, null, null, charset, null);
pm.saveProperty(newP);
}
}
use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.
the class UserManagerImpl method getUserCharset.
@Override
public String getUserCharset(Identity identity) {
String charset;
charset = WebappHelper.getDefaultCharset();
PropertyManager pm = PropertyManager.getInstance();
Property p = pm.findProperty(identity, null, null, null, CHARSET);
if (p != null) {
charset = p.getStringValue();
// (a rather rare case)
if (!Charset.isSupported(charset)) {
charset = WebappHelper.getDefaultCharset();
}
} else {
charset = WebappHelper.getDefaultCharset();
}
return charset;
}
use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.
the class UserPrefsResetForm method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (resetElements.isAtLeastSelected(1)) {
// Log out user first if logged in
boolean logout = false;
Set<UserSession> sessions = sessionManager.getAuthenticatedUserSessions();
for (UserSession session : sessions) {
Identity ident = session.getIdentity();
if (ident != null && tobeChangedIdentity.equalsByPersistableKey(ident)) {
sessionManager.signOffAndClear(session);
logout = true;
break;
}
}
// Delete gui prefs
if (resetElements.isSelected(0)) {
PropertyManager pm = PropertyManager.getInstance();
pm.deleteProperties(tobeChangedIdentity, null, null, null, "v2guipreferences");
}
// Reset preferences
if (resetElements.isSelected(1)) {
UserManager um = UserManager.getInstance();
User user = um.loadUserByKey(tobeChangedIdentity.getUser().getKey());
org.olat.core.id.Preferences preferences = user.getPreferences();
preferences.setFontsize(null);
preferences.setNotificationInterval(null);
preferences.setPresenceMessagesPublic(false);
preferences.setReceiveRealMail(null);
um.updateUser(user);
PropertyManager pm = PropertyManager.getInstance();
pm.deleteProperties(tobeChangedIdentity, null, null, null, "charset");
}
// Reset history
if (resetElements.isSelected(2)) {
HistoryManager.getInstance().deleteHistory(tobeChangedIdentity);
}
// reset form buttons
resetElements.uncheckAll();
if (logout) {
// if logout, need a redirect to the login page
String lang = i18nModule.getLocaleKey(ureq.getLocale());
ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(WebappHelper.getServletContextPath() + "/dmz/?lang=" + lang + "&logout=true"));
}
}
}
use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.
the class DBTest method testRollbackNonTransactional.
@Test
public void testRollbackNonTransactional() {
String propertyKey1 = "testNonTransactional-1";
String testValue1 = "testNonTransactional-1";
String propertyKey2 = "testNonTransactional-2";
String testValue2 = "testNonTransactional-2";
String testValue3 = "testNonTransactional-3";
try {
PropertyManager pm = PropertyManager.getInstance();
Property p1 = pm.createPropertyInstance(null, null, null, null, propertyKey1, null, null, testValue1, null);
pm.saveProperty(p1);
Property p2 = pm.createPropertyInstance(null, null, null, null, propertyKey2, null, null, testValue2, null);
pm.saveProperty(p2);
// name is null => generated DB error => rollback ?
Property p3 = pm.createPropertyInstance(null, null, null, null, null, null, null, testValue3, null);
pm.saveProperty(p3);
dbInstance.commit();
fail("Should generate error for rollback.");
dbInstance.closeSession();
} catch (Exception ex) {
dbInstance.closeSession();
}
// check if p1 & p2 is NOT rollbacked
PropertyManager pm = PropertyManager.getInstance();
Property p_1 = pm.findProperty(null, null, null, null, propertyKey1);
assertNull("Property1 is NOT rollbacked", p_1);
Property p_2 = pm.findProperty(null, null, null, null, propertyKey2);
assertNull("Property2 is NOT rollbacked", p_2);
}
use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.
the class DBTest method testMixedNonTransactional_Transactional.
@Test
public void testMixedNonTransactional_Transactional() {
String propertyKey1 = "testMixed-1";
String testValue1 = "testMixed-1";
String propertyKey2 = "testMixed-2";
String testValue2 = "testMixed-2";
String testValue3 = "testMixed-3";
try {
// outside of transaction
PropertyManager pm = PropertyManager.getInstance();
Property p1 = pm.createPropertyInstance(null, null, null, null, propertyKey1, null, null, testValue1, null);
pm.saveProperty(p1);
// inside of transaction
Property p2 = pm.createPropertyInstance(null, null, null, null, propertyKey2, null, null, testValue2, null);
pm.saveProperty(p2);
// name is null => generated DB error => rollback
Property p3 = pm.createPropertyInstance(null, null, null, null, null, null, null, testValue3, null);
pm.saveProperty(p3);
dbInstance.commit();
fail("Should generate error for rollback.");
dbInstance.closeSession();
} catch (Exception ex) {
dbInstance.closeSession();
}
// check if p1&p2 is rollbacked
PropertyManager pm = PropertyManager.getInstance();
Property p_1 = pm.findProperty(null, null, null, null, propertyKey1);
assertNull("Property1 is NOT rollbacked", p_1);
Property p_2 = pm.findProperty(null, null, null, null, propertyKey2);
assertNull("Property2 is NOT rollbacked", p_2);
}
Aggregations