<commit_before>package controllers;

import static org.sagebionetworks.bridge.BridgeConstants.ASSETS_HOST;

import org.sagebionetworks.bridge.config.BridgeConfigFactory;
import org.sagebionetworks.bridge.exceptions.EntityNotFoundException;
import org.sagebionetworks.bridge.models.UserSession;
import org.sagebionetworks.bridge.models.UserSessionInfo;
import org.sagebionetworks.bridge.models.studies.Study;

import play.libs.Json;
import play.mvc.Result;

@org.springframework.stereotype.Controller
public class ApplicationController extends BaseController {

    private static final UserSession EMPTY_USER_SESSION = new UserSession();
    private static final String ASSETS_BUILD = "201501291830";

    public Result redirectToPublicApp() {
        return redirect("/");
    }

    public Result loadApp() throws Exception {
        return loadPublicApp();
    }

    public Result loadPublicApp() throws Exception {
        UserSessionInfo info = new UserSessionInfo(new UserSession());
        try {
            Study study = getStudy();
            if ("pd".equals(study.getIdentifier()) || "neurod".equals(study.getIdentifier()) || "parkinson".equals(study.getIdentifier())) {
                return ok(views.html.neurod.render(Json.toJson(info).toString(), ASSETS_HOST, ASSETS_BUILD));
            } else if ("api".equals(study.getIdentifier())) {
                return ok(views.html.api.render(Json.toJson(info).toString(), ASSETS_HOST, ASSETS_BUILD));
            }
            String apiHost = "api" + BridgeConfigFactory.getConfig().getStudyHostnamePostfix();
            return ok(views.html.nosite.render(study.getName(), apiHost));
        } catch(EntityNotFoundException e) {
            return ok(views.html.api.render(Json.toJson(info).toString(), ASSETS_HOST, ASSETS_BUILD));
        }
    }

    public Result loadConsent(String sessionToken) throws Exception {
        UserSession session = null;
        if (sessionToken != null) {
            session = cacheProvider.getUserSession(sessionToken);
        }
        if (session == null) {
            session = EMPTY_USER_SESSION;
        }
        UserSessionInfo info = new UserSessionInfo(session);
        return ok(views.html.consent.render(Json.toJson(info).toString(), ASSETS_HOST, ASSETS_BUILD));
    }

    public Result preflight(String all) {
        response().setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "https://" + ASSETS_HOST);
        response().setHeader(ACCESS_CONTROL_ALLOW_METHODS, "HEAD, GET, OPTIONS, POST, PUT, DELETE");
        response().setHeader(ACCESS_CONTROL_ALLOW_HEADERS, "*");
        return ok();
    }<commit_msg>Do not retrieve study from cache just to render the html pages<commit_after>package controllers;

import static org.sagebionetworks.bridge.BridgeConstants.ASSETS_HOST;

import org.sagebionetworks.bridge.config.BridgeConfigFactory;
import org.sagebionetworks.bridge.exceptions.EntityNotFoundException;
import org.sagebionetworks.bridge.models.UserSession;
import org.sagebionetworks.bridge.models.UserSessionInfo;
import org.sagebionetworks.bridge.models.studies.Study;

import play.libs.Json;
import play.mvc.Result;

@org.springframework.stereotype.Controller
public class ApplicationController extends BaseController {

    private static final UserSession EMPTY_USER_SESSION = new UserSession();
    private static final String ASSETS_BUILD = "201501291830";

    public Result redirectToPublicApp() {
        return redirect("/");
    }

    public Result loadApp() throws Exception {
        return loadPublicApp();
    }

    public Result loadPublicApp() throws Exception {
        UserSessionInfo info = new UserSessionInfo(new UserSession());
        try {
            // Study study = getStudy(); don't need the entire study, so don't get it
            String studyIdentifier = getStudyIdentifier();
            if ("parkinson".equals(studyIdentifier)) {
                return ok(views.html.neurod.render(Json.toJson(info).toString(), ASSETS_HOST, ASSETS_BUILD));
            } else if ("api".equals(studyIdentifier)) {
                return ok(views.html.api.render(Json.toJson(info).toString(), ASSETS_HOST, ASSETS_BUILD));
            }
            String apiHost = "api" + BridgeConfigFactory.getConfig().getStudyHostnamePostfix();
            return ok(views.html.nosite.render("Unknown study", apiHost));
        } catch(EntityNotFoundException e) {
            return ok(views.html.api.render(Json.toJson(info).toString(), ASSETS_HOST, ASSETS_BUILD));
        }
    }

    public Result loadConsent(String sessionToken) throws Exception {
        UserSession session = null;
        if (sessionToken != null) {
            session = cacheProvider.getUserSession(sessionToken);
        }
        if (session == null) {
            session = EMPTY_USER_SESSION;
        }
        UserSessionInfo info = new UserSessionInfo(session);
        return ok(views.html.consent.render(Json.toJson(info).toString(), ASSETS_HOST, ASSETS_BUILD));
    }

    public Result preflight(String all) {
        response().setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "https://" + ASSETS_HOST);
        response().setHeader(ACCESS_CONTROL_ALLOW_METHODS, "HEAD, GET, OPTIONS, POST, PUT, DELETE");
        response().setHeader(ACCESS_CONTROL_ALLOW_HEADERS, "*");
        return ok();
    }
{'fraction_non_alphanumeric': 0.10800604229607251, 'fraction_numerical': 0.004531722054380665, 'mean_word_length': 3.4437919463087248, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5617238', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1456, 'n_words': 294}