use of org.olat.core.id.User in project openolat by klemens.
the class NotificationHelper method getFormatedName.
/**
* returns "firstname lastname" or a translated "user unknown" for a given
* identity
*
* @param ident
* @return
*/
public static String getFormatedName(Identity ident) {
String formattedName;
if (ident == null) {
Translator trans = Util.createPackageTranslator(NotificationNewsController.class, I18nManager.getInstance().getLocaleOrDefault(null));
return trans.translate("user.unknown");
} else {
// Optimize: use from cache to not re-calculate user properties over and over again
formattedName = userPropertiesCache.get(ident.getKey());
if (formattedName != null) {
return formattedName;
}
}
Translator trans = Util.createPackageTranslator(NotificationNewsController.class, I18nManager.getInstance().getLocaleOrDefault(ident.getUser().getPreferences().getLanguage()));
User user = ident.getUser();
if (user == null) {
formattedName = trans.translate("user.unknown");
} else {
// grap user properties from context
List<UserPropertyHandler> propertyHandlers = UserManager.getInstance().getUserPropertyHandlersFor(NotificationHelper.class.getName(), false);
String[] properties = new String[propertyHandlers.size()];
for (int i = 0; i < propertyHandlers.size(); i++) {
UserPropertyHandler propHandler = propertyHandlers.get(i);
String prop = propHandler.getUserProperty(user, trans.getLocale());
if (StringHelper.containsNonWhitespace(prop)) {
properties[i] = prop;
} else {
properties[i] = "-";
}
}
formattedName = trans.translate("user.formatted", properties);
}
// put formatted name in cache, times out after 5 mins
userPropertiesCache.put(ident.getKey(), formattedName);
return formattedName;
}
use of org.olat.core.id.User in project openolat by klemens.
the class EvalUserPropertyFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
public Object call(Object[] inStack) {
/*
* argument check
*/
if (inStack.length > 2) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.providetwo.attrvalue"));
} else if (inStack.length < 2) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.providetwo.attrvalue"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String)) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attributename", "solution.example.name.infunction"));
}
if (!(inStack[1] instanceof String)) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attribvalue", "solution.example.name.infunction"));
} else {
String propValue = (String) inStack[1];
if (!StringHelper.containsNonWhitespace(propValue)) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attribvalue", "solution.example.whiteSpace"));
}
}
/*
* check reference integrity
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
// return a valid value to continue with condition evaluation test
return defaultValue();
}
/*
* the real function evaluation which is used during run time
*/
String propName = (String) inStack[0];
String searchValue = (String) inStack[1];
Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
if (ident == null) {
return defaultValue();
}
User user = ident.getUser();
String userValue = user.getPropertyOrIdentityEnvAttribute(propName, null);
boolean match = false;
boolean debug = log.isDebug();
if (debug) {
log.debug("value : " + userValue);
log.debug("searchValue: " + searchValue);
log.debug("fT : " + functionType);
}
if (StringHelper.containsNonWhitespace(userValue)) {
match = checkPropertyValue(searchValue, userValue);
}
if (debug) {
log.debug("identity '" + ident.getName() + "' tested on properties '" + propName + "' to have value '" + searchValue + "' user's value was '" + userValue + "', match=" + match);
}
return match ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
use of org.olat.core.id.User in project openolat by klemens.
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 klemens.
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);
}
use of org.olat.core.id.User in project openolat by klemens.
the class CoachingDAOTest method getUsers.
@Test
public void getUsers() throws URISyntaxException {
URL coachingCourseUrl = CoachingLargeTest.class.getResource("CoachingCourse.zip");
File coachingCourseFile = new File(coachingCourseUrl.toURI());
RepositoryEntry re1 = CourseFactory.deployCourseFromZIP(coachingCourseFile, UUID.randomUUID().toString(), 4);
RepositoryEntry re2 = CourseFactory.deployCourseFromZIP(coachingCourseFile, UUID.randomUUID().toString(), 4);
RepositoryEntry re3 = CourseFactory.deployCourseFromZIP(coachingCourseFile, UUID.randomUUID().toString(), 4);
dbInstance.commitAndCloseSession();
// members of courses
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("User-Part-1");
repositoryService.addRole(participant, re1, GroupRoles.participant.name());
repositoryService.addRole(participant, re2, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// groups
BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "Coaching-grp-1", "tg", null, null, false, false, re2);
businessGroupRelationDao.addRole(participant, group2, GroupRoles.participant.name());
BusinessGroup group3 = businessGroupService.createBusinessGroup(null, "Coaching-grp-1", "tg", null, null, false, false, re3);
businessGroupRelationDao.addRole(participant, group3, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// make statements participant 1
effManager.createUserEfficiencyStatement(new Date(), 6.0f, true, participant, re1.getOlatResource());
effManager.createUserEfficiencyStatement(new Date(), 4.0f, false, participant, re2.getOlatResource());
effManager.createUserEfficiencyStatement(new Date(), 2.0f, false, participant, re3.getOlatResource());
dbInstance.commitAndCloseSession();
// make user infos
userCourseInformationsManager.updateUserCourseInformations(re1.getOlatResource(), participant);
userCourseInformationsManager.updateUserCourseInformations(re2.getOlatResource(), participant);
userCourseInformationsManager.updateUserCourseInformations(re3.getOlatResource(), participant);
dbInstance.commitAndCloseSession();
// update props
User partUser = participant.getUser();
partUser.setProperty(UserConstants.FIRSTNAME, "Rei");
partUser.setProperty(UserConstants.LASTNAME, "Ayanami");
partUser.setProperty(UserConstants.EMAIL, "rei.ayanami@openolat.com");
partUser = userManager.updateUser(partUser);
dbInstance.commitAndCloseSession();
List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(UserListController.usageIdentifyer, false);
// search by first name
SearchCoachedIdentityParams params = new SearchCoachedIdentityParams();
Map<String, String> props = new HashMap<>();
props.put(UserConstants.FIRSTNAME, "re");
params.setUserProperties(props);
List<StudentStatEntry> stats = coachingDAO.getUsersStatisticsNative(params, userPropertyHandlers);
Assert.assertNotNull(stats);
Assert.assertFalse(stats.isEmpty());
// check participant
StudentStatEntry entryStat = getStudentStatEntry(participant, stats);
Assert.assertNotNull(entryStat);
Assert.assertEquals(3, entryStat.getCountRepo());
Assert.assertEquals(3, entryStat.getInitialLaunch());
Assert.assertEquals(1, entryStat.getCountPassed());
Assert.assertEquals(2, entryStat.getCountFailed());
Assert.assertEquals(0, entryStat.getCountNotAttempted());
// search by user name
SearchCoachedIdentityParams loginParams = new SearchCoachedIdentityParams();
loginParams.setLogin(participant.getName());
List<StudentStatEntry> loginStats = coachingDAO.getUsersStatisticsNative(loginParams, userPropertyHandlers);
Assert.assertNotNull(loginStats);
Assert.assertEquals(1, loginStats.size());
// check participant
StudentStatEntry loginStat = loginStats.get(0);
Assert.assertNotNull(loginStat);
Assert.assertEquals(3, loginStat.getCountRepo());
Assert.assertEquals(3, loginStat.getInitialLaunch());
Assert.assertEquals(1, loginStat.getCountPassed());
Assert.assertEquals(2, loginStat.getCountFailed());
Assert.assertEquals(0, loginStat.getCountNotAttempted());
}
Aggregations