/** Update available report criteria */
  public ReportCriteria syncUserReportCriteria(
      ReportCriteria reportCriteria, ReportCriteriaUpdateType updateType) {
    UserCriteria userCriteria = reportCriteria.getUserCriteria();
    AvailableCriteria availCriteria = reportCriteria.getAvailableCriteria();

    if (userCriteria.isSingleUser()) {
      syncCriteriaForSingleUser(reportCriteria);
    } else {
      if (updateType == ReportCriteriaUpdateType.UPDATE_CUSTOMERS
          || updateType == ReportCriteriaUpdateType.UPDATE_ALL) {
        availCriteria.setCustomers(getAvailableCustomers(userCriteria));
      }

      if (updateType == ReportCriteriaUpdateType.UPDATE_PROJECTS
          || updateType == ReportCriteriaUpdateType.UPDATE_ALL) {
        availCriteria.setProjects(getAvailableProjects(userCriteria));
      }

      if (updateType == ReportCriteriaUpdateType.UPDATE_ALL) {
        availCriteria.setUserDepartments(userDepartmentDAO.findAll());

        availCriteria.setReportRange(reportAggregatedDAO.getMinMaxDateTimesheetEntry());
      }

      if (updateType == ReportCriteriaUpdateType.UPDATE_USERS
          || updateType == ReportCriteriaUpdateType.UPDATE_ALL) {
        availCriteria.setUsers(getAvailableUsers(userCriteria));
      }
    }

    return reportCriteria;
  }
  /**
   * Sync criteria for users, only customers & projects are displayed for users in this list
   *
   * @param reportCriteria
   */
  private void syncCriteriaForSingleUser(ReportCriteria reportCriteria) {
    Set<Customer> customers = new HashSet<Customer>();
    Set<Project> projects = new HashSet<Project>();
    AvailableCriteria availCriteria = reportCriteria.getAvailableCriteria();
    User user;

    user = reportCriteria.getUserCriteria().getUsers().get(0);

    List<ProjectAssignment> assignments =
        projectAssignmentDAO.findProjectAssignmentsForUser(
            user.getUserId(), reportCriteria.getUserCriteria().getReportRange());

    for (ProjectAssignment assignment : assignments) {
      customers.add(assignment.getProject().getCustomer());
      projects.add(assignment.getProject());
    }

    availCriteria.setCustomers(new ArrayList<Customer>(customers));
    availCriteria.setProjects(new ArrayList<Project>(projects));

    availCriteria.setReportRange(reportAggregatedDAO.getMinMaxDateTimesheetEntry(user));
  }