use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.
the class FilterService method getTimesheetFilter.
@AbacContext(VIEW_TIMESHEET)
public Filter getTimesheetFilter() {
Filter result = new Filter();
result.setDepartments(departmentRepository.getDepartments());
result.setHourTypes(hourTypeService.getAll());
employeeService.getLoggedEmployee().ifPresent(employee -> result.setEmployees(Collections.singletonList(employee)));
result.setProjects(getActiveAndReportedProjects(result.getPeriod()));
return result;
}
use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.
the class ReportsBean method getSelectedProjectIds.
protected Long[] getSelectedProjectIds() {
Filter filter = getFilter();
List<Hours> reportedHours = hoursService.getHours(getFilter());
Set<Project> projectsWithReportedHours = reportedHours.parallelStream().map(Hours::getProject).collect(Collectors.toSet());
Set<Project> projects = new HashSet<>(projectService.getEffortsProjects(filter));
projects = Sets.union(projects, projectsWithReportedHours).stream().filter(project -> project.getStatus() == ACTIVE || projectsWithReportedHours.contains(project) || (nonNull(filter.getName()) && filter.getProjects().contains(project))).collect(Collectors.toSet());
return projects.stream().map(Project::getId).toArray(Long[]::new);
}
use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.
the class WorkTimeServiceTest method testGetProblemWorkTime_PeriodHasWorkingDays.
@Test
public void testGetProblemWorkTime_PeriodHasWorkingDays() throws NoSuchFieldException {
Date date1 = new Date();
Date date2 = new Date();
Period period = new Period();
Employee employee = new Employee("employee");
Map<Employee, Map<Boolean, BigDecimal>> actualWorkTimeByEmployee = new HashMap<>();
actualWorkTimeByEmployee.put(employee, new HashMap<Boolean, BigDecimal>() {
{
put(false, new BigDecimal(8).setScale(2));
put(true, new BigDecimal(8).setScale(2));
}
});
WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
employee.setCalendar(calendar);
Employee manager1 = new Employee("manager1");
Employee manager2 = new Employee("manager2");
Map<Employee, List<Employee>> managersForApproveByEmployee = new HashMap<Employee, List<Employee>>() {
{
put(employee, asList(manager1));
}
};
Map<Employee, List<Employee>> managersByEmployee = new HashMap<Employee, List<Employee>>() {
{
put(employee, asList(manager1, manager2));
}
};
List<Employee> employees = asList(employee);
Filter filter = new Filter();
filter.setEmployees(employees);
filter.setCustomPeriod(period);
ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
EmployeeRepository.EmployeeQuery employeeQuery = Mockito.mock(EmployeeRepository.EmployeeQuery.class, Mockito.RETURNS_DEEP_STUBS);
Tuple tuple1 = Mockito.mock(Tuple.class);
Tuple tuple2 = Mockito.mock(Tuple.class);
expect(workdaysCalendarService.getDays(calendar, period)).andReturn(asList(new Day(date1, calendar, true), new Day(date2, calendar, true)));
expect(hoursRepository.getActualTimeByEmployeeAndApproval(employees, period)).andReturn(actualWorkTimeByEmployee);
expect(hoursRepository.getManagersForApproveByEmployee(employees, period)).andReturn(managersForApproveByEmployee);
expect(projectRepository.query(true)).andReturn(projectQuery);
expect(employeeRepository.query()).andReturn(employeeQuery);
Mockito.when(employeeQuery.filter(filter).notFormer().list()).thenReturn(employees);
Mockito.when(tuple1.get(0, Employee.class)).thenReturn(employee);
Mockito.when(tuple1.get(1, Employee.class)).thenReturn(manager1);
Mockito.when(tuple2.get(0, Employee.class)).thenReturn(employee);
Mockito.when(tuple2.get(1, Employee.class)).thenReturn(manager2);
Mockito.when(projectQuery.teamMembers(employees).getManagers()).thenReturn(asList(tuple1, tuple2));
EasyMock.replay(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
List<WorkTime> expected = asList(new WorkTime(employee, new BigDecimal("16.00"), actualWorkTimeByEmployee.get(employee), managersForApproveByEmployee.get(employee), managersByEmployee.get(employee)));
List<WorkTime> actual = workTimeService.getProblemWorkTime(filter);
EasyMock.verify(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
assertEqualsWorkTime(expected.get(0), actual.get(0));
}
use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.
the class WorkTimeServiceTest method testGetProblemWorkTime_PeriodHasNonWorkingDays.
@Test
public void testGetProblemWorkTime_PeriodHasNonWorkingDays() throws NoSuchFieldException {
Date date1 = new Date();
Date date2 = new Date();
Period period = new Period();
Employee employee = new Employee("employee");
Map<Employee, Map<Boolean, BigDecimal>> actualWorkTimeByEmployee = new HashMap<>();
WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
employee.setCalendar(calendar);
Employee manager1 = new Employee("manager1");
Employee manager2 = new Employee("manager2");
Map<Employee, List<Employee>> managersForApproveByEmployee = new HashMap<Employee, List<Employee>>() {
{
put(employee, asList(manager1));
}
};
List<Employee> employees = asList(employee);
Filter filter = new Filter();
filter.setEmployees(employees);
filter.setCustomPeriod(period);
ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
EmployeeRepository.EmployeeQuery employeeQuery = Mockito.mock(EmployeeRepository.EmployeeQuery.class, Mockito.RETURNS_DEEP_STUBS);
Tuple tuple1 = Mockito.mock(Tuple.class);
Tuple tuple2 = Mockito.mock(Tuple.class);
expect(workdaysCalendarService.getDays(calendar, period)).andReturn(asList(new Day(date1, calendar, false), new Day(date2, calendar, false)));
expect(hoursRepository.getActualTimeByEmployeeAndApproval(employees, period)).andReturn(actualWorkTimeByEmployee);
expect(hoursRepository.getManagersForApproveByEmployee(employees, period)).andReturn(managersForApproveByEmployee);
expect(projectRepository.query(true)).andReturn(projectQuery);
expect(employeeRepository.query()).andReturn(employeeQuery);
Mockito.when(employeeQuery.filter(filter).notFormer().list()).thenReturn(employees);
Mockito.when(tuple1.get(0, Employee.class)).thenReturn(employee);
Mockito.when(tuple1.get(1, Employee.class)).thenReturn(manager1);
Mockito.when(tuple2.get(0, Employee.class)).thenReturn(employee);
Mockito.when(tuple2.get(1, Employee.class)).thenReturn(manager2);
Mockito.when(projectQuery.teamMembers(employees).getManagers()).thenReturn(asList(tuple1, tuple2));
EasyMock.replay(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
List<WorkTime> actual = workTimeService.getProblemWorkTime(filter);
EasyMock.verify(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
assertTrue(actual.isEmpty());
}
use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.
the class WorkTimeServiceTest method testGetProblemWorkTime_PeriodHasWorkingAndNonWorkingDays.
@Test
public void testGetProblemWorkTime_PeriodHasWorkingAndNonWorkingDays() throws NoSuchFieldException {
Date date1 = new Date();
Date date2 = new Date();
Period period = new Period();
Employee employee = new Employee("employee");
Map<Employee, Map<Boolean, BigDecimal>> actualWorkTimeByEmployee = new HashMap<>();
actualWorkTimeByEmployee.put(employee, new HashMap<Boolean, BigDecimal>() {
{
put(false, new BigDecimal(8).setScale(2));
}
});
WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
employee.setCalendar(calendar);
Employee manager1 = new Employee("manager1");
Employee manager2 = new Employee("manager2");
Map<Employee, List<Employee>> managersForApproveByEmployee = new HashMap<Employee, List<Employee>>() {
{
put(employee, asList(manager1));
}
};
Map<Employee, List<Employee>> managersByEmployee = new HashMap<Employee, List<Employee>>() {
{
put(employee, asList(manager1, manager2));
}
};
List<Employee> employees = asList(employee);
Filter filter = new Filter();
filter.setEmployees(employees);
filter.setCustomPeriod(period);
ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
EmployeeRepository.EmployeeQuery employeeQuery = Mockito.mock(EmployeeRepository.EmployeeQuery.class, Mockito.RETURNS_DEEP_STUBS);
Tuple tuple1 = Mockito.mock(Tuple.class);
Tuple tuple2 = Mockito.mock(Tuple.class);
expect(workdaysCalendarService.getDays(anyObject(WorkdaysCalendar.class), anyObject(Period.class))).andReturn(asList(new Day(date1, calendar, true), new Day(date2, calendar, false)));
expect(hoursRepository.getActualTimeByEmployeeAndApproval(employees, period)).andReturn(actualWorkTimeByEmployee);
expect(hoursRepository.getManagersForApproveByEmployee(employees, period)).andReturn(managersForApproveByEmployee);
expect(projectRepository.query(true)).andReturn(projectQuery);
expect(employeeRepository.query()).andReturn(employeeQuery);
Mockito.when(employeeQuery.filter(filter).notFormer().list()).thenReturn(employees);
Mockito.when(tuple1.get(0, Employee.class)).thenReturn(employee);
Mockito.when(tuple1.get(1, Employee.class)).thenReturn(manager1);
Mockito.when(tuple2.get(0, Employee.class)).thenReturn(employee);
Mockito.when(tuple2.get(1, Employee.class)).thenReturn(manager2);
Mockito.when(projectQuery.teamMembers(employees).getManagers()).thenReturn(asList(tuple1, tuple2));
EasyMock.replay(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
List<WorkTime> expected = asList(new WorkTime(employee, new BigDecimal("8.00"), actualWorkTimeByEmployee.get(employee), managersForApproveByEmployee.get(employee), managersByEmployee.get(employee)));
List<WorkTime> actual = workTimeService.getProblemWorkTime(filter);
EasyMock.verify(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
assertEqualsWorkTime(expected.get(0), actual.get(0));
}
Aggregations