/**
   * Calculates overheads for user from given backlogs( projects)
   *
   * @param from
   * @param weeksAhead
   * @param items
   * @return
   */
  public HashMap<Integer, String> calculateOverheads(
      Date from, int weeksAhead, List<Backlog> items, User user) {
    GregorianCalendar cal = new GregorianCalendar();
    CalendarUtils cUtils = new CalendarUtils();
    HashMap<Integer, String> overheads = new HashMap<Integer, String>();

    Date start = from;
    Date end = cUtils.nextMonday(start);
    cal.setTime(start);
    Integer week = cal.get(GregorianCalendar.WEEK_OF_YEAR);
    List<Assignment> assignments = new ArrayList<Assignment>(user.getAssignments());

    for (int i = 1; i <= weeksAhead; i++) {
      // 1. Get Backlogs that hit for the week
      log.debug("Projects searched from :" + start);
      log.debug("Projects searched ending :" + end);
      cal.setTime(start);
      week = cal.get(GregorianCalendar.WEEK_OF_YEAR);
      log.debug("Calculating overhead for week" + week);

      // 2. Get projects that hit current week
      List<Backlog> list = this.getProjectsAndIterationsInTimeFrame(items, start, end);
      log.debug(list.size() + " projects found for given time frame");

      // 3. Calculate overhead sum from items in those projects
      AFTime overhead = new AFTime(0);
      for (Backlog blog : list) {
        // Only check assignments for Projects (overhead
        // only set for projects not iterations)
        if (blog.getClass().equals(Project.class)) {
          Project pro = (Project) blog;
          for (Assignment ass : assignments) {
            if (ass.getBacklog().equals((Backlog) pro)) {
              if (pro.getDefaultOverhead() != null) {
                overhead.add(pro.getDefaultOverhead());
                log.debug("Added overhead from project: " + pro.getDefaultOverhead());
              }
              if (ass.getDeltaOverhead() != null) {
                overhead.add(ass.getDeltaOverhead());
                log.debug("Added overhead from user: "******"Class was iteration class, overhead :" + blog.getClass());
        }
      }
      overheads.put(week, overhead.toString());
      start = cUtils.nextMonday(start);
      end = cUtils.nextMonday(start);
      cal.setTime(start);
      week = cal.get(GregorianCalendar.WEEK_OF_YEAR);
    }

    return overheads;
  }
  public HashMap<Integer, String> calculateEffortLefts(
      Date from, int weeksAhead, Map<Backlog, List<BacklogItem>> items) {
    GregorianCalendar cal = new GregorianCalendar();
    CalendarUtils cUtils = new CalendarUtils();
    HashMap<Integer, String> effortLefts = new HashMap<Integer, String>();

    Date start = from;
    Date end = cUtils.nextMonday(start);
    cal.setTime(start);
    Integer week = cal.get(GregorianCalendar.WEEK_OF_YEAR);
    for (int i = 1; i <= weeksAhead; i++) {
      // 1. Get Backlogs that hit for the week
      log.debug("Projects searched from :" + start);
      log.debug("Projects searched ending :" + end);
      cal.setTime(start);
      week = cal.get(GregorianCalendar.WEEK_OF_YEAR);
      log.debug("Calculating sums for week" + week);

      // 2. Get projects that hit current week
      List<Backlog> list =
          this.getProjectsAndIterationsInTimeFrame(
              new ArrayList<Backlog>(items.keySet()), start, end);
      log.debug(list.size() + " projects found for given time frame");

      // 3. Calculate effort sum from items in those projects
      AFTime total = new AFTime(0);
      for (Backlog blog : list) {
        Project pro = null;
        Iteration it = null;
        if (blog.getClass().equals(Project.class)) {
          pro = (Project) blog;
          List<BacklogItem> blis = items.get((Backlog) pro);
          if (blis != null) {
            // Dividing for weeks that project hits
            AFTime sum =
                this.backlogBusiness.getEffortLeftResponsibleDividedSum(blis).getEffortHours();
            int projectLength = CalendarUtils.getLengthInDays(pro.getStartDate(), pro.getEndDate());
            log.debug("Week Project length: " + projectLength + " days");
            int weekEndDaysInProject = cUtils.getWeekEndDays(pro.getStartDate(), pro.getEndDate());
            log.debug("Excluding " + weekEndDaysInProject + " days from project as week end days");
            projectLength = projectLength - weekEndDaysInProject;
            if (projectLength == 0) { // TODO Find better way to
              // prevent null divination
              // if project on weekend
              projectLength = 1;
            }
            List<Date> dates =
                cUtils.getProjectDaysList(
                    pro.getStartDate(),
                    pro.getEndDate(),
                    start,
                    new Date(end.getTime() - 86400000L),
                    false);
            int projectDaysOnWeek = 0;
            if (dates != null) {
              projectDaysOnWeek = dates.size();
            }
            log.debug("Week Project length (modified): " + projectLength + " days");
            log.debug("Week Project days:" + projectDaysOnWeek);
            log.debug(
                "Week Project effort per day: " + new AFTime(sum.getTime() / (long) projectLength));
            sum = new AFTime((sum.getTime() / (long) projectLength) * projectDaysOnWeek);
            if (sum != null) {
              total.add(sum);
              log.debug("Week effort sum: " + sum);
            }
          }
        }
        if (blog.getClass().equals(Iteration.class)) {
          it = (Iteration) blog;
          List<BacklogItem> blis = items.get((Backlog) it);
          if (blis != null) {
            // Dividing for weeks that project hits
            AFTime sum =
                this.backlogBusiness.getEffortLeftResponsibleDividedSum(blis).getEffortHours();
            int projectLength = CalendarUtils.getLengthInDays(it.getStartDate(), it.getEndDate());
            log.debug("Week Project length: " + projectLength + " days");
            int weekEndDaysInProject = cUtils.getWeekEndDays(it.getStartDate(), it.getEndDate());
            log.debug("Excluding " + weekEndDaysInProject + " days from project as week end days");
            projectLength = projectLength - weekEndDaysInProject;
            if (projectLength == 0) { // TODO Find better way to
              // prevent null division if
              // project on weekend
              projectLength = 1;
            }
            List<Date> dates =
                cUtils.getProjectDaysList(
                    it.getStartDate(),
                    it.getEndDate(),
                    start,
                    new Date(end.getTime() - 86400000L),
                    false);
            int projectDaysOnWeek = 0;
            if (dates != null) {
              projectDaysOnWeek = dates.size();
            }
            log.debug("Week Project length(modified): " + projectLength + " days");
            log.debug("Week Project days:" + projectDaysOnWeek);
            log.debug(
                "Week Project effort per day: " + new AFTime(sum.getTime() / (long) projectLength));
            sum = new AFTime((sum.getTime() / (long) projectLength) * projectDaysOnWeek);
            if (sum != null) {
              total.add(sum);
              log.debug("Week effort sum: " + sum);
            }
          }
        }
      }

      effortLefts.put(week, total.toString());
      start = cUtils.nextMonday(start);
      end = cUtils.nextMonday(start);
      cal.setTime(start);
      week = cal.get(GregorianCalendar.WEEK_OF_YEAR);
    }

    return effortLefts;
  }