// retrieves application from group and application ID in form; returns a reasonable proposal if none available; throws exception if insufficient access rights
// also sets session attribute "applications" with applications according to group
// the application ID can be null if no information available or application not used in the JSP
protected Application applicationPreparation(HttpServletRequest req, Group group, Long applicationId) {
ApplicationManager applicationManager = new ApplicationManager(locale,session);
List<Application> applications = applicationManager.getApplications(group);
Application defaultApplication = group.getDefaultApplication(); // may be null
Application application = new Application();
application.setId(-1);
switch (applications.size()) {
case 0:
application.setName("(" + getLocalizedMessage("SystemWeb", "sys.noApplicationAvailable") + ")");
applications.add(application);
break;
case 1:
application = applications.iterator().next();
break;
default:
if (defaultApplication != null){
application = defaultApplication;
} else {
application.setName("(" + getLocalizedMessage("SystemWeb", "sys.noApplicationSelected") + ")");
applications.add(0,application);
}
}
req.getSession().setAttribute("applications", applications);
if (applicationId != null){
Application selectedApplication = applicationManager.getApplication(applicationId);
if (selectedApplication != null && selectedApplication.getGroup() == group){
application = selectedApplication;
}
}
return application;