Search in sources :

Example 1 with HostPageModel

use of org.activityinfo.server.login.model.HostPageModel in project activityinfo by bedatadriven.

the class HostController method getHostPage.

@GET
@Produces(MediaType.TEXT_HTML)
public Response getHostPage(@Context UriInfo uri, @Context HttpServletRequest req, @QueryParam("redirect") boolean redirect, @QueryParam("ui") String ui, @QueryParam("locale") String locale, @QueryParam("logging") String logging, @QueryParam("gwt.codesvr") String codeServer) throws Exception {
    if (!authProvider.isAuthenticated()) {
        // Otherwise, go to the default ActivityInfo root page
        return Response.temporaryRedirect(uri.getAbsolutePathBuilder().replacePath("/login").build()).build();
    }
    if (redirect) {
        return Response.seeOther(uri.getAbsolutePathBuilder().replacePath(ENDPOINT).build()).build();
    }
    String appUri = uri.getAbsolutePathBuilder().replaceQuery("").build().toString();
    HostPageModel model = new HostPageModel(appUri);
    User authenticatedUser = entityManager.get().find(User.class, authProvider.get().getUserId());
    model.setFeatureFlags(authenticatedUser.getFeatures());
    model.setNewUI("3".equals(ui) || "3dev".equals(ui));
    if ("3dev".equals(ui)) {
        model.setBootstrapScript("/App/App.nocache.js");
    } else if ("dev".equals(ui)) {
        // Running in development mode
        // Use the default bootstrap script
        model.setBootstrapScript("/ActivityInfo/ActivityInfo.nocache.js");
    } else if ("true".equalsIgnoreCase(logging)) {
        // Load a special logging version of the Application
        model.setBootstrapScript("/ActivityInfoLogging/ActivityInfoLogging.nocache.js");
    } else {
        // locale or the one explicitly provided
        if (Strings.isNullOrEmpty(locale)) {
            locale = authProvider.get().getUserLocale();
        }
        String module;
        if (model.isNewUI()) {
            module = "App";
        } else {
            module = "ActivityInfo";
        }
        model.setBootstrapScript(String.format("/%s/%s.js", module, locale));
        model.setAppCacheManifest(String.format("/%s/%s.appcache", module, locale));
    }
    return Response.ok(model.asViewable()).type(MediaType.TEXT_HTML).cacheControl(CacheControl.valueOf("no-cache")).build();
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) HostPageModel(org.activityinfo.server.login.model.HostPageModel) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with HostPageModel

use of org.activityinfo.server.login.model.HostPageModel in project activityinfo by bedatadriven.

the class HostViewTest method templateProcesses.

@Test
public void templateProcesses() {
    User user = new User();
    user.setName("Alex");
    user.setEmail("akbertram@gmail.com");
    user.setLocale("fr");
    Authentication auth = new Authentication(user);
    auth.setId("XYZ12345");
    auth.setUser(user);
    HostPageModel pageModel = new HostPageModel("http://www.activityinfo.org");
    pageModel.setBootstrapScript("/ActivityInfo/en.js");
    assertProcessable(pageModel);
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) Authentication(org.activityinfo.server.database.hibernate.entity.Authentication) HostPageModel(org.activityinfo.server.login.model.HostPageModel) Test(org.junit.Test)

Aggregations

User (org.activityinfo.server.database.hibernate.entity.User)2 HostPageModel (org.activityinfo.server.login.model.HostPageModel)2 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Authentication (org.activityinfo.server.database.hibernate.entity.Authentication)1 Test (org.junit.Test)1