Search in sources :

Example 11 with MCRSession

use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.

the class MCRCommandLineInterface method processCommand.

/**
 * Processes a command entered by searching a matching command in the list
 * of known commands and executing its method.
 *
 * @param command
 *            The command string to be processed
 */
protected static void processCommand(String command) {
    MCRSession session = MCRSessionMgr.getSession(sessionId.get());
    MCRSessionMgr.setCurrentSession(session);
    try {
        session.beginTransaction();
        List<String> commandsReturned = knownCommands.invokeCommand(expandCommand(command));
        session.commitTransaction();
        addCommandsToQueue(commandsReturned);
    } catch (Exception ex) {
        MCRCLIExceptionHandler.handleException(ex);
        rollbackTransaction(session);
        if (SKIP_FAILED_COMMAND) {
            saveFailedCommand(command);
        } else {
            saveQueue(command);
            if (!interactiveMode) {
                System.exit(1);
            }
            commandQueue.clear();
        }
    } finally {
        MCRSessionMgr.releaseCurrentSession();
    }
}
Also used : MCRSession(org.mycore.common.MCRSession) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 12 with MCRSession

use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.

the class MCRCommandLineInterface method initSession.

private static void initSession() {
    MCRSession session = MCRSessionMgr.getCurrentSession();
    session.setCurrentIP("127.0.0.1");
    session.setUserInformation(MCRSystemUserInformation.getSuperUserInstance());
    MCRSessionMgr.setCurrentSession(session);
    sessionId.set(session.getID());
    MCRSessionMgr.releaseCurrentSession();
}
Also used : MCRSession(org.mycore.common.MCRSession)

Example 13 with MCRSession

use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.

the class MCRUploadHandlerManager method getHandler.

public static MCRUploadHandler getHandler(String uploadID) {
    long yesterday = System.currentTimeMillis() - 86400000;
    MCRUploadHandlerCacheEntry entry = HANDLERS.getIfUpToDate(uploadID, yesterday);
    if (entry == null)
        throw new MCRUsageException("Upload session " + uploadID + " timed out");
    String sessionID = entry.getSessionID();
    if (!sessionID.equals(MCRSessionMgr.getCurrentSessionID())) {
        MCRSession session = MCRSessionMgr.getSession(sessionID);
        if (session != null)
            MCRSessionMgr.setCurrentSession(session);
    }
    return entry.getUploadHandler();
}
Also used : MCRUsageException(org.mycore.common.MCRUsageException) MCRSession(org.mycore.common.MCRSession)

Example 14 with MCRSession

use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.

the class MCRSessionHookFilter method filter.

@Override
public void filter(ContainerRequestContext request) throws IOException {
    MCRSession session = MCRServlet.getSession(httpRequest);
    MCRSessionMgr.setCurrentSession(session);
    LOGGER.info(MessageFormat.format("{0} ip={1} mcr={2} user={3}", request.getUriInfo().getPath(), MCRFrontendUtil.getRemoteAddr(httpRequest), session.getID(), session.getUserInformation().getUserID()));
    MCRFrontendUtil.configureSession(session, httpRequest, httpResponse);
}
Also used : MCRSession(org.mycore.common.MCRSession)

Example 15 with MCRSession

use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.

the class MCRFrontendUtil method getBaseURL.

/**
 * returns the base URL of the mycore system
 */
public static String getBaseURL() {
    if (MCRSessionMgr.hasCurrentSession()) {
        MCRSession session = MCRSessionMgr.getCurrentSession();
        Object value = session.get(BASE_URL_ATTRIBUTE);
        if (value != null) {
            LOGGER.debug("Returning BaseURL {} from user session.", value);
            return value.toString();
        }
    }
    return BASE_URL;
}
Also used : MCRSession(org.mycore.common.MCRSession)

Aggregations

MCRSession (org.mycore.common.MCRSession)63 IOException (java.io.IOException)15 MCRUserInformation (org.mycore.common.MCRUserInformation)10 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)10 MCRPath (org.mycore.datamodel.niofs.MCRPath)6 SignedJWT (com.nimbusds.jwt.SignedJWT)5 Date (java.util.Date)5 EntityManager (javax.persistence.EntityManager)5 Path (java.nio.file.Path)4 Response (javax.ws.rs.core.Response)4 Test (org.junit.Test)4 MCRRestAPIException (org.mycore.restapi.v1.errors.MCRRestAPIException)4 SAXException (org.xml.sax.SAXException)4 UnknownHostException (java.net.UnknownHostException)3 Document (org.jdom2.Document)3 MCRAccessException (org.mycore.access.MCRAccessException)3 MCRException (org.mycore.common.MCRException)3 MCRPersistenceException (org.mycore.common.MCRPersistenceException)3 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)3 MCRRestAPIError (org.mycore.restapi.v1.errors.MCRRestAPIError)3