System.out.println("ProjectManagerImpl.getAllProjects() " + user.getUserType());
sessionFactory = HibernateSessionFactory.getInstance();
session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(BOProject.class);
// List<BOProject> toProjectList = new ArrayList<BOProject>();
if (projectStatus != null) {
criteria.add(Restrictions.eq("projectStatus", projectStatus));
}
// List<BOProject> fromProjectList = criteria.list();
/*
* if(true) { return fromProjectList; }
*/
if (user.getUserType() == UserType.Administrator || user.getUserType() == UserType.CEO) {
System.out.println("ProjectManagerImpl.getAllProjects() Administrator ");
// toProjectList = fromProjectList;
} else {
System.out.println("ProjectManagerImpl.getAllProjects() Others ");
String departmentsOwned = getAllDepartmentsAndChildDepartmentsForUserAsString(new StringBuilder(), user.getDepartmentsOwned(), 0);
// criteria.add(Restrictions.sqlRestriction(
// "select * from projects p where p.project_owner = ? or p.project_id in( select t.task_project from tasks t, user_tasks ut where ut.task_id = t.task_id and ( t.task_owner = ? or ut.user_id = ? ))"
// , 2, Hibernate.LONG));
String restriction = "(" + " project_owner = " + user.getUserID() + " " + " or project_company in " + " ( " + " select company.company_id " + " from companies company "
+ " where company.company_owner = " + user.getUserID() + " " + " ) ";
if (!departmentsOwned.trim().equals("")) {
restriction += " or project_id in " + " ( " + " select pdept.project_id " + " from project_departments pdept, departments dept " + " where pdept.department_id = dept.dept_id "
+ " and pdept.department_id in ( " + departmentsOwned + ") " + " ) ";
}
restriction += " or project_id in " + " ( " + " select t.task_project" + " from tasks t, user_tasks ut " + " where ut.task_id = t.task_id " + " and " + " ("
+ " t.task_owner = " + user.getUserID() + " " + " or ut.user_id = " + user.getUserID() + " " + ")" + " )" + ")";
criteria.add(Restrictions.sqlRestriction(restriction));
// fillRelevantProjects(fromProjectList, toProjectList, user,
// projectStatus);
}
System.out.println("ProjectManagerImpl.getAllProjects() ended ");
return criteria.list();
// return toProjectList;
} catch (Exception a_th) {
throw new RuntimeException(a_th);
} finally {