* @param criteriasInGroupsAndCategories user selections
* @param session the Hibernate session to use
* @return appropriate applications (best first), may be empty
*/
private ApplicationType[] findAppropriateApplications(HttpServletRequest req, Map<String, String[][]> criteriasInGroupsAndCategories) {
ApplicationManager applicationManager = new ApplicationManager(req.getLocale(),session);
ApplicationType[] applications = applicationManager.getApplications();
float[] applicationWeights = new float[applications.length];
CategoryManager categoryManager = new CategoryManager(req.getLocale(),session);
CriteriaManager criteriaManager = new CriteriaManager(req.getLocale(),session);
Category[] categories = categoryManager.getSortedCategories();
try {
// evaluate user input for all categories (input pages)
for (Category category : categories) {
String categoryname = category.getCategoryname();
String[][] criteriasInCategory = criteriasInGroupsAndCategories.get(categoryname);
if (criteriasInCategory != null) { // input page "touched"
CriteriaGroup[] groups = categoryManager.getSortedGroups(category);
// evaluate user input within the groups of a category
for (int groupX = 0; groupX < groups.length; groupX++) {
CriteriaGroup group = groups[groupX];
// evaluate all selected criteria
String[] selectedCriterias = criteriasInCategory[groupX];
Criteria[] criterias = criteriaManager.getSortedCriterias(group);
for (int criteriaX = 0; criteriaX < criterias.length; criteriaX++) {
Criteria criteria = criterias[criteriaX];
boolean criteriaSelected = false;
if (!criteriaSelected && selectedCriterias != null){
for (int selectedCriteriaX = 0; selectedCriteriaX < selectedCriterias.length; selectedCriteriaX++) {
String selectedCriteriaEntry = selectedCriterias[selectedCriteriaX];
if (Integer.parseInt(selectedCriteriaEntry) == criteriaX){
criteriaSelected = true;
break;
}
}
}
if (criteriaSelected){
// first decrease weight of all applications, then find applications with assigned criteria and increase
// => only applications with assigned criteria remain >= 0
for (int i = 0; i < applications.length; i++) {
applicationWeights[i] -= 1.0;
}
Application2Criteria[] application2criterias = applicationManager.getApplication2criteria(criteria);
for (Application2Criteria application2criteria : application2criterias) {
for (int applicationX = 0; applicationX < applications.length; applicationX++) {
ApplicationType application = applications[applicationX];
if (application == application2criteria.getApplication()){
applicationWeights[applicationX] += application2criteria.getWeight();