Search in sources :

Example 1 with FreemarkerTemplate

use of org.molgenis.core.ui.data.system.core.FreemarkerTemplate in project molgenis by molgenis.

the class AppsController method viewApp.

@GetMapping(value = "/{appId}/**")
public String viewApp(@PathVariable("appId") String appId, Model model, HttpServletResponse response) {
    App app = dataService.findOneById(APP, appId, App.class);
    if (app == null) {
        model.addAttribute("errorMessage", format("Unknown app '%s'", appId));
        response.setStatus(SC_BAD_REQUEST);
        return "forward:" + URI;
    }
    if (!app.isActive()) {
        model.addAttribute("errorMessage", format("App '%s' is deactivated", app.getName()));
        response.setStatus(SC_BAD_REQUEST);
        return "forward:" + URI;
    }
    model.addAttribute("app", toAppInfoDto(app));
    if (app.getUseFreemarkerTemplate()) {
        FreemarkerTemplate htmlTemplate = app.getHtmlTemplate();
        return htmlTemplate.getNameWithoutExtension();
    } else {
        return "redirect:/" + FILE_STORE_PLUGIN_APPS_PATH + "/" + app.getId() + "/index.html";
    }
}
Also used : App(org.molgenis.apps.model.App) FreemarkerTemplate(org.molgenis.core.ui.data.system.core.FreemarkerTemplate)

Example 2 with FreemarkerTemplate

use of org.molgenis.core.ui.data.system.core.FreemarkerTemplate in project molgenis by molgenis.

the class AppsControllerTest method testViewAppWithFreeMarkerTemplate.

@Test
public void testViewAppWithFreeMarkerTemplate() throws Exception {
    App app = mock(App.class);
    when(app.getId()).thenReturn("id");
    when(app.getUseFreemarkerTemplate()).thenReturn(true);
    when(app.getName()).thenReturn("name");
    when(app.isActive()).thenReturn(true);
    FreemarkerTemplate htmlTemplate = mock(FreemarkerTemplate.class);
    when(htmlTemplate.getNameWithoutExtension()).thenReturn("html");
    when(app.getHtmlTemplate()).thenReturn(htmlTemplate);
    when(dataService.findOneById(APP, "id", App.class)).thenReturn(app);
    AppInfoDto expectedAppInfo = AppInfoDto.builder().setId("id").setName("name").setActive(true).build();
    mockMvc.perform(get(AppsController.URI + "/id")).andExpect(status().isOk()).andExpect(view().name("html")).andExpect(model().attribute("app", expectedAppInfo));
}
Also used : App(org.molgenis.apps.model.App) FreemarkerTemplate(org.molgenis.core.ui.data.system.core.FreemarkerTemplate) Test(org.testng.annotations.Test)

Example 3 with FreemarkerTemplate

use of org.molgenis.core.ui.data.system.core.FreemarkerTemplate in project molgenis by molgenis.

the class RepositoryTemplateLoader method findTemplateSource.

@Override
public Object findTemplateSource(String name) throws IOException {
    FreemarkerTemplate template = dataService.findOne(FREEMARKER_TEMPLATE, new QueryImpl<FreemarkerTemplate>().eq("Name", name), FreemarkerTemplate.class);
    if (template == null) {
        return null;
    }
    TemplateSource templateSource = new TemplateSource(template);
    LOG.debug("Created " + templateSource);
    return templateSource;
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) FreemarkerTemplate(org.molgenis.core.ui.data.system.core.FreemarkerTemplate)

Aggregations

FreemarkerTemplate (org.molgenis.core.ui.data.system.core.FreemarkerTemplate)3 App (org.molgenis.apps.model.App)2 QueryImpl (org.molgenis.data.support.QueryImpl)1 Test (org.testng.annotations.Test)1