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