Search in sources :

Example 6 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class IQEditReplaceWizard method doStep2.

private void doStep2(UserRequest ureq) {
    String nodeTitle = courseNode.getShortTitle();
    if (results != null && !results.isEmpty()) {
        exportDir = CourseFactory.getOrCreateDataExportDirectory(ureq.getIdentity(), course.getCourseTitle());
        UserManager um = UserManager.getInstance();
        String charset = um.getUserCharset(ureq.getIdentity());
        QTIExportManager qem = QTIExportManager.getInstance();
        Long repositoryRef = results.get(0).getResultSet().getRepositoryRef();
        List<QTIItemObject> qtiItemObjectList = new QTIObjectTreeBuilder().getQTIItemObjectList(repositoryRef);
        QTIExportFormatter formatter;
        if (courseNode instanceof IQTESTCourseNode) {
            formatter = new QTIExportFormatterCSVType1(ureq.getLocale(), "\t", "\"", "\r\n", false);
        } else if (courseNode instanceof IQSELFCourseNode) {
            formatter = new QTIExportFormatterCSVType1(ureq.getLocale(), "\t", "\"", "\r\n", false);
            ((QTIExportFormatterCSVType1) formatter).setAnonymous(true);
        } else {
            formatter = new QTIExportFormatterCSVType3(ureq.getLocale(), null, "\t", "\"", "\r\n", false);
        }
        Map<Class<?>, QTIExportItemFormatConfig> qtiItemConfigs = getQTIItemConfigs(qtiItemObjectList);
        formatter.setMapWithExportItemConfigs(qtiItemConfigs);
        resultExportFile = qem.exportResults(formatter, results, qtiItemObjectList, courseNode.getShortTitle(), exportDir, charset, ".xls");
        vcStep2 = createVelocityContainer("replacewizard_step2");
        String[] args1 = new String[] { Integer.toString(learners.size()) };
        vcStep2.contextPut("information", translate("replace.wizard.information.paragraph1", args1));
        String[] args2 = new String[] { exportDir.getName(), resultExportFile };
        vcStep2.contextPut("information_par2", translate("replace.wizard.information.paragraph2", args2));
        vcStep2.contextPut("nodetitle", nodeTitle);
        showFileButton = LinkFactory.createButton("replace.wizard.showfile", vcStep2, this);
    } else {
        // it exists no result
        String[] args = new String[] { Integer.toString(numberOfQtiSerEntries) };
        vcStep2 = createVelocityContainer("replacewizard_step2");
        vcStep2.contextPut("information", translate("replace.wizard.information.empty.results", args));
        vcStep2.contextPut("nodetitle", nodeTitle);
    }
    nextBtn = LinkFactory.createButton("replace.wizard.next", vcStep2, this);
    setNextWizardStep(translate("replace.wizard.title.step2"), vcStep2);
}
Also used : QTIExportFormatterCSVType1(org.olat.ims.qti.export.QTIExportFormatterCSVType1) QTIExportFormatterCSVType3(org.olat.ims.qti.export.QTIExportFormatterCSVType3) QTIExportFormatter(org.olat.ims.qti.export.QTIExportFormatter) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) QTIItemObject(org.olat.ims.qti.export.helper.QTIItemObject) UserManager(org.olat.user.UserManager) QTIExportManager(org.olat.ims.qti.export.QTIExportManager) QTIObjectTreeBuilder(org.olat.ims.qti.export.helper.QTIObjectTreeBuilder) IQSELFCourseNode(org.olat.course.nodes.IQSELFCourseNode) QTIExportItemFormatConfig(org.olat.ims.qti.export.QTIExportItemFormatConfig)

Example 7 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class FileSystemExport method fsToZip.

