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);
}
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;
}
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;
}
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());
}
Aggregations