Search in sources :

Example 6 with UserPropertyUsageContext

use of org.olat.user.propertyhandlers.UserPropertyUsageContext in project OpenOLAT by OpenOLAT.

the class UsrPropContextCfgTableController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source.equals(contextTableCtr)) {
        TableEvent tblEvent = (TableEvent) event;
        Entry<String, UserPropertyUsageContext> contextRow = contTblModel.getObject(tblEvent.getRowId());
        removeAsListenerAndDispose(editBox);
        removeAsListenerAndDispose(contextEditCtr);
        contextEditCtr = new UsrPropContextEditController(ureq, getWindowControl(), contextRow.getValue(), contextRow.getKey());
        editBox = new CloseableModalController(getWindowControl(), translate("close"), contextEditCtr.getInitialComponent(), true, translate("upc.context.edit") + " :: " + contextRow.getKey(), true);
        listenTo(editBox);
        editBox.activate();
    } else if (source.equals(contextEditCtr)) {
    // nothing to do
    } else if (source.equals(editBox)) {
        if (event.equals(CloseableModalController.CLOSE_MODAL_EVENT)) {
            // edit-popup was closed, refresh our table
            refreshView();
        }
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) UserPropertyUsageContext(org.olat.user.propertyhandlers.UserPropertyUsageContext) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)

Example 7 with UserPropertyUsageContext

use of org.olat.user.propertyhandlers.UserPropertyUsageContext in project openolat by klemens.

the class UsrPropCfgManager method loadModifiedUserPropertiesConfig.

/**
 * loads our persisted Config and manipulates the Config of the user-manager
 * (which comes from xml-config)
 */
