Search in sources :

Example 36 with PropertyManager

use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.

the class CollaborationTools method createOrUpdateProperty.

/**
 * creates the property if non-existing, or updates the existing property to
 * the supplied values. Real changes are made persistent immediately.
 *
 * @param selectedTool
 * @param toolValue
 */
private void createOrUpdateProperty(final String selectedTool, final boolean toolValue) {
    Boolean cv = cacheToolStates.get(selectedTool);
    if (cv != null && cv.booleanValue() == toolValue) {
        // nice, cache saved a needless update
        return;
    }
    // handle Boolean Values via String Field in Property DB Table
    final String toolValueStr = toolValue ? TRUE : FALSE;
    final PropertyManager pm = PropertyManager.getInstance();
    coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {

        @Override
        public void execute() {
            // was: synchronized (CollaborationTools.class) {
            Property property = getPropertyOf(selectedTool);
            if (property == null) {
                // not existing -> create it
                property = pm.createPropertyInstance(null, null, ores, PROP_CAT_BG_COLLABTOOLS, selectedTool, null, null, toolValueStr, null);
            } else {
                // if existing -> update to desired value
                property.setStringValue(toolValueStr);
            }
            // create a room if needed
            if (toolValue && TOOL_OPENMEETINGS.equals(selectedTool)) {
                openOpenMeetingsRoom();
            }
            // property becomes persistent
            pm.saveProperty(property);
        }
    });
    this.dirty = true;
    cacheToolStates.put(selectedTool, Boolean.valueOf(toolValue));
}
Also used : PropertyManager(org.olat.properties.PropertyManager) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) Property(org.olat.properties.Property)

Example 37 with PropertyManager

use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.

the class AdminModule method checkToken.

private boolean checkToken(HttpServletRequest request, String tokenPropertyName) {
    String submittedToken = request.getParameter("token");
    if (submittedToken == null) {
        log.audit("Trying to set maintenance message without using a token. Remote address::" + request.getRemoteAddr());
        return false;
    }
    // get token and compare
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(null, null, null, AdminModule.SYSTEM_PROPERTY_CATEGORY, tokenPropertyName);
    String token = (p == null ? "" : p.getStringValue());
    if (token.equals(submittedToken)) {
        // limit access to token
        return true;
    }
    log.audit("Trying to set maintenance message using a wrong token. Remote address::" + request.getRemoteAddr());
    return false;
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Example 38 with PropertyManager

use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.

the class InfoMessageManager method setInfoMessage.

/**
 * @param message The new info message that will show up on the login screen
 * Synchronized to prevent two users creating or updating the info message property
 * at the same time
 */
public void setInfoMessage(final String message) {
    // o_clusterOK synchronized
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(INFO_MSG, KEY);
    coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {

        public void execute() {
            PropertyManager pm = PropertyManager.getInstance();
            Property p = pm.findProperty(null, null, null, "_o3_", INFO_MSG);
            if (p == null) {
                p = pm.createPropertyInstance(null, null, null, "_o3_", INFO_MSG, null, null, null, "");
                pm.saveProperty(p);
            }
            p.setTextValue(message);
            // set Message in RAM
            InfoMessageManager.infoMessage = message;
            pm.updateProperty(p);
        }
    });
    // end syncerCallback
    EventBus eb = coordinatorManager.getCoordinator().getEventBus();
    MultiUserEvent mue = new MultiUserEvent(message);
    eb.fireEventToListenersOf(mue, INFO_MESSAGE_ORES);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) PropertyManager(org.olat.properties.PropertyManager) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) EventBus(org.olat.core.util.event.EventBus) Property(org.olat.properties.Property) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 39 with PropertyManager

use of org.olat.properties.PropertyManager in project openolat by klemens.

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 40 with PropertyManager

use of org.olat.properties.PropertyManager in project openolat by klemens.

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