ReportCriteriaServiceImpl implements ReportCriteriaService { public ReportCriteria syncUserReportCriteria(ReportCriteria reportCriteria, ReportCriteriaUpdateType updateType) { UserSelectedCriteria userSelectedCriteria = reportCriteria.getUserSelectedCriteria(); AvailableCriteria availCriteria = reportCriteria.getAvailableCriteria(); List<TimesheetLock> timesheetLocks = Lists.newArrayList(WrapAsJava$.MODULE$.asJavaCollection(lockService.findAll())); availCriteria.setTimesheetLocks(timesheetLocks); if (userSelectedCriteria.isForGlobalReport() || userSelectedCriteria.isForPm()) { if (updateType == UPDATE_CUSTOMERS_AND_PROJECTS || updateType == ReportCriteriaUpdateType.UPDATE_ALL) { Tuple2<List<Customer>, List<Project>> available = customerAndProjectCriteriaFilter.getAvailableCustomers(userSelectedCriteria); List<Customer> updatedAvailableCustomers = available._1(); availCriteria.setCustomers(updatedAvailableCustomers); preserveSelectedCustomers(userSelectedCriteria, updatedAvailableCustomers); List<Project> updatedAvailableProjects = available._2(); availCriteria.setProjects(updatedAvailableProjects); preserveSelectedProjects(userSelectedCriteria, updatedAvailableProjects); } if (updateType == ReportCriteriaUpdateType.UPDATE_USERS_AND_DEPTS || updateType == ReportCriteriaUpdateType.UPDATE_ALL) { Tuple2<List<UserDepartment>, List<User>> avail = userAndDepartmentCriteriaFilter.getAvailableUsers(userSelectedCriteria); availCriteria.setUserDepartments(avail._1()); availCriteria.setUsers(avail._2()); } if (updateType == ReportCriteriaUpdateType.UPDATE_ALL) { availCriteria.setReportRange(reportAggregatedDAO.getMinMaxDateTimesheetEntry()); } } else { individualUserCriteriaSync.syncCriteriaForIndividualUser(reportCriteria); } return reportCriteria; } protected  ReportCriteriaServiceImpl(); @Autowired  ReportCriteriaServiceImpl(ReportAggregatedDao reportAggregatedDAO,
                                     CustomerAndProjectCriteriaFilter customerAndProjectCriteriaFilter,
                                     UserAndDepartmentCriteriaFilter userAndDepartmentCriteriaFilter,
                                     IndividualUserCriteriaSync individualUserCriteriaSync,
                                     TimesheetLockService lockService,
                                     UserDao userDao,
                                     ProjectDao projectDao); ReportCriteria syncUserReportCriteria(ReportCriteria reportCriteria, ReportCriteriaUpdateType updateType); @Override UsersAndProjects criteriaToUsersAndProjects(UserSelectedCriteria userSelectedCriteria);  }
@Test public void should_sync_criteria_for_single_user() { UserSelectedCriteria userSelectedCriteria = new UserSelectedCriteria(); userSelectedCriteria.setSelectedReportType(UserSelectedCriteria.ReportType.INDIVIDUAL_USER); userSelectedCriteria.setUsers(Arrays.asList(new User(1))); ReportCriteria reportCriteria = new ReportCriteria(userSelectedCriteria); reportCriteriaService.syncUserReportCriteria(reportCriteria, ReportCriteriaUpdateType.UPDATE_ALL); verify(individualUserCriteriaSync).syncCriteriaForIndividualUser(reportCriteria); }
@Test public void should_sync_criteria_for_global_for_all_users() { UserSelectedCriteria userSelectedCriteria = new UserSelectedCriteria(); userSelectedCriteria.setSelectedReportType(UserSelectedCriteria.ReportType.REPORT); userSelectedCriteria.setUsers(Arrays.asList(new User(1))); ReportCriteria reportCriteria = new ReportCriteria(userSelectedCriteria); Tuple2<List<UserDepartment>, List<User>> apply = new Tuple2<List<UserDepartment>, List<User>>(Lists.<UserDepartment>newArrayList(), Lists.<User>newArrayList()); when(userAndDepartmentCriteriaFilter.getAvailableUsers(userSelectedCriteria)).thenReturn(apply); reportCriteriaService.syncUserReportCriteria(reportCriteria, ReportCriteriaUpdateType.UPDATE_USERS_AND_DEPTS); verify(userAndDepartmentCriteriaFilter).getAvailableUsers(userSelectedCriteria); }
@Test public void should_sync_criteria_for_global_for_all_customers() { UserSelectedCriteria userSelectedCriteria = new UserSelectedCriteria(); userSelectedCriteria.setSelectedReportType(UserSelectedCriteria.ReportType.REPORT); userSelectedCriteria.setUsers(Arrays.asList(new User(1))); Tuple2<List<Customer>, List<Project>> apply = new Tuple2<List<Customer>, List<Project>>(Lists.<Customer>newArrayList(), Lists.<Project>newArrayList()); when(customerAndProjectCriteriaFilter.getAvailableCustomers(userSelectedCriteria)).thenReturn(apply); ReportCriteria reportCriteria = new ReportCriteria(userSelectedCriteria); reportCriteriaService.syncUserReportCriteria(reportCriteria, ReportCriteriaUpdateType.UPDATE_CUSTOMERS_AND_PROJECTS); verify(customerAndProjectCriteriaFilter).getAvailableCustomers(userSelectedCriteria); }