private void loadModifiedUserPropertiesConfig(Properties props) {
    log.info("loading modified UserPropertiesConfig");
    UserPropertiesConfig usrMngConfig = userManager.getUserPropertiesConfig();
    cfgObject = new UsrPropCfgObject(allUserPropertyHandlersFromXML, usrMngConfig.getUserPropertyUsageContexts());
    // now manipulate this cfgObject according to our own config ( from the
    // persistedProperties)
    List<String> val_activeHandlers = Arrays.asList(props.getProperty(CONF_KEY_ACTUPROP, "").split(PROP_DELIMITER));
    List<String> val_dactiveHandlers = Arrays.asList(props.getProperty(CONF_KEY_DACTUPROP, "").split(PROP_DELIMITER));
    for (UserPropertyHandler handler : cfgObject.getPropertyHandlers()) {
        // modify the groupName of the handler
        String groupName = props.getProperty(handler.getName() + CONF_KEY_PROPGROUP, null);
        if (groupName != null) {
            handler.setGroup(groupName);
        }
        // either it is set as an active property, or the property can't be deactivated (email, firstname, lastname, etc.)
        if (val_activeHandlers.contains(handler.getName()) || !UsrPropCfgManager.canBeDeactivated(handler)) {
            cfgObject.setHandlerAsActive(handler, true);
        } else if (!val_dactiveHandlers.contains(handler.getName())) {
            // this is a new handler (not yet in our own config)
            // -->set it as active
            // (note: if you delete persistedProperties-conf-file, all handlers are
            // "new" and therefore should be active)
            log.info("UserPropertyHandler " + handler.getName() + " unknown in config, set Property as active.");
            cfgObject.setHandlerAsActive(handler, true);
        }
    }
    // handle contexts (these are the contexts from xml)
    for (Entry<String, UserPropertyUsageContext> ctxEntry : cfgObject.getUsageContexts().entrySet()) {
        UserPropertyUsageContext ctx = ctxEntry.getValue();
        String contextName = ctxEntry.getKey();
        List<UserPropertyHandler> ctx_allHandlers = new ArrayList<UserPropertyHandler>();
        Set<UserPropertyHandler> ctx_mandHandlers = new HashSet<UserPropertyHandler>();
        Set<UserPropertyHandler> ctx_adminonlyHandlers = new HashSet<UserPropertyHandler>();
        Set<UserPropertyHandler> ctx_usrreadonlyHandlers = new HashSet<UserPropertyHandler>();
        String handlerNameInConfig = props.getProperty(contextName, null);
        if (handlerNameInConfig == null) {
            // our config doesn't know this context,
            // leave it as is!
            log.info("UserPropertyUsageContext " + contextName + " unknown in config, leave Context untouched.");
            continue;
        }
        // this list from the persistedProperties has the correct order of handlers!
        List<String> val_handlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX, "").split(PROP_DELIMITER));
        List<String> val_mandatoryHandlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_MANDATORY_PREFIX, "").split(PROP_DELIMITER));
        List<String> val_adminonlyHandlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_ADMINONLY_PREFIX, "").split(PROP_DELIMITER));
        List<String> val_userreadonlyHandlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_USERREADONLY_PREFIX, "").split(PROP_DELIMITER));
        for (UserPropertyHandler handler : cfgObject.getPropertyHandlers()) {
            String handlerName = handler.getName();
            if (val_handlers.contains(handlerName) && cfgObject.isActiveHandler(handler)) {
                ctx_allHandlers.add(handler);
                // either it is set as mandatory in config or it is one of the property where mandatory must be enforced :)
                if (val_mandatoryHandlers.contains(handlerName) || !UsrPropCfgManager.canBeOptionalInContext(handler, contextName)) {
                    ctx_mandHandlers.add(handler);
                }
                if (val_adminonlyHandlers.contains(handlerName)) {
                    ctx_adminonlyHandlers.add(handler);
                }
                if (val_userreadonlyHandlers.contains(handlerName)) {
                    ctx_usrreadonlyHandlers.add(handler);
                }
            }
        }
        ctx.setPropertyHandlers(restoreCorrectHandlerOrderWithinContext(ctx_allHandlers, val_handlers));
        ctx.setMandatoryProperties(ctx_mandHandlers);
        ctx.setAdminViewOnlyProperties(ctx_adminonlyHandlers);
        ctx.setUserViewReadOnlyProperties(ctx_usrreadonlyHandlers);
    }
    // create new modified userPropertiesConfig for UserManager
    setUserManagerProperties();
}
Also used : UserPropertyUsageContext(org.olat.user.propertyhandlers.UserPropertyUsageContext) ArrayList(java.util.ArrayList) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) UserPropertiesConfig(org.olat.user.UserPropertiesConfig) HashSet(java.util.HashSet)

Example 8 with UserPropertyUsageContext

use of org.olat.user.propertyhandlers.UserPropertyUsageContext in project openolat by klemens.

the class UsrPropCfgManager method savePersistedProperties.

/**
 * saves our config to persistedProperties
 */
