Search in sources :

Example 56 with User

use of org.olat.core.id.User in project OpenOLAT by OpenOLAT.

the class UserTest method testSetUserProfile.

/**
 * test if user profile does work
 * @throws Exception
 */
@Test
public void testSetUserProfile() throws Exception {
    // preferences that are not set to a value must not return null
    // The preferences object itself must not be null - a user always has
    // a preferences object
    String fs = u1.getPreferences().getLanguage();
    assertTrue(fs != null);
    // change preferences values and look it up (test only one
    // attribute, we assume that getters and setters do work!)
    u1.getPreferences().setLanguage("de");
    userManager.updateUser(u1);
    User u1test = userManager.loadUserByKey(u1.getKey());
    assertTrue(u1test.getPreferences().getLanguage().matches("de"));
}
Also used : User(org.olat.core.id.User) Test(org.junit.Test)

Example 57 with User

use of org.olat.core.id.User in project OpenOLAT by OpenOLAT.

the class UserTest method testEquals.

@Test
public void testEquals() {
    User user1 = userManager.findUniqueIdentityByEmail("salat@id.salat.uzh.ch").getUser();
    User user2 = userManager.findUniqueIdentityByEmail("migros@id.migros.uzh.ch").getUser();
    User user1_2 = userManager.findUniqueIdentityByEmail("salat@id.salat.uzh.ch").getUser();
    assertFalse("Wrong equals implementation, different types are recognized as equals ", user1.equals(new Integer(1)));
    assertFalse("Wrong equals implementation, different users are recognized as equals ", user1.equals(user2));
    assertFalse("Wrong equals implementation, null value is recognized as equals ", user1.equals(null));
    assertTrue("Wrong equals implementation, same users are NOT recognized as equals ", user1.equals(user1));
    assertTrue("Wrong equals implementation, same users are NOT recognized as equals ", user1.equals(user1_2));
}
Also used : User(org.olat.core.id.User) Test(org.junit.Test)

Example 58 with User

use of org.olat.core.id.User in project OpenOLAT by OpenOLAT.

the class UserTest method testHashCode.

@Test
public void testHashCode() {
    User user1 = userManager.findUniqueIdentityByEmail("salat@id.salat.uzh.ch").getUser();
    User user2 = userManager.findUniqueIdentityByEmail("migros@id.migros.uzh.ch").getUser();
    User user1_2 = userManager.findUniqueIdentityByEmail("salat@id.salat.uzh.ch").getUser();
    assertTrue("Wrong hashCode implementation, same users have NOT same hash-code ", user1.hashCode() == user1.hashCode());
    assertFalse("Wrong hashCode implementation, different users have same hash-code", user1.hashCode() == user2.hashCode());
    assertTrue("Wrong hashCode implementation, same users have NOT same hash-code ", user1.hashCode() == user1_2.hashCode());
}
Also used : User(org.olat.core.id.User) Test(org.junit.Test)

Example 59 with User

use of org.olat.core.id.User in project OpenOLAT by OpenOLAT.

the class CustomDBController method exportDb.

private void exportDb(UserRequest ureq, final String category) {
    final ICourse course = CourseFactory.loadCourse(courseKey);
    String label = ExportUtil.createFileNameWithTimeStamp("DBS_" + course.getCourseTitle(), "xls");
    MediaResource export = new OpenXMLWorkbookResource(label) {

        @Override
        protected void generate(OutputStream out) {
            try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
                List<CourseDBEntry> content = courseDbManager.getValues(course, null, category, null);
                OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
                // create the headers
                Row headerRow = exportSheet.newRow();
                headerRow.addCell(0, translate("customDb.category"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(1, translate("customDb.entry.identity"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(2, translate("customDb.entry.name"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(3, translate("customDb.entry.value"), workbook.getStyles().getHeaderStyle());
                for (CourseDBEntry entry : content) {
                    User user = entry.getIdentity().getUser();
                    String name = user.getProperty(UserConstants.FIRSTNAME, null) + " " + user.getProperty(UserConstants.LASTNAME, null);
                    Row dataRow = exportSheet.newRow();
                    dataRow.addCell(0, entry.getCategory(), null);
                    dataRow.addCell(1, name, null);
                    if (StringHelper.containsNonWhitespace(entry.getName())) {
                        dataRow.addCell(2, entry.getName(), null);
                    }
                    if (entry.getValue() != null) {
                        dataRow.addCell(3, entry.getValue().toString(), null);
                    }
                }
            } catch (IOException e) {
                logError("", e);
            }
        }
    };
    ureq.getDispatchResult().setResultingMediaResource(export);
}
Also used : User(org.olat.core.id.User) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) OutputStream(java.io.OutputStream) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) ICourse(org.olat.course.ICourse) MediaResource(org.olat.core.gui.media.MediaResource) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) IOException(java.io.IOException) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet)

Example 60 with User

use of org.olat.core.id.User in project OpenOLAT by OpenOLAT.

the class GetUserPropertyFunction method call.

/**
 * @see org.olat.course.condition.interpreter.AbstractFunction#call(java.lang.Object[])
 */
public Object call(Object[] inStack) {
    /*
		 * argument check
		 */
    if (inStack.length > 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.providetwo.attrvalue"));
    } else if (inStack.length < 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.providetwo.attrvalue"));
    }
    /*
		 * argument type check
		 */
    if (!(inStack[0] instanceof String)) {
        return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attributename", "solution.example.name.infunction"));
    }
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        // return emtyp string to continue with condition evaluation test
        return defaultValue();
    }
    Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
    if (ident == null) {
        return defaultValue();
    }
    User user = ident.getUser();
    String propertyName = (String) inStack[0];
    // always use default locale
    String propertyValue = user.getProperty(propertyName, null);
    // case that we just ignore it.
    return (propertyValue == null ? defaultValue() : propertyValue);
}
Also used : User(org.olat.core.id.User) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity)

Aggregations

User (org.olat.core.id.User)260 Identity (org.olat.core.id.Identity)126 Test (org.junit.Test)82 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)52 HashMap (java.util.HashMap)28 Translator (org.olat.core.gui.translator.Translator)26 SecurityGroup (org.olat.basesecurity.SecurityGroup)20 Date (java.util.Date)18 ArrayList (java.util.ArrayList)16 Locale (java.util.Locale)16 FormItem (org.olat.core.gui.components.form.flexible.FormItem)16 File (java.io.File)14 VelocityContext (org.apache.velocity.VelocityContext)14 MailTemplate (org.olat.core.util.mail.MailTemplate)12 LDAPUser (org.olat.ldap.model.LDAPUser)12 UserManager (org.olat.user.UserManager)12 IOException (java.io.IOException)10 Map (java.util.Map)10 List (java.util.List)8 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8