Search in sources :

Example 1 with PortalSession

use of au.org.emii.portal.session.PortalSession in project spatial-portal by AtlasOfLivingAustralia.

the class PortalSessionCloner method clone.

public PortalSession clone(PortalSession masterPortalSession) throws CloneNotSupportedException {
    PortalSession portalSession = (PortalSession) masterPortalSession.copy();
    /* super.clone will leave references to existing objects
         * in place, e.g.  portalSession.mapLayers == mapLayers is
         * currently true - to fix this, we will re-init all these
         * fields now
         *
         * although we don't mind sharing these between users, they
         * have to be defined 'later' when we call clone() because
         * the config file has not yet been loaded if we try earlier
         */
    portalSession.reset();
    // maplayers
    if (masterPortalSession.getMapLayers() != null) {
        for (MapLayer mapLayer : masterPortalSession.getMapLayers()) {
            portalSession.addMapLayer((MapLayer) mapLayer.clone());
        }
    }
    // default map bounding box
    if (masterPortalSession.getDefaultBoundingBox() != null) {
        portalSession.setDefaultBoundingbox((BoundingBox) masterPortalSession.getDefaultBoundingBox().copy());
    }
    // step 4: clone active layers
    if (masterPortalSession.getActiveLayers() != null) {
        for (MapLayer mapLayer : masterPortalSession.getActiveLayers()) {
            portalSession.getActiveLayers().add((MapLayer) mapLayer.clone());
        }
    }
    /* step 5: skip things
         *
         * o userDefined
         * o UserDefinedMenu
         * All get skipped because for new sessions they should
         * all be empty lists/objects
         */
    /* step 6: create an initial user defined menu tree - isn't done on creating
         * during stage 2 because otherwise we would have to bother cloning everything
         */
    LOGGER.debug("Session cloned");
    return portalSession;
}
Also used : PortalSession(au.org.emii.portal.session.PortalSession) MapLayer(au.org.emii.portal.menu.MapLayer)

Example 2 with PortalSession

use of au.org.emii.portal.session.PortalSession in project spatial-portal by AtlasOfLivingAustralia.

the class SessionInitImpl method init.

@Override
public void init(Desktop desktop, Object request) throws Exception {
    LOGGER.debug("* INIT Desktop");
    Session session = desktop.getSession();
    if (session == null) {
        LOGGER.debug("user has a null session - no idea why (system coming up/going down - " + "concurrency ?) will redirect to error page");
        redirectAndInvalidateSession(desktop.getSession(), ERROR_PAGE);
    } else {
        // user has a session...
        // Sesssion is OK - do things we want to do before we start
        // composing the page
        PortalSession portalSession = (PortalSession) session.getAttribute(PORTAL_SESSION_ATTRIBUTE);
        if (portalSession == null) {
            init(session, null);
            portalSession = (PortalSession) session.getAttribute(PORTAL_SESSION_ATTRIBUTE);
        }
        PortalSessionUtilities portalSessionUtilities = getPortalSessionUtilities(session);
        OpenLayersJavascript openLayersJavascript = getApplicationContext(session).getBean(OpenLayersJavascript.class);
        String script = openLayersJavascript.initialiseMap(portalSessionUtilities.getCurrentBoundingBox(portalSession)) + openLayersJavascript.getIFrameReferences() + openLayersJavascript.setBaseLayer(portalSession.getBaseLayer()) + openLayersJavascript.activateMapLayers(portalSession.getActiveLayers());
        // remove all whitespace
        script = openLayersJavascript.minify(script);
        portalSession.setOnIframeMapFullyLoaded(script);
        LOGGER.debug("onIframeMapFullyLoaded set to: " + script);
    }
    LOGGER.debug("...session init complete");
}
Also used : OpenLayersJavascript(au.org.emii.portal.javascript.OpenLayersJavascript) PortalSession(au.org.emii.portal.session.PortalSession) PortalSessionUtilities(au.org.emii.portal.util.PortalSessionUtilities) HttpSession(javax.servlet.http.HttpSession) PortalSession(au.org.emii.portal.session.PortalSession) Session(org.zkoss.zk.ui.Session)

Example 3 with PortalSession

use of au.org.emii.portal.session.PortalSession in project spatial-portal by AtlasOfLivingAustralia.

the class SessionInitImpl method init.

@Override
public void init(Session session, Object request) throws Exception {
    LOGGER.debug("* SESSION INIT:");
    // obtain stage1 loader - check for errors
    ConfigurationLoaderStage1Impl stage1 = getConfigurationLoaderStage1(session);
    // wait for portal to finish if its reloading
    waitForPortalReload(stage1, session);
    /*if (stage1.isReloading()) {
            // portal is taking too long to load - MAX_TIME_RELOADING_SECONDS exceeded!
            redirectAndInvalidateSession(session, "/WEB-INF/jsp/Reloading.jsp");

        } else*/
    if (stage1.isError()) {
        // portal reloaded but has errors
        redirectAndInvalidateSession(session, ERROR_PAGE);
    } else {
        // see if there is a master session
        PortalSession masterPortalSession = getMasterPortalSession(session);
        if (masterPortalSession == null) {
            // hmm master portal session never got created - don't know why, check
            // output for previous errors
            LOGGER.error("masterPortalSession is null - redirecting user to error page");
            // redirect to error page - nothing we can do and portal doesn't look to
            // be coming up any time soon
            redirectAndInvalidateSession(session, ERROR_PAGE);
        } else {
            // all good :-D
            // deep copy of PortalSession - otherwise you will be sharing state with everybody
            // after cloning, save a the independent clone in SESSION scope
            PortalSessionCloner cloner = getPortalSessionCloner(session);
            PortalSession portalSession = cloner.clone(masterPortalSession);
            session.setAttribute(PORTAL_SESSION_ATTRIBUTE, portalSession);
            LOGGER.debug("* SESSION INIT OK");
        }
    }
}
Also used : PortalSession(au.org.emii.portal.session.PortalSession) PortalSessionCloner(au.org.emii.portal.util.PortalSessionCloner) ConfigurationLoaderStage1Impl(au.org.emii.portal.config.ConfigurationLoaderStage1Impl)

Example 4 with PortalSession

use of au.org.emii.portal.session.PortalSession in project spatial-portal by AtlasOfLivingAustralia.

the class ConfigurationLoaderStage2Impl method load.

@Override
public PortalSession load() {
    reloading = true;
    // protect against sticky error flag
    error = false;
    workingPortalSession = new PortalSession();
    // note - order is different to natural xml order due to dependencies
    // between stages, eg menu depends on datasource depends on uriresolver, etc
    settings();
    settingsSupplementary();
    finaliseSession();
    // If we were able to construct the working session with no errors,
    // return this to the user otherwise return null
    PortalSession masterPortalSession;
    if (error) {
        LOGGER.error("error constructing master portal session in stage 2 loader " + "- error flag got set, returning null PortalSession instance " + "and disabling portal");
        masterPortalSession = null;
    } else {
        // all good
        masterPortalSession = workingPortalSession;
    }
    // geoserver/alaspatial analysis page data
    CommonData.init(settingsSupplementary);
    cleanup();
    reloading = false;
    return masterPortalSession;
}
Also used : PortalSession(au.org.emii.portal.session.PortalSession)

Example 5 with PortalSession

use of au.org.emii.portal.session.PortalSession in project spatial-portal by AtlasOfLivingAustralia.

the class MapComposer method reloadPortal.

/**
 * split from button for yes/no event processing
 * <p/>
 * see onClick$reloadPortal()
 */
void reloadPortal() {
    // grab the portaluser instance so that logged in users stay logged in...
    PortalSession portalSession = getPortalSession();
    // remove the old species filters
    getSession().removeAttribute("speciesfilters");
    // create a new session from the master session
    SessionInit sessionInit = new SessionInitImpl();
    try {
        sessionInit.init(Sessions.getCurrent(), null);
    } catch (Exception ex) {
        LOGGER.error("Error creating replacement session information after user clicked reload portal", ex);
    }
    // check PortalSession is not null - if it is, something is badly wrong
    // so redirect to error page
    portalSession = getPortalSession();
    if (portalSession == null) {
        LOGGER.error("Null portal session created after clicking reset map, sending user to error page");
        try {
            Executions.getCurrent().forward("/WEB-INF/jsp/Error.jsp");
        } catch (IOException ex) {
            LOGGER.error("error redirecting to error page", ex);
        }
    } else {
        // all good - put the portal user back in, then force a page reload
        Executions.getCurrent().sendRedirect(CommonData.getWebportalServer() + "/");
    }
}
Also used : PortalSession(au.org.emii.portal.session.PortalSession) SessionInitImpl(au.org.emii.portal.web.SessionInitImpl) SessionInit(org.zkoss.zk.ui.util.SessionInit) ParseException(org.json.simple.parser.ParseException)

Aggregations

PortalSession (au.org.emii.portal.session.PortalSession)10 MapLayer (au.org.emii.portal.menu.MapLayer)4 HasMapLayer (au.org.emii.portal.menu.HasMapLayer)2 Checkbox (org.zkoss.zul.Checkbox)2 MapComposer (au.org.emii.portal.composer.MapComposer)1 ConfigurationLoaderStage1Impl (au.org.emii.portal.config.ConfigurationLoaderStage1Impl)1 OpenLayersJavascript (au.org.emii.portal.javascript.OpenLayersJavascript)1 PortalSessionCloner (au.org.emii.portal.util.PortalSessionCloner)1 PortalSessionUtilities (au.org.emii.portal.util.PortalSessionUtilities)1 SessionInitImpl (au.org.emii.portal.web.SessionInitImpl)1 Properties (java.util.Properties)1 HttpSession (javax.servlet.http.HttpSession)1 ParseException (org.json.simple.parser.ParseException)1 Session (org.zkoss.zk.ui.Session)1 SessionInit (org.zkoss.zk.ui.util.SessionInit)1 Listitem (org.zkoss.zul.Listitem)1