private void savePersistedProperties() {
    StringBuilder sbActiveHandlers = new StringBuilder();
    StringBuilder sbDeactiveHandlers = new StringBuilder();
    // the propertyhandlers
    for (UserPropertyHandler handler : cfgObject.getPropertyHandlers()) {
        // save the group of each handler
        setStringProperty(handler.getName() + CONF_KEY_PROPGROUP, handler.getGroup(), false);
        if (cfgObject.isActiveHandler(handler)) {
            sbActiveHandlers.append(handler.getName() + PROP_DELIMITER);
        } else {
            sbDeactiveHandlers.append(handler.getName() + PROP_DELIMITER);
        }
    }
    setStringProperty(CONF_KEY_ACTUPROP, sbActiveHandlers.toString(), false);
    setStringProperty(CONF_KEY_DACTUPROP, sbDeactiveHandlers.toString(), false);
    // the contexts
    for (Entry<String, UserPropertyUsageContext> ctxEntry : cfgObject.getUsageContexts().entrySet()) {
        StringBuilder sbHandlers = new StringBuilder();
        StringBuilder sbMandatoryHandlers = new StringBuilder();
        StringBuilder sbAdminonlyHandlers = new StringBuilder();
        StringBuilder sbUsrreadonlyHandlers = new StringBuilder();
        // now loop over the handlers in the current context
        UserPropertyUsageContext ctx = ctxEntry.getValue();
        for (UserPropertyHandler handler : ctx.getPropertyHandlers()) {
            if (cfgObject.isActiveHandler(handler)) {
                sbHandlers.append(handler.getName() + PROP_DELIMITER);
                log.debug(ctxEntry.getKey() + " has active handler :" + handler.getName());
            }
            if (ctx.isMandatoryUserProperty(handler)) {
                sbMandatoryHandlers.append(handler.getName() + PROP_DELIMITER);
            }
            if (ctx.isForAdministrativeUserOnly(handler)) {
                sbAdminonlyHandlers.append(handler.getName() + PROP_DELIMITER);
            }
            if (ctx.isUserViewReadOnly(handler)) {
                sbUsrreadonlyHandlers.append(handler.getName() + PROP_DELIMITER);
            }
        }
        setStringProperty(ctxEntry.getKey(), "1", false);
        setStringProperty(ctxEntry.getKey() + CONF_KEY_CONTPREFIX, sbHandlers.toString(), false);
        setStringProperty(ctxEntry.getKey() + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_MANDATORY_PREFIX, sbMandatoryHandlers.toString(), false);
        setStringProperty(ctxEntry.getKey() + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_ADMINONLY_PREFIX, sbAdminonlyHandlers.toString(), false);
        setStringProperty(ctxEntry.getKey() + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_USERREADONLY_PREFIX, sbUsrreadonlyHandlers.toString(), false);
    }
    // now persist
    savePropertiesAndFireChangedEvent();
}
Also used : UserPropertyUsageContext(org.olat.user.propertyhandlers.UserPropertyUsageContext) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 9 with UserPropertyUsageContext

use of org.olat.user.propertyhandlers.UserPropertyUsageContext in project openolat by klemens.

the class UsrPropContextCfgTableModel method getValueAt.

@Override
public Object getValueAt(int row, int col) {
    Entry<String, UserPropertyUsageContext> contextRow = objects.get(row);
    UserPropertyUsageContext ucontext = contextRow.getValue();
    switch(col) {
        case 0:
            return contextRow.getKey();
        case 1:
            return ucontext.getDescription();
        case 2:
            return ucontext.getPropertyHandlers().size();
        default:
            return "-";
    }
}
Also used : UserPropertyUsageContext(org.olat.user.propertyhandlers.UserPropertyUsageContext)

Example 10 with UserPropertyUsageContext

use of org.olat.user.propertyhandlers.UserPropertyUsageContext in project openolat by klemens.

the class SimpleMessageModule method enableSmsUserProperty.

private void enableSmsUserProperty() {
    List<UserPropertyHandler> handlers = usrPropCfgMng.getUserPropertiesConfigObject().getPropertyHandlers();
    UserPropertyHandler smsHandler = null;
    UserPropertyHandler mobileHandler = null;
    for (UserPropertyHandler handler : handlers) {
        if (UserConstants.SMSTELMOBILE.equals(handler.getName())) {
            smsHandler = handler;
        } else if (UserConstants.TELMOBILE.equals(handler.getName())) {
            mobileHandler = handler;
        }
    }
    if (smsHandler != null) {
        UserPropertyUsageContext context = usrPropCfgMng.getUserPropertiesConfigObject().getUsageContexts().get("org.olat.user.ProfileFormController");
        if (!context.contains(smsHandler)) {
            if (mobileHandler == null) {
                context.addPropertyHandler(smsHandler);
            } else {
                int index = context.getPropertyHandlers().indexOf(mobileHandler);
                context.addPropertyHandler(index + 1, smsHandler);
            }
        }
    }
}
Also used : UserPropertyUsageContext(org.olat.user.propertyhandlers.UserPropertyUsageContext) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

UserPropertyUsageContext (org.olat.user.propertyhandlers.UserPropertyUsageContext)10 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)6 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TableEvent (org.olat.core.gui.components.table.TableEvent)2 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)2 UserPropertiesConfig (org.olat.user.UserPropertiesConfig)2