use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.
the class PFManagerTest method provideParticipantContainer.
@Test
public void provideParticipantContainer() {
// prepare
Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-15");
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(initialAuthor);
PFCourseNode pfNode = new PFCourseNode();
pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_COACHBOX, true);
pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_PARTICIPANTBOX, true);
// import "Demo course" into the bcroot_junittest
RepositoryEntry entry = JunitTestHelper.deployDemoCourse(initialAuthor);
Long resourceableId = entry.getOlatResource().getResourceableId();
ICourse course = CourseFactory.loadCourse(resourceableId);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
Identity check3 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-3");
repositoryEntryRelationDao.addRole(check3, entry, GroupRoles.participant.name());
VFSContainer vfsContainer = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, check3, false);
Assert.assertNotNull(vfsContainer);
Assert.assertTrue(vfsContainer.exists());
}
use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.
the class CourseAssessmentWebService method importTestItems.
private void importTestItems(ICourse course, String nodeKey, Identity identity, AssessableResultsVO resultsVO) {
try {
IQManager iqManager = CoreSpringFactory.getImpl(IQManager.class);
// load the course and the course node
CourseNode courseNode = getParentNode(course, nodeKey);
ModuleConfiguration modConfig = courseNode.getModuleConfiguration();
// check if the result set is already saved
QTIResultSet set = iqManager.getLastResultSet(identity, course.getResourceableId(), courseNode.getIdent());
if (set == null) {
String resourcePathInfo = course.getResourceableId() + File.separator + courseNode.getIdent();
// The use of these classes AssessmentInstance, AssessmentContext and
// Navigator
// allow the use of the persistence mechanism of OLAT without
// duplicating the code.
// The consequence is that we must loop on section and items and set the
// navigator on
// the right position before submitting the inputs.
AssessmentInstance ai = AssessmentFactory.createAssessmentInstance(identity, "", modConfig, false, course.getResourceableId(), courseNode.getIdent(), resourcePathInfo, null);
Navigator navigator = ai.getNavigator();
navigator.startAssessment();
// The type of the navigator depends on the setting of the course node
boolean perItem = (navigator instanceof MenuItemNavigator);
Map<String, ItemInput> datas = convertToHttpItemInput(resultsVO.getResults());
AssessmentContext ac = ai.getAssessmentContext();
int sectioncnt = ac.getSectionContextCount();
// loop on the sections
for (int i = 0; i < sectioncnt; i++) {
SectionContext sc = ac.getSectionContext(i);
navigator.goToSection(i);
ItemsInput iips = new ItemsInput();
int itemcnt = sc.getItemContextCount();
// loop on the items
for (int j = 0; j < itemcnt; j++) {
ItemContext it = sc.getItemContext(j);
if (datas.containsKey(it.getIdent())) {
if (perItem) {
// save the datas on a per item base
navigator.goToItem(i, j);
// the navigator can give informations on its current status
Info info = navigator.getInfo();
if (info.containsError()) {
// some items cannot processed twice
} else {
iips.addItemInput(datas.get(it.getIdent()));
navigator.submitItems(iips);
iips = new ItemsInput();
}
} else {
// put for a section
iips.addItemInput(datas.get(it.getIdent()));
}
}
}
if (!perItem) {
// save the inputs of the section. In a section based navigation,
// we must saved the inputs of the whole section at once
navigator.submitItems(iips);
}
}
navigator.submitAssessment();
// persist the QTIResultSet (o_qtiresultset and o_qtiresult) on the
// database
// TODO iqManager.persistResults(ai, course.getResourceableId(),
// courseNode.getIdent(), identity, "127.0.0.1");
// write the reporting file on the file system
// The path is <olatdata> / resreporting / <username> / Assessment /
// <assessId>.xml
// TODO Document docResReporting = iqManager.getResultsReporting(ai,
// identity, Locale.getDefault());
// TODO FilePersister.createResultsReporting(docResReporting, identity,
// ai.getFormattedType(), ai.getAssessID());
// prepare all instances needed to save the score at the course node
// level
CourseEnvironment cenv = course.getCourseEnvironment();
IdentityEnvironment identEnv = new IdentityEnvironment();
identEnv.setIdentity(identity);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identEnv, cenv);
// update scoring overview for the user in the current course
Float score = ac.getScore();
Boolean passed = ac.isPassed();
// perhaps don't pass this key directly
ScoreEvaluation sceval = new ScoreEvaluation(score, passed, passed, new Long(nodeKey));
AssessableCourseNode acn = (AssessableCourseNode) courseNode;
// assessment nodes are assessable
boolean incrementUserAttempts = true;
acn.updateUserScoreEvaluation(sceval, userCourseEnv, identity, incrementUserAttempts, Role.coach);
} else {
log.error("Result set already saved");
}
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.
the class CourseWebService method getCourseCalendarWebService.
@Path("calendar")
public CalWebService getCourseCalendarWebService(@Context HttpServletRequest request) {
CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class);
if (calendarModule.isEnabled() && (calendarModule.isEnableCourseToolCalendar() || calendarModule.isEnableCourseElementCalendar()) && course.getCourseConfig().isCalendarEnabled()) {
UserRequest ureq = getUserRequest(request);
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(ureq.getIdentity());
ienv.setRoles(ureq.getUserSession().getRoles());
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, userCourseEnv, null);
return new CalWebService(wrapper);
}
return null;
}
use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.
the class MembersAvatarDisplayRunController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
Comparator<Identity> idComparator = new IdentityComparator();
Collections.sort(owners, idComparator);
Collections.sort(coaches, idComparator);
Collections.sort(participants, idComparator);
Collections.sort(waiting, idComparator);
if (canEmail) {
allEmailLink = uifactory.addFormLink("email", "members.email.title", null, formLayout, Link.BUTTON);
allEmailLink.setIconLeftCSS("o_icon o_icon_mail");
}
IdentityEnvironment idEnv = ureq.getUserSession().getIdentityEnvironment();
Identity ownId = idEnv.getIdentity();
Roles roles = idEnv.getRoles();
if (editable && (roles.isOLATAdmin() || roles.isGroupManager() || owners.contains(ownId) || coaches.contains(ownId) || (canDownload && !waiting.contains(ownId)))) {
downloadLink = uifactory.addFormLink("download", "members.download", null, formLayout, Link.BUTTON);
downloadLink.setIconLeftCSS("o_icon o_icon_download");
if (formLayout instanceof FormLayoutContainer) {
printLink = LinkFactory.createButton("print", ((FormLayoutContainer) formLayout).getFormItemComponent(), this);
printLink.setIconLeftCSS("o_icon o_icon_print o_icon-lg");
printLink.setPopup(new LinkPopupSettings(700, 500, "print-members"));
((FormLayoutContainer) formLayout).getFormItemComponent().put("print", printLink);
}
}
Set<Long> duplicateCatcher = deduplicateList ? new HashSet<Long>() : null;
ownerList = initFormMemberList("owners", owners, duplicateCatcher, formLayout, canEmail);
coachList = initFormMemberList("coaches", coaches, duplicateCatcher, formLayout, canEmail);
participantList = initFormMemberList("participants", participants, duplicateCatcher, formLayout, canEmail);
waitingtList = initFormMemberList("waiting", waiting, duplicateCatcher, formLayout, canEmail);
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
layoutCont.contextPut("showOwners", showOwners);
layoutCont.contextPut("hasOwners", new Boolean(!ownerList.isEmpty()));
layoutCont.contextPut("showCoaches", showCoaches);
layoutCont.contextPut("hasCoaches", new Boolean(!coachList.isEmpty()));
layoutCont.contextPut("showParticipants", showParticipants);
layoutCont.contextPut("hasParticipants", new Boolean(!participantList.isEmpty()));
layoutCont.contextPut("showWaiting", showWaiting);
layoutCont.contextPut("hasWaiting", new Boolean(!waitingtList.isEmpty()));
}
}
use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.
the class UserCalendarWebService method getCalendar.
private KalendarRenderWrapper getCalendar(UserRequest ureq, String calendarId) {
int typeIndex = calendarId.indexOf('_');
if (typeIndex <= 0 || (typeIndex + 1 >= calendarId.length())) {
return null;
}
CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class);
if (!calendarModule.isEnabled()) {
return null;
}
String type = calendarId.substring(0, typeIndex);
String id = calendarId.substring(typeIndex + 1);
KalendarRenderWrapper wrapper = null;
if ("group".equals(type) && calendarModule.isEnableGroupCalendar()) {
Long groupId = Long.parseLong(id);
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
BusinessGroup group = bgs.loadBusinessGroup(groupId);
if (bgs.isIdentityInBusinessGroup(ureq.getIdentity(), group)) {
CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class);
wrapper = collaborationManager.getCalendar(group, ureq, false);
}
} else if ("course".equals(type) && (calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar())) {
Long courseId = Long.parseLong(id);
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(ureq.getIdentity());
ienv.setRoles(ureq.getUserSession().getRoles());
ICourse course = CourseFactory.loadCourse(courseId);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, userCourseEnv, null);
} else if ("user".equals(type) && calendarModule.isEnablePersonalCalendar()) {
if (id.equals(ureq.getIdentity().getName())) {
wrapper = getPersonalCalendar(ureq.getIdentity());
} else if (isAdmin(ureq.getHttpReq())) {
Identity identity = BaseSecurityManager.getInstance().findIdentityByName(id);
wrapper = getPersonalCalendar(identity);
}
}
return wrapper;
}
Aggregations