public SandBox resolveSandBox(WebRequest request, Site site) {
Long previousSandBoxId = null;
if (BLCRequestUtils.isOKtoUseSession(request)) {
previousSandBoxId = (Long) request.getAttribute(SANDBOX_ID_VAR, WebRequest.SCOPE_GLOBAL_SESSION);
}
SandBox currentSandbox = null;
if (!sandBoxPreviewEnabled) {
if (LOG.isTraceEnabled()) {
LOG.trace("Sandbox preview disabled. Setting sandbox to production");
}
request.setAttribute(SANDBOX_VAR, currentSandbox, WebRequest.SCOPE_REQUEST);
} else if (crossAppAuthService != null && !crossAppAuthService.isAuthedFromAdmin()) {
if (LOG.isInfoEnabled()) {
LOG.info("Sandbox preview attempted without authentication");
}
request.setAttribute(SANDBOX_VAR, currentSandbox, WebRequest.SCOPE_REQUEST);
} else if (crossAppAuthService != null && crossAppAuthService.hasCsrPermission()) {
if (LOG.isInfoEnabled()) {
LOG.info("Sandbox preview attempted in CSR mode");
}
request.setAttribute(SANDBOX_VAR, currentSandbox, WebRequest.SCOPE_REQUEST);
} else {
Long sandboxId = null;
// Clear the sandBox - second parameter is to support legacy implementations.
if ((request.getParameter("blClearSandBox") == null) && (request.getParameter("blSandboxDateTimeRibbonProduction") == null)) {
sandboxId = lookupSandboxId(request);
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("Removing sandbox from session.");
}
if (BLCRequestUtils.isOKtoUseSession(request)) {
request.removeAttribute(SANDBOX_DATE_TIME_VAR, WebRequest.SCOPE_GLOBAL_SESSION);
request.removeAttribute(SANDBOX_ID_VAR, WebRequest.SCOPE_GLOBAL_SESSION);
}
}
if (sandboxId != null) {
if (previousSandBoxId != null && !previousSandBoxId.equals(sandboxId)) {
request.setAttribute(BroadleafRequestProcessor.REPROCESS_PARAM_NAME, true, WebRequest.SCOPE_REQUEST);
}
currentSandbox = sandBoxDao.retrieve(sandboxId);
request.setAttribute(SANDBOX_VAR, currentSandbox, WebRequest.SCOPE_REQUEST);
if (currentSandbox != null && !SandBoxType.PRODUCTION.equals(currentSandbox.getSandBoxType())) {
setContentTime(request);
}
}
// if (currentSandbox == null && site != null) {