@Test public void createThreeProjectsForTwoUsers() { User userA = UserMother.createUser(); userA.setUserId(1); User userB = UserMother.createUser(); userB.setUserId(2); Project pA = ProjectMother.createProject(1); Project pB = ProjectMother.createProject(2); Project pC = ProjectMother.createProject(3); assignments.add(ProjectAssignmentMother.createProjectAssignment(userA, pA)); assignments.add(ProjectAssignmentMother.createProjectAssignment(userB, pB)); assignments.add(ProjectAssignmentMother.createProjectAssignment(userA, pC)); int id = 1; for (ProjectAssignment assignment : assignments) { assignment.setAssignmentId(id++); } for (ProjectAssignment assignment : assignments) { collection.addProjectAssignment(assignment); } assertEquals(3, collection.getAssignments().size()); assertEquals(2, collection.getUserIds().size()); }
@Override public ProjectManagerReport getProjectManagerDetailedReport(Project project) { ProjectManagerReport report = new ProjectManagerReport(); // get the project report.setProject(project); // get a proper report range DateRange reportRange = getReportRangeForProject(project); report.setReportRange(reportRange); // get all aggregates List<Project> projects = Arrays.asList(project); SortedSet<AssignmentAggregateReportElement> aggregates = new TreeSet<AssignmentAggregateReportElement>( reportAggregatedDAO.getCumulatedHoursPerAssignmentForProjects(projects, reportRange)); // filter out just the id's List<Integer> assignmentIds = new ArrayList<>(); for (AssignmentAggregateReportElement aggregate : aggregates) { assignmentIds.add(aggregate.getProjectAssignment().getAssignmentId()); } // get all assignments for this period regardless whether they booked hours on it List<ProjectAssignment> allAssignments = projectAssignmentService.getProjectAssignments(project, reportRange); for (ProjectAssignment assignment : allAssignments) { if (!assignmentIds.contains(assignment.getAssignmentId())) { AssignmentAggregateReportElement emptyAggregate = new AssignmentAggregateReportElement(); emptyAggregate.setProjectAssignment(assignment); aggregates.add(emptyAggregate); } } report.setAggregates(aggregates); report.deriveTotals(); return report; }
/** * 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)); }