Search in sources :

Example 1 with App

use of org.hisp.dhis.appmanager.App in project dhis2-core by dhis2.

the class AppController method getApps.

// -------------------------------------------------------------------------
// Resources
// -------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
public void getApps(@RequestParam(required = false) String key, HttpServletRequest request, HttpServletResponse response) throws IOException {
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    String contextPath = ContextUtils.getContextPath(request);
    List<App> apps = new ArrayList<>();
    if (key != null) {
        App app = appManager.getApp(key, contextPath);
        if (app == null) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        apps.add(app);
    } else if (!filters.isEmpty()) {
        apps = appManager.filterApps(filters, contextPath);
    } else {
        apps = appManager.getApps(contextPath);
    }
    response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
    renderService.toJson(response.getOutputStream(), apps);
}
Also used : App(org.hisp.dhis.appmanager.App) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with App

use of org.hisp.dhis.appmanager.App in project dhis2-core by dhis2.

the class RedirectAction method execute.

@Override
public String execute() throws Exception {
    String startModule = (String) systemSettingManager.getSystemSetting(SettingKey.START_MODULE);
    String contextPath = (String) ContextUtils.getContextPath(ServletActionContext.getRequest());
    if (startModule != null && !startModule.trim().isEmpty()) {
        if (startModule.startsWith("app:")) {
            List<App> apps = appManager.getApps(contextPath);
            for (App app : apps) {
                if (app.getName().equals(startModule.substring("app:".length()))) {
                    redirectUrl = app.getLaunchUrl();
                    return SUCCESS;
                }
            }
        } else {
            redirectUrl = "../" + startModule + "/index.action";
            return SUCCESS;
        }
    }
    redirectUrl = "../dhis-web-dashboard-integration/index.action";
    return SUCCESS;
}
Also used : App(org.hisp.dhis.appmanager.App)

Example 3 with App

use of org.hisp.dhis.appmanager.App in project dhis2-core by dhis2.

the class DefaultDashboardService method search.

@Override
public DashboardSearchResult search(String query, Set<DashboardItemType> maxTypes) {
    Set<String> words = Sets.newHashSet(query.split(TextUtils.SPACE));
    List<App> dashboardApps = appManager.getAppsByType(AppType.DASHBOARD_WIDGET, new HashSet<>(appManager.getApps(null)));
    DashboardSearchResult result = new DashboardSearchResult();
    result.setUsers(userService.getAllUsersBetweenByName(query, 0, getMax(DashboardItemType.USERS, maxTypes)));
    result.setCharts(objectManager.getBetweenLikeName(Chart.class, words, 0, getMax(DashboardItemType.CHART, maxTypes)));
    result.setEventCharts(objectManager.getBetweenLikeName(EventChart.class, words, 0, getMax(DashboardItemType.EVENT_CHART, maxTypes)));
    result.setMaps(objectManager.getBetweenLikeName(Map.class, words, 0, getMax(DashboardItemType.MAP, maxTypes)));
    result.setReportTables(objectManager.getBetweenLikeName(ReportTable.class, words, 0, getMax(DashboardItemType.REPORT_TABLE, maxTypes)));
    result.setEventReports(objectManager.getBetweenLikeName(EventReport.class, words, 0, getMax(DashboardItemType.EVENT_REPORT, maxTypes)));
    result.setReports(objectManager.getBetweenLikeName(Report.class, words, 0, getMax(DashboardItemType.REPORTS, maxTypes)));
    result.setResources(objectManager.getBetweenLikeName(Document.class, words, 0, getMax(DashboardItemType.RESOURCES, maxTypes)));
    result.setApps(appManager.getAppsByName(query, dashboardApps, "ilike"));
    return result;
}
Also used : App(org.hisp.dhis.appmanager.App) EventReport(org.hisp.dhis.eventreport.EventReport) Report(org.hisp.dhis.report.Report) EventChart(org.hisp.dhis.eventchart.EventChart) ReportTable(org.hisp.dhis.reporttable.ReportTable) Document(org.hisp.dhis.document.Document) EventReport(org.hisp.dhis.eventreport.EventReport) DashboardSearchResult(org.hisp.dhis.dashboard.DashboardSearchResult) Map(org.hisp.dhis.mapping.Map) EventChart(org.hisp.dhis.eventchart.EventChart) Chart(org.hisp.dhis.chart.Chart)

Example 4 with App

use of org.hisp.dhis.appmanager.App in project dhis2-core by dhis2.

the class AppController method renderApp.

@RequestMapping(value = "/{app}/**", method = RequestMethod.GET)
public void renderApp(@PathVariable("app") String app, HttpServletRequest request, HttpServletResponse response) throws IOException {
    Iterable<Resource> locations = Lists.newArrayList(resourceLoader.getResource("file:" + appManager.getAppFolderPath() + "/" + app + "/"), resourceLoader.getResource("classpath*:/apps/" + app + "/"));
    Resource manifest = findResource(locations, "manifest.webapp");
    if (manifest == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    ObjectMapper jsonMapper = DefaultRenderService.getJsonMapper();
    App application = jsonMapper.readValue(manifest.getInputStream(), App.class);
    if (application.getName() == null || !appManager.isAccessible(application)) {
        throw new ReadAccessDeniedException("You don't have access to application " + app + ".");
    }
    String pageName = getUrl(request.getPathInfo(), app);
    // if request was for manifest.webapp, check for * and replace with host
    if ("manifest.webapp".equals(pageName)) {
        if ("*".equals(application.getActivities().getDhis().getHref())) {
            String contextPath = ContextUtils.getContextPath(request);
            application.getActivities().getDhis().setHref(contextPath);
            jsonMapper.writeValue(response.getOutputStream(), application);
            return;
        }
    }
    Resource resource = findResource(locations, pageName);
    if (resource == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    if (new ServletWebRequest(request, response).checkNotModified(resource.lastModified())) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return;
    }
    String mimeType = request.getSession().getServletContext().getMimeType(resource.getFilename());
    if (mimeType != null) {
        response.setContentType(mimeType);
    }
    response.setContentLength((int) resource.contentLength());
    response.setHeader("Last-Modified", DateUtils.getHttpDateString(new Date(resource.lastModified())));
    StreamUtils.copy(resource.getInputStream(), response.getOutputStream());
}
Also used : App(org.hisp.dhis.appmanager.App) Resource(org.springframework.core.io.Resource) ReadAccessDeniedException(org.hisp.dhis.hibernate.exception.ReadAccessDeniedException) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

App (org.hisp.dhis.appmanager.App)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Chart (org.hisp.dhis.chart.Chart)1 DashboardSearchResult (org.hisp.dhis.dashboard.DashboardSearchResult)1 Document (org.hisp.dhis.document.Document)1 EventChart (org.hisp.dhis.eventchart.EventChart)1 EventReport (org.hisp.dhis.eventreport.EventReport)1 ReadAccessDeniedException (org.hisp.dhis.hibernate.exception.ReadAccessDeniedException)1 Map (org.hisp.dhis.mapping.Map)1 Report (org.hisp.dhis.report.Report)1 ReportTable (org.hisp.dhis.reporttable.ReportTable)1 Resource (org.springframework.core.io.Resource)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1