use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class BCWebService method getFolder.
/**
* Retrieves metadata of the course node
* @response.representation.200.qname {http://www.example.com}folderVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node metadatas
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_FOLDERVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or parentNode not found
* @param courseId The course resourceable's id
* @param nodeId The node's id
* @param httpRequest The HTTP request
* @return The persisted structure element (fully populated)
*/
@GET
@Path("{nodeId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getFolder(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest httpRequest) {
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CourseNode courseNode = course.getRunStructure().getNode(nodeId);
if (courseNode == null || !(courseNode instanceof BCCourseNode)) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
UserRequest ureq = getUserRequest(httpRequest);
boolean accessible = (new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment())).isAccessible(courseNode, new VisibleTreeFilter());
if (accessible) {
Set<String> subscribed = new HashSet<String>();
NotificationsManager man = NotificationsManager.getInstance();
List<String> notiTypes = Collections.singletonList("FolderModule");
List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
for (Subscriber sub : subs) {
Long courseKey = sub.getPublisher().getResId();
if (courseId.equals(courseKey)) {
subscribed.add(sub.getPublisher().getSubidentifier());
}
}
FolderVO folderVo = createFolderVO(ureq.getUserSession().getIdentityEnvironment(), course, (BCCourseNode) courseNode, subscribed);
return Response.ok(folderVo).build();
} else {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class QuestionListController method doOpenExcelImportQTI21.
private void doOpenExcelImportQTI21(UserRequest ureq) {
removeAsListenerAndDispose(excelImportWizard);
Step additionalStep = null;
if (getSource().askEditable()) {
additionalStep = new EditableStep(ureq);
}
final AssessmentItemsPackage importPackage = new AssessmentItemsPackage();
final ImportOptions options = new ImportOptions();
options.setShuffle(true);
Step start = new QImport_1_InputStep(ureq, importPackage, options, additionalStep);
StepRunnerCallback finish = new StepRunnerCallback() {
@Override
public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
QTI21QPoolServiceProvider spi = CoreSpringFactory.getImpl(QTI21QPoolServiceProvider.class);
List<AssessmentItemAndMetadata> items = importPackage.getItems();
List<QuestionItem> importItems = new ArrayList<>();
for (AssessmentItemAndMetadata item : items) {
QuestionItem importedItem = spi.importExcelItem(getIdentity(), item, getLocale());
if (importedItem != null) {
importItems.add(importedItem);
}
}
for (QuestionItem item : importItems) {
QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_BY_IMPORT);
builder.withAfter(item);
qpoolService.persist(builder.create());
}
boolean editable = true;
if (getSource().askEditable()) {
Object editableCtx = runContext.get("editable");
editable = (editableCtx instanceof Boolean) ? ((Boolean) editableCtx).booleanValue() : false;
}
qpoolService.index(importItems);
int postImported = getSource().postImport(importItems, editable);
if (postImported > 0) {
getItemsTable().reset();
}
return StepsMainRunController.DONE_MODIFIED;
}
};
excelImportWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("import.excellike.21"), "o_sel_qpool_excel_import_wizard");
listenTo(excelImportWizard);
getWindowControl().pushAsModalDialog(excelImportWizard.getInitialComponent());
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class QuestionListController method doExport.
private void doExport(UserRequest ureq, List<QuestionItemShort> items) {
removeAsListenerAndDispose(exportWizard);
Step start = new Export_1_TypeStep(ureq, items);
StepRunnerCallback finish = new StepRunnerCallback() {
@Override
public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
return StepsMainRunController.DONE_MODIFIED;
}
};
exportWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("export.item"), "o_sel_qpool_export_1_wizard");
listenTo(exportWizard);
getWindowControl().pushAsModalDialog(exportWizard.getInitialComponent());
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class RepositoryMembersController method doImportMembers.
private void doImportMembers(UserRequest ureq) {
removeAsListenerAndDispose(importMembersWizard);
Step start = new ImportMember_1a_LoginListStep(ureq, repoEntry, null, false);
StepRunnerCallback finish = new StepRunnerCallback() {
@Override
public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
addMembers(uureq, runContext);
if (runContext.containsKey("notFounds")) {
showWarning("user.notfound", runContext.get("notFounds").toString());
}
return StepsMainRunController.DONE_MODIFIED;
}
};
importMembersWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("import.member"), "o_sel_group_import_logins_wizard");
listenTo(importMembersWizard);
getWindowControl().pushAsModalDialog(importMembersWizard.getInitialComponent());
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class AuthenticatedDispatcher method execute.
/**
* Main method called by OpenOLATServlet. This processess all requests for
* authenticated users.
*
* @param request
* @param response
* @param uriPrefix
*/
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
String uriPrefix = DispatcherModule.getLegacyUriPrefix(request);
UserSession usess = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSession(request);
UserRequest ureq = null;
try {
// upon creation URL is checked for
ureq = new UserRequestImpl(uriPrefix, request, response);
} catch (NumberFormatException nfe) {
// a 404 message must be shown -> e.g. robots correct their links.
if (log.isDebug()) {
log.debug("Bad Request " + request.getPathInfo());
}
}
boolean auth = usess.isAuthenticated();
if (!auth) {
String guestAccess = ureq.getParameter(GUEST);
if (guestAccess == null || !CoreSpringFactory.getImpl(LoginModule.class).isGuestLoginEnabled()) {
String businessPath = extractBusinessPath(ureq, request, uriPrefix);
if (businessPath != null) {
usess.putEntryInNonClearedStore(AUTHDISPATCHER_BUSINESSPATH, businessPath);
}
redirectToDefaultDispatcher(request, response);
return;
} else if (guestAccess.equals(TRUE)) {
// try to log in as anonymous
// use the language from the lang parameter if available, otherwise use the system default locale
String guestLang = ureq.getParameter("language");
if (guestLang == null) {
// support for legacy lang parameter
guestLang = ureq.getParameter("lang");
}
Locale guestLoc;
if (guestLang == null) {
guestLoc = I18nModule.getDefaultLocale();
} else {
guestLoc = I18nManager.getInstance().getLocaleOrDefault(guestLang);
}
int loginStatus = AuthHelper.doAnonymousLogin(ureq, guestLoc);
if (loginStatus != AuthHelper.LOGIN_OK) {
if (loginStatus == AuthHelper.LOGIN_NOTAVAILABLE) {
DispatcherModule.redirectToServiceNotAvailable(response);
}
// error, redirect to login screen
redirectToDefaultDispatcher(request, response);
return;
}
// else now logged in as anonymous user, continue
}
}
// authenticated!
try {
// kill session if not secured via SSL
if (forceSecureAccessOnly && !request.isSecure()) {
SessionInfo sessionInfo = usess.getSessionInfo();
if (sessionInfo != null) {
HttpSession session = sessionInfo.getSession();
if (session != null) {
try {
session.invalidate();
} catch (IllegalStateException ise) {
// thrown when session already invalidated. fine. ignore.
}
}
}
redirectToDefaultDispatcher(request, response);
return;
}
SessionInfo sessionInfo = usess.getSessionInfo();
if (sessionInfo == null) {
redirectToDefaultDispatcher(request, response);
return;
}
if (userBasedLogLevelManager != null) {
userBasedLogLevelManager.activateUsernameBasedLogLevel(sessionInfo.getLogin());
}
sessionInfo.setLastClickTime();
String businessPath = (String) usess.removeEntryFromNonClearedStore(AUTHDISPATCHER_BUSINESSPATH);
if (businessPath != null) {
processBusinessPath(businessPath, ureq, usess);
} else if (ureq.isValidDispatchURI()) {
// valid uri for dispatching (has timestamp, componentid and windowid)
processValidDispatchURI(ureq, usess, request, response);
} else {
businessPath = extractBusinessPath(ureq, request, uriPrefix);
if (businessPath == null) {
processBusinessPath("", ureq, usess);
} else {
processBusinessPath(businessPath, ureq, usess);
}
}
} catch (InvalidRequestParameterException e) {
try {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
} catch (IOException e1) {
log.error("An exception occured while handling the invalid request parameter exception...", e1);
}
} catch (Throwable th) {
// Do not log as Warn or Error here, log as ERROR in MsgFactory => ExceptionWindowController throws an OLATRuntimeException
log.debug("handleError in AuthenticatedDispatcher throwable=" + th);
DispatcherModule.handleError();
ChiefController msgcc = MsgFactory.createMessageChiefController(ureq, th);
// the controller's window must be failsafe also
msgcc.getWindow().dispatchRequest(ureq, true);
// do not dispatch (render only), since this is a new Window created as
// a result of another window's click.
} finally {
if (userBasedLogLevelManager != null) {
userBasedLogLevelManager.deactivateUsernameBasedLogLevel();
}
}
}
Aggregations