/**
 * Exports a given filesystem as Zip-Outputstream
 *
 * @param zout the Zip-Outputstream
 * @param sourceFolder the source folder
 * @param pfNode the PFCourseNode
 * @param identities
 * @param translator
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static boolean fsToZip(ZipOutputStream zout, final Path sourceFolder, PFCourseNode pfNode, List<Identity> identities, Translator translator) {
    String targetPath = translator.translate("participant.folder") + "/";
    UserManager userManager = CoreSpringFactory.getImpl(UserManager.class);
    Set<String> idKeys = new HashSet<>();
    if (identities != null) {
        for (Identity identity : identities) {
            idKeys.add(identity.getKey().toString());
        }
    } else {
        File[] listOfFiles = sourceFolder.toFile().listFiles();
        if (listOfFiles != null) {
            for (File file : listOfFiles) {
                if (file.isDirectory()) {
                    idKeys.add(file.getName());
                }
            }
        }
    }
    try {
        Files.walkFileTree(sourceFolder, new SimpleFileVisitor<Path>() {

            // contains identity check  and changes identity key to user display name
            private String containsID(String relPath) {
                for (String key : idKeys) {
                    // additional check if folder is a identity-key (coming from fs)
                    if (relPath.contains(key) && StringHelper.isLong(key)) {
                        String exportFolderName = userManager.getUserDisplayName(Long.parseLong(key)).replace(", ", "_") + "_" + key;
                        return relPath.replace(key.toString(), exportFolderName);
                    }
                }
                return null;
            }

            // checks module config and translates folder name
            private String boxesEnabled(String relPath) {
                if (pfNode.hasParticipantBoxConfigured() && relPath.contains(PFManager.FILENAME_DROPBOX)) {
                    return relPath.replace(PFManager.FILENAME_DROPBOX, translator.translate("drop.box"));
                } else if (pfNode.hasCoachBoxConfigured() && relPath.contains(PFManager.FILENAME_RETURNBOX)) {
                    return relPath.replace(PFManager.FILENAME_RETURNBOX, translator.translate("return.box"));
                } else {
                    return null;
                }
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                String relPath = sourceFolder.relativize(file).toString();
                if ((relPath = containsID(relPath)) != null && (relPath = boxesEnabled(relPath)) != null) {
                    zout.putNextEntry(new ZipEntry(targetPath + relPath));
                    Files.copy(file, zout);
                    zout.closeEntry();
                }
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                String relPath = sourceFolder.relativize(dir).toString() + "/";
                if ((relPath = containsID(relPath)) != null && (relPath = boxesEnabled(relPath)) != null) {
                    zout.putNextEntry(new ZipEntry(targetPath + relPath));
                    zout.closeEntry();
                }
                return FileVisitResult.CONTINUE;
            }
        });
        zout.close();
        return true;
    } catch (IOException e) {
        log.error("Unable to export zip", e);
        return false;
    }
}
Also used : Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) UserManager(org.olat.user.UserManager) Identity(org.olat.core.id.Identity) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) HashSet(java.util.HashSet)

Example 8 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class DatePropertyHandler method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale, org.olat.core.id.User, java.lang.String, boolean, org.olat.core.gui.components.form.flexible.FormItemContainer)
 */
@Override
public FormItem addFormItem(Locale locale, final User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    org.olat.core.gui.components.form.flexible.elements.DateChooser dateElem = null;
    Date val = decode(getInternalValue(user));
    dateElem = FormUIFactory.getInstance().addDateChooser(getName(), i18nFormElementLabelKey(), val, formItemContainer);
    dateElem.setItemValidatorProvider(new ItemValidatorProvider() {

        @Override
        public boolean isValidValue(String value, ValidationError validationError, Locale llocale) {
            return DatePropertyHandler.this.isValidValue(user, value, validationError, llocale);
        }
    });
    UserManager um = UserManager.getInstance();
    if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
        dateElem.setEnabled(false);
    }
    if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
        dateElem.setMandatory(true);
    }
    dateElem.setExampleKey("form.example.free", new String[] { Formatter.getInstance(locale).formatDate(new Date()) });
    return dateElem;
}
Also used : Locale(java.util.Locale) DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) UserManager(org.olat.user.UserManager) ValidationError(org.olat.core.gui.components.form.ValidationError) Date(java.util.Date)

Example 9 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class Generic127CharTextPropertyHandler method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale, org.olat.core.id.User, java.lang.String, boolean, org.olat.core.gui.components.form.flexible.FormItemContainer)
 */
@Override
public FormItem addFormItem(Locale locale, final User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    org.olat.core.gui.components.form.flexible.elements.TextElement tElem = null;
    tElem = FormUIFactory.getInstance().addTextElement(getName(), i18nFormElementLabelKey(), 127, getInternalValue(user), formItemContainer);
    tElem.setItemValidatorProvider(new ItemValidatorProvider() {

        @Override
        public boolean isValidValue(String value, ValidationError validationError, Locale llocale) {
            return Generic127CharTextPropertyHandler.this.isValidValue(user, value, validationError, llocale);
        }
    });
    tElem.setLabel(i18nFormElementLabelKey(), null);
    UserManager um = UserManager.getInstance();
    if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
        tElem.setEnabled(false);
    }
    if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
        tElem.setMandatory(true);
    }
    return tElem;
}
Also used : Locale(java.util.Locale) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) UserManager(org.olat.user.UserManager) ValidationError(org.olat.core.gui.components.form.ValidationError) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement)

Example 10 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class RegistrationController method createNewUserAfterRegistration.

/**
 * OO-92
 * this will finally create the user, set all it's userproperties
 *
 * @return User the newly created, persisted User Object
 */
private Identity createNewUserAfterRegistration() {
    // create user with mandatory fields from registration-form
    UserManager um = UserManager.getInstance();
    User volatileUser = um.createUser(registrationForm.getFirstName(), registrationForm.getLastName(), tempKey.getEmailAddress());
    // set user configured language
    Preferences preferences = volatileUser.getPreferences();
    preferences.setLanguage(registrationForm.getLangKey());
    volatileUser.setPreferences(preferences);
    // create an identity with the given username / pwd and the user object
    String login = registrationForm.getLogin();
    String pwd = registrationForm.getPassword();
    Identity persistedIdentity = registrationManager.createNewUserAndIdentityFromTemporaryKey(login, pwd, volatileUser, tempKey);
    if (persistedIdentity == null) {
        showError("user.notregistered");
        return null;
    } else {
        // update other user properties from form
        List<UserPropertyHandler> userPropertyHandlers = um.getUserPropertyHandlersFor(RegistrationForm2.USERPROPERTIES_FORM_IDENTIFIER, false);
        User persistedUser = persistedIdentity.getUser();
        // add eventually static value
        UserPropertiesConfig userPropertiesConfig = CoreSpringFactory.getImpl(UserPropertiesConfig.class);
        if (registrationModule.isStaticPropertyMappingEnabled()) {
            String propertyName = registrationModule.getStaticPropertyMappingName();
            String propertyValue = registrationModule.getStaticPropertyMappingValue();
            if (StringHelper.containsNonWhitespace(propertyName) && StringHelper.containsNonWhitespace(propertyValue) && userPropertiesConfig.getPropertyHandler(propertyName) != null) {
                try {
                    persistedUser.setProperty(propertyName, propertyValue);
                } catch (Exception e) {
                    logError("Cannot set the static property value", e);
                }
            }
        }
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            FormItem fi = registrationForm.getPropFormItem(userPropertyHandler.getName());
            userPropertyHandler.updateUserFromFormItem(persistedUser, fi);
        }
        // persist changes in db
        um.updateUserFromIdentity(persistedIdentity);
        // send notification mail to sys admin
        String notiEmail = CoreSpringFactory.getImpl(RegistrationModule.class).getRegistrationNotificationEmail();
        if (notiEmail != null) {
            registrationManager.sendNewUserNotificationMessage(notiEmail, persistedIdentity);
        }
        // tell system that this user did accept the disclaimer
        registrationManager.setHasConfirmedDislaimer(persistedIdentity);
        return persistedIdentity;
    }
}
Also used : User(org.olat.core.id.User) UserManager(org.olat.user.UserManager) FormItem(org.olat.core.gui.components.form.flexible.FormItem) Preferences(org.olat.core.id.Preferences) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) UserPropertiesConfig(org.olat.user.UserPropertiesConfig)

Aggregations

UserManager (org.olat.user.UserManager)64 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)22 Locale (java.util.Locale)12 Identity (org.olat.core.id.Identity)12 Date (java.util.Date)10 FormItem (org.olat.core.gui.components.form.flexible.FormItem)10 Translator (org.olat.core.gui.translator.Translator)10 User (org.olat.core.id.User)10 ArrayList (java.util.ArrayList)8 File (java.io.File)6 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)6 RestSecurityHelper.getLocale (org.olat.restapi.security.RestSecurityHelper.getLocale)6 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 ValidationError (org.olat.core.gui.components.form.ValidationError)4 SelectionElement (org.olat.core.gui.components.form.flexible.elements.SelectionElement)4 ItemValidatorProvider (org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider)4 AssertException (org.olat.core.logging.AssertException)4 ICourse (org.olat.course.ICourse)4 RestSecurityHelper.isUserManager (org.olat.restapi.security.RestSecurityHelper.isUserManager)4