use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.
the class MCRUploadViaFormServlet method handleUploadedFiles.
private void handleUploadedFiles(MCRUploadHandler handler, Collection<Part> files) throws Exception {
int numFiles = (int) files.stream().map(Part::getSubmittedFileName).filter(Objects::nonNull).count();
LOGGER.info("UploadHandler uploading {} file(s)", numFiles);
handler.startUpload(numFiles);
MCRSession session = MCRSessionMgr.getCurrentSession();
session.commitTransaction();
for (Part file : files) {
try {
handleUploadedFile(handler, file);
} finally {
file.delete();
}
}
session.beginTransaction();
}
use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.
the class MCRContainerLoginFormServlet method think.
/* (non-Javadoc)
* @see org.mycore.frontend.servlets.MCRServlet#think(org.mycore.frontend.servlets.MCRServletJob)
*/
@Override
protected void think(MCRServletJob job) throws Exception {
MCRSession mcrSession = MCRSessionMgr.getCurrentSession();
MCRUserInformation userInformation = mcrSession.getUserInformation();
MCRLogin login = new MCRLogin(userInformation, getFormAction());
login.getForm().getInput().addAll(Arrays.asList(getUserNameField(), getPasswordField()));
job.getRequest().setAttribute(LOGIN_ATTR, new MCRJAXBContent<>(MCRLogin.getContext(), login));
}
use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.
the class MCRLockServlet method render.
@Override
protected void render(MCRServletJob job, Exception ex) throws Exception {
if (job.getResponse().isCommitted()) {
LOGGER.info("Response allready committed");
return;
}
if (ex != null) {
throw ex;
}
HttpServletRequest req = job.getRequest();
MCRObjectID objectId = (MCRObjectID) job.getRequest().getAttribute(OBJECT_ID_KEY);
Action action = (Action) job.getRequest().getAttribute(ACTION_KEY);
MCRSession lockingSession = MCRObjectIDLockTable.getLocker(objectId);
if (MCRObjectIDLockTable.isLockedByCurrentSession(objectId) || action == Action.unlock) {
String url = getProperty(job.getRequest(), PARAM_REDIRECT);
if (url.startsWith("/")) {
url = req.getContextPath() + url;
}
url = addQueryParameter(url, req);
job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(url));
} else {
String errorI18N = getErrorI18N("error", "lockedBy", objectId.toString(), lockingSession.getUserInformation().getUserID());
job.getResponse().sendError(HttpServletResponse.SC_CONFLICT, errorI18N);
}
}
use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.
the class MCRServlet method configureSession.
private void configureSession(MCRServletJob job) {
MCRSession session = MCRSessionMgr.getCurrentSession();
String c = getClass().getName();
c = c.substring(c.lastIndexOf(".") + 1);
String msg = c + " ip=" + MCRFrontendUtil.getRemoteAddr(job.getRequest()) + " mcr=" + session.getID() + " user=" + session.getUserInformation().getUserID();
LOGGER.info(msg);
MCRFrontendUtil.configureSession(session, job.getRequest(), job.getResponse());
}
use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.
the class MCRServlet method processThinkPhase.
private Exception processThinkPhase(MCRServletJob job) {
MCRSession session = MCRSessionMgr.getCurrentSession();
try {
if (getProperty(job.getRequest(), INITIAL_SERVLET_NAME_KEY).equals(getServletName())) {
// current Servlet not called via RequestDispatcher
session.beginTransaction();
}
configureSession(job);
think(job);
if (getProperty(job.getRequest(), INITIAL_SERVLET_NAME_KEY).equals(getServletName())) {
// current Servlet not called via RequestDispatcher
session.commitTransaction();
}
} catch (Exception ex) {
if (getProperty(job.getRequest(), INITIAL_SERVLET_NAME_KEY).equals(getServletName())) {
// current Servlet not called via RequestDispatcher
LOGGER.warn("Exception occurred, performing database rollback.");
session.rollbackTransaction();
} else {
LOGGER.warn("Exception occurred, cannot rollback database transaction right now.");
}
return ex;
}
return null;
}
Aggregations