Search in sources :

Example 6 with PropertyManager

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);
    }
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Example 7 with PropertyManager

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;
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Example 8 with PropertyManager

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"));
        }
    }
}
Also used : User(org.olat.core.id.User) PropertyManager(org.olat.properties.PropertyManager) UserSession(org.olat.core.util.UserSession) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) Identity(org.olat.core.id.Identity)

Example 9 with PropertyManager

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);
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Example 10 with PropertyManager

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);
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Aggregations

PropertyManager (org.olat.properties.PropertyManager)50 Property (org.olat.properties.Property)48 Test (org.junit.Test)10 Identity (org.olat.core.id.Identity)8 DBRuntimeException (org.olat.core.logging.DBRuntimeException)8 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)6 ArrayList (java.util.ArrayList)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 UserSession (org.olat.core.util.UserSession)4 NarrowedPropertyManager (org.olat.properties.NarrowedPropertyManager)4 OLATResourceable (org.olat.core.id.OLATResourceable)3 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)3 File (java.io.File)2 IOException (java.io.IOException)2 Calendar (java.util.Calendar)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2