Search in sources :

Example 76 with UserPropertyHandler

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

the class CertificatesSelectionController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    ;
    int colPos = 0;
    if (isAdministrativeUser) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.name", CertificatesSelectionDataModel.USERNAME_COL));
    }
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(AssessedIdentitiesTableDataModel.usageIdentifyer, isAdministrativeUser);
    List<UserPropertyHandler> resultingPropertyHandlers = new ArrayList<UserPropertyHandler>();
    // followed by the users fields
    for (int i = 0; i < userPropertyHandlers.size(); i++) {
        UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
        boolean visible = userManager.isMandatoryUserProperty(AssessedIdentitiesTableDataModel.usageIdentifyer, userPropertyHandler);
        resultingPropertyHandlers.add(userPropertyHandler);
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos++, false, null));
    }
    if (hasAssessableNodes) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.passed", CertificatesSelectionDataModel.PASSED_COL, new PassedCellRenderer()));
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.score", CertificatesSelectionDataModel.SCORE_COL));
    }
    tableModel = new CertificatesSelectionDataModel(columnsModel, resultingPropertyHandlers);
    Set<Integer> preselectedRows = new HashSet<>();
    ICourse course = CourseFactory.loadCourse(courseEntry);
    CourseNode rootNode = course.getRunStructure().getRootNode();
    List<CertificateInfos> infos = new ArrayList<>(datas.size());
    int count = 0;
    for (AssessedIdentityWrapper data : datas) {
        ScoreEvaluation scoreEval = data.getUserCourseEnvironment().getScoreAccounting().getScoreEvaluation(rootNode);
        Float score = scoreEval == null ? null : scoreEval.getScore();
        Boolean passed = scoreEval == null ? null : scoreEval.getPassed();
        Identity assessedIdentity = data.getIdentity();
        infos.add(new CertificateInfos(assessedIdentity, score, passed));
        if (passed != null && passed.booleanValue()) {
            preselectedRows.add(new Integer(count));
        }
        count++;
    }
    tableModel.setObjects(infos);
    tableEl = uifactory.addTableElement(getWindowControl(), "selection", tableModel, getTranslator(), formLayout);
    tableEl.setMultiSelect(true);
    tableEl.setSelectAllEnable(true);
    tableEl.setMultiSelectedIndex(preselectedRows);
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) AssessedIdentityWrapper(org.olat.course.assessment.AssessedIdentityWrapper) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) CourseNode(org.olat.course.nodes.CourseNode) PassedCellRenderer(org.olat.course.assessment.bulk.PassedCellRenderer) Identity(org.olat.core.id.Identity) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) HashSet(java.util.HashSet)

Example 77 with UserPropertyHandler

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

the class UserBulkChangeManager method setUserContext.

/**
 * @param identity
 * @param vcContext
 * @param isAdministrativeUser
 */
public void setUserContext(Identity identity, Context vcContext) {
    List<UserPropertyHandler> userPropertyHandlers2 = userManager.getAllUserPropertyHandlers();
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers2) {
        String propertyName = userPropertyHandler.getName();
        String userValue = identity.getUser().getProperty(propertyName, null);
        vcContext.put(propertyName, userValue);
    }
}
Also used : UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 78 with UserPropertyHandler

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

the class UserBulkChangeManager method changeSelectedIdentities.

public void changeSelectedIdentities(List<Identity> selIdentities, Map<String, String> attributeChangeMap, Map<String, String> roleChangeMap, List<String> notUpdatedIdentities, boolean isAdministrativeUser, List<Long> ownGroups, List<Long> partGroups, Translator trans, Identity addingIdentity) {
    Translator transWithFallback = userManager.getPropertyHandlerTranslator(trans);
    String usageIdentifyer = UserBulkChangeStep00.class.getCanonicalName();
    notUpdatedIdentities.clear();
    List<Identity> changedIdentities = new ArrayList<>();
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser);
    String[] securityGroups = { Constants.GROUP_USERMANAGERS, Constants.GROUP_GROUPMANAGERS, Constants.GROUP_AUTHORS, Constants.GROUP_ADMIN, Constants.GROUP_POOL_MANAGER, Constants.GROUP_INST_ORES_MANAGER };
    // loop over users to be edited:
    for (Identity identity : selIdentities) {
        // reload identity from cache, to prevent stale object
        identity = securityManager.loadIdentityByKey(identity.getKey());
        User user = identity.getUser();
        String oldEmail = user.getEmail();
        String errorDesc = "";
        boolean updateError = false;
        // change pwd
        if (attributeChangeMap.containsKey(PWD_IDENTIFYER)) {
            String newPwd = attributeChangeMap.get(PWD_IDENTIFYER);
            if (StringHelper.containsNonWhitespace(newPwd)) {
                if (!userManager.syntaxCheckOlatPassword(newPwd)) {
                    errorDesc = transWithFallback.translate("error.password");
                    updateError = true;
                }
            } else {
                newPwd = null;
            }
            olatAuthManager.changePasswordAsAdmin(identity, newPwd);
        }
        // set language
        String userLanguage = user.getPreferences().getLanguage();
        if (attributeChangeMap.containsKey(LANG_IDENTIFYER)) {
            String inputLanguage = attributeChangeMap.get(LANG_IDENTIFYER);
            if (!userLanguage.equals(inputLanguage)) {
                Preferences preferences = user.getPreferences();
                preferences.setLanguage(inputLanguage);
                user.setPreferences(preferences);
            }
        }
        Context vcContext = new VelocityContext();
        // set all properties as context
        setUserContext(identity, vcContext);
        // org.olat.admin.user.bulkChange.UserBulkChangeStep00
        for (int k = 0; k < userPropertyHandlers.size(); k++) {
            UserPropertyHandler propHandler = userPropertyHandlers.get(k);
            String propertyName = propHandler.getName();
            String userValue = identity.getUser().getProperty(propertyName, null);
            String inputFieldValue = "";
            if (attributeChangeMap.containsKey(propertyName)) {
                inputFieldValue = attributeChangeMap.get(propertyName);
                inputFieldValue = inputFieldValue.replace("$", "$!");
                String evaluatedInputFieldValue = evaluateValueWithUserContext(inputFieldValue, vcContext);
                // validate evaluated property-value
                ValidationError validationError = new ValidationError();
                // do validation checks with users current locale!
                Locale locale = transWithFallback.getLocale();
                if (!propHandler.isValidValue(identity.getUser(), evaluatedInputFieldValue, validationError, locale)) {
                    errorDesc = transWithFallback.translate(validationError.getErrorKey(), validationError.getArgs()) + " (" + evaluatedInputFieldValue + ")";
                    updateError = true;
                    break;
                }
                if (!evaluatedInputFieldValue.equals(userValue)) {
                    String stringValue = propHandler.getStringValue(evaluatedInputFieldValue, locale);
                    propHandler.setUserProperty(user, stringValue);
                }
            }
        }
        // loop over securityGroups defined above
        for (String securityGroup : securityGroups) {
            SecurityGroup secGroup = securityManager.findSecurityGroupByName(securityGroup);
            Boolean isInGroup = securityManager.isIdentityInSecurityGroup(identity, secGroup);
            String thisRoleAction = "";
            if (roleChangeMap.containsKey(securityGroup)) {
                thisRoleAction = roleChangeMap.get(securityGroup);
                // user not anymore in security group, remove him
                if (isInGroup && thisRoleAction.equals("remove")) {
                    securityManager.removeIdentityFromSecurityGroup(identity, secGroup);
                    log.audit("User::" + addingIdentity.getName() + " removed system role::" + securityGroup + " from user::" + identity.getName(), null);
                }
                // user not yet in security group, add him
                if (!isInGroup && thisRoleAction.equals("add")) {
                    securityManager.addIdentityToSecurityGroup(identity, secGroup);
                    log.audit("User::" + addingIdentity.getName() + " added system role::" + securityGroup + " to user::" + identity.getName(), null);
                }
            }
        }
        // set status
        if (roleChangeMap.containsKey("Status")) {
            Integer status = Integer.parseInt(roleChangeMap.get("Status"));
            int oldStatus = identity.getStatus();
            String oldStatusText = (oldStatus == Identity.STATUS_PERMANENT ? "permanent" : (oldStatus == Identity.STATUS_ACTIV ? "active" : (oldStatus == Identity.STATUS_LOGIN_DENIED ? "login_denied" : (oldStatus == Identity.STATUS_DELETED ? "deleted" : "unknown"))));
            String newStatusText = (status == Identity.STATUS_PERMANENT ? "permanent" : (status == Identity.STATUS_ACTIV ? "active" : (status == Identity.STATUS_LOGIN_DENIED ? "login_denied" : (status == Identity.STATUS_DELETED ? "deleted" : "unknown"))));
            if (oldStatus != status && status == Identity.STATUS_LOGIN_DENIED && Boolean.parseBoolean(roleChangeMap.get("sendLoginDeniedEmail"))) {
                sendLoginDeniedEmail(identity);
            }
            identity = securityManager.saveIdentityStatus(identity, status);
            log.audit("User::" + addingIdentity.getName() + " changed accout status for user::" + identity.getName() + " from::" + oldStatusText + " to::" + newStatusText, null);
        }
        // persist changes:
        if (updateError) {
            String errorOutput = identity.getName() + ": " + errorDesc;
            log.debug("error during bulkChange of users, following user could not be updated: " + errorOutput);
            notUpdatedIdentities.add(errorOutput);
        } else {
            userManager.updateUserFromIdentity(identity);
            securityManager.deleteInvalidAuthenticationsByEmail(oldEmail);
            changedIdentities.add(identity);
            log.audit("User::" + addingIdentity.getName() + " successfully changed account data for user::" + identity.getName() + " in bulk change", null);
        }
        // commit changes for this user
        dbInstance.commit();
    }
    // FXOLAT-101: add identity to new groups:
    if (ownGroups.size() != 0 || partGroups.size() != 0) {
        List<BusinessGroupMembershipChange> changes = new ArrayList<BusinessGroupMembershipChange>();
        for (Identity selIdentity : selIdentities) {
            if (ownGroups != null && !ownGroups.isEmpty()) {
                for (Long tutorGroupKey : ownGroups) {
                    BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(selIdentity, tutorGroupKey);
                    change.setTutor(Boolean.TRUE);
                    changes.add(change);
                }
            }
            if (partGroups != null && !partGroups.isEmpty()) {
                for (Long partGroupKey : partGroups) {
                    BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(selIdentity, partGroupKey);
                    change.setParticipant(Boolean.TRUE);
                    changes.add(change);
                }
            }
        }
        MailPackage mailing = new MailPackage();
        businessGroupService.updateMemberships(addingIdentity, changes, mailing);
        dbInstance.commit();
    }
}
Also used : Context(org.apache.velocity.context.Context) VelocityContext(org.apache.velocity.VelocityContext) Locale(java.util.Locale) User(org.olat.core.id.User) MailPackage(org.olat.core.util.mail.MailPackage) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) SecurityGroup(org.olat.basesecurity.SecurityGroup) BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) Translator(org.olat.core.gui.translator.Translator) ValidationError(org.olat.core.gui.components.form.ValidationError) Identity(org.olat.core.id.Identity) Preferences(org.olat.core.id.Preferences) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 79 with UserPropertyHandler

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

the class UserBulkChangeManager method getDemoContext.

public Context getDemoContext(Translator propertyTrans) {
    Context vcContext = new VelocityContext();
    List<UserPropertyHandler> userPropertyHandlers2 = userManager.getAllUserPropertyHandlers();
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers2) {
        String propertyName = userPropertyHandler.getName();
        String userValue = propertyTrans.translate("import.example." + userPropertyHandler.getName());
        vcContext.put(propertyName, userValue);
    }
    return vcContext;
}
Also used : Context(org.apache.velocity.context.Context) VelocityContext(org.apache.velocity.VelocityContext) VelocityContext(org.apache.velocity.VelocityContext) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 80 with UserPropertyHandler

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

the class GroupController method initGroupTable.

/**
 * Init GroupList-table-controller for non-waitinglist (participant-list,
 * owner-list).
 */
protected void initGroupTable(TableController tableController, UserRequest ureq, boolean enableTablePreferences, boolean enableUserSelection) {
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser);
    if (isAdministrativeUser) {
        // first the login name, but only if administrative user
        DefaultColumnDescriptor cd0 = new DefaultColumnDescriptor("table.user.login", 0, COMMAND_VCARD, ureq.getLocale());
        cd0.setIsPopUpWindowAction(true, "height=700, width=900, location=no, menubar=no, resizable=yes, status=no, scrollbars=yes, toolbar=no");
        tableController.addColumnDescriptor(cd0);
    }
    if (chatEnabled) {
        tableController.addColumnDescriptor(new CustomRenderColumnDescriptor("table.header.online", 1, COMMAND_IM, getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, new OnlineIconRenderer()));
    }
    int visibleColId = 0;
    // followed by the users fields
    for (int i = 0; i < userPropertyHandlers.size(); i++) {
        UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
        boolean visible = userManager.isMandatoryUserProperty(usageIdentifyer, userPropertyHandler);
        ColumnDescriptor cd = userPropertyHandler.getColumnDescriptor(i + 3, COMMAND_VCARD, ureq.getLocale());
        // make all user attributes clickable to open visiting card
        if (cd instanceof DefaultColumnDescriptor) {
            DefaultColumnDescriptor dcd = (DefaultColumnDescriptor) cd;
            dcd.setIsPopUpWindowAction(true, "height=700, width=900, location=no, menubar=no, resizable=yes, status=no, scrollbars=yes, toolbar=no");
        }
        tableController.addColumnDescriptor(visible, cd);
        if (visible) {
            visibleColId++;
        }
    }
    // in the end
    if (enableTablePreferences) {
        DefaultColumnDescriptor dcd = new DefaultColumnDescriptor("table.subject.addeddate", 2, COMMAND_VCARD, ureq.getLocale());
        dcd.setIsPopUpWindowAction(true, "height=700, width=900, location=no, menubar=no, resizable=yes, status=no, scrollbars=yes, toolbar=no");
        tableController.addColumnDescriptor(true, dcd);
        tableController.setSortColumn(++visibleColId, true);
    }
    if (enableUserSelection) {
        tableController.addColumnDescriptor(new StaticColumnDescriptor(COMMAND_SELECTUSER, "table.subject.action", myTrans.translate("action.general")));
    }
    if (mayModifyMembers) {
        tableController.addMultiSelectAction("action.remove", COMMAND_REMOVEUSER);
        tableController.setMultiSelect(true);
    }
}
Also used : CustomRenderColumnDescriptor(org.olat.core.gui.components.table.CustomRenderColumnDescriptor) OnlineIconRenderer(org.olat.group.ui.main.OnlineIconRenderer) CustomRenderColumnDescriptor(org.olat.core.gui.components.table.CustomRenderColumnDescriptor) DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor) StaticColumnDescriptor(org.olat.core.gui.components.table.StaticColumnDescriptor) ColumnDescriptor(org.olat.core.gui.components.table.ColumnDescriptor) StaticColumnDescriptor(org.olat.core.gui.components.table.StaticColumnDescriptor) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor)

Aggregations

UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)319 Identity (org.olat.core.id.Identity)84 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)74 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)70 ArrayList (java.util.ArrayList)62 FormItem (org.olat.core.gui.components.form.flexible.FormItem)62 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)56 User (org.olat.core.id.User)52 HashMap (java.util.HashMap)40 StaticFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer)36 FlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel)34 Translator (org.olat.core.gui.translator.Translator)32 Date (java.util.Date)30 UserManager (org.olat.user.UserManager)28 TextFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer)24 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)24 File (java.io.File)22 BusinessGroup (org.olat.group.BusinessGroup)22 SortKey (org.olat.core.commons.persistence.SortKey)18 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)18