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);
}
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;
}
}
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;
}
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;
}
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;
}
}
Aggregations