Search in sources :

Example 1 with RangePeriodSelector

use of com.artezio.arttime.web.criteria.RangePeriodSelector in project ART-TIME by Artezio.

the class FilterBean method setCurrentFilter.

public void setCurrentFilter(Filter filter) {
    filter = filterRepository.fetchDetails(filter);
    if (currentFilter != null) {
        RangePeriodSelector currentPeriodSelector = currentFilter.getRangePeriodSelector();
        filter.setRangePeriodSelector(currentPeriodSelector);
    }
    currentFilter = filter;
    setSelectedProjects(filter.getProjects());
    newFilterName = currentFilter.getName();
}
Also used : RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector)

Example 2 with RangePeriodSelector

use of com.artezio.arttime.web.criteria.RangePeriodSelector in project ART-TIME by Artezio.

the class FilterServiceTest method testCreatePersonalTimesheetFilter.

@Test
public void testCreatePersonalTimesheetFilter() throws NoSuchFieldException {
    setField(filterService, "hourTypeRepository", hourTypeRepository);
    setField(filterService, "projectRepository", projectRepository);
    setField(filterService, "departmentRepository", departmentRepository);
    Filter currentFilter = new Filter();
    RangePeriodSelector currentPeriodSelector = new RangePeriodSelector(new Period(new Date(1), new Date(2)));
    currentFilter.setRangePeriodSelector(currentPeriodSelector);
    Employee employee = new Employee("user");
    expect(departmentRepository.getDepartments()).andReturn(Collections.emptyList());
    expect(hourTypeRepository.getAll()).andReturn(Collections.emptyList());
    expect(projectRepository.getActiveAndReportedProjects(employee, currentFilter.getPeriod())).andReturn(Collections.emptyList());
    replay(departmentRepository, hourTypeRepository, projectRepository);
    Filter actual = filterService.createPersonalTimesheetFilter(currentFilter, employee);
    verify(departmentRepository, hourTypeRepository, projectRepository);
    assertEquals(currentFilter.getPeriod(), actual.getPeriod());
    assertEquals(1, actual.getEmployees().size());
    assertEquals(employee, actual.getEmployees().get(0));
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Period(com.artezio.arttime.datamodel.Period) Test(org.junit.Test)

Example 3 with RangePeriodSelector

use of com.artezio.arttime.web.criteria.RangePeriodSelector in project ART-TIME by Artezio.

the class HoursRepositoryTest method testGetHours_FilterHasNoProjectsAndHasHourTypes.

@Test
public void testGetHours_FilterHasNoProjectsAndHasHourTypes() {
    HourType hourType = new HourType("1");
    List<HourType> hourTypes = Collections.singletonList(hourType);
    Project project = new Project();
    project.setAccountableHours(hourTypes);
    Hours hour = new Hours(project, new Date(), null, hourType);
    entityManager.persist(hourType);
    entityManager.persist(project);
    entityManager.persist(hour);
    RangePeriodSelector rangePeriodSelector = new RangePeriodSelector(createPeriod(-1, 1));
    Filter filter = new Filter();
    filter.setRangePeriodSelector(rangePeriodSelector);
    filter.setHourTypes(hourTypes);
    filter.setProjects(Collections.emptyList());
    List<Hours> actual = hoursRepository.getHours(filter);
    List<Hours> expected = Collections.singletonList(hour);
    assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Filter(com.artezio.arttime.filter.Filter) RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 4 with RangePeriodSelector

use of com.artezio.arttime.web.criteria.RangePeriodSelector in project ART-TIME by Artezio.

the class FilterTest method testSetCustomPeriod.

@Test
public void testSetCustomPeriod() throws ParseException {
    RangePeriodSelector rangePeriodSelector = new RangePeriodSelector();
    rangePeriodSelector.setMonthPeriod();
    filter.setRangePeriodSelector(rangePeriodSelector);
    Period period = new Period(sdf.parse("13-01-2015"), sdf.parse("15-01-2015"));
    filter.setCustomPeriod(period);
    assertEquals(Range.CUSTOM, rangePeriodSelector.getRange());
    assertSame(period.getStart(), rangePeriodSelector.getPeriod().getStart());
    assertSame(period.getFinish(), rangePeriodSelector.getPeriod().getFinish());
}
Also used : RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Period(com.artezio.arttime.datamodel.Period) Test(org.junit.Test)

Example 5 with RangePeriodSelector

use of com.artezio.arttime.web.criteria.RangePeriodSelector in project ART-TIME by Artezio.

the class IntegrationFacadeTest method testGetHours_includeSubprojects.

@Test
public void testGetHours_includeSubprojects() {
    List<Hours> expecteds = new ArrayList<>();
    Project project = new Project();
    project.setCode("TEST-PROJECT");
    Project subproject = new Project(project);
    subproject.setCode("TEST_SUBPROJECT");
    Date from = new GregorianCalendar(2011, 1, 5).getTime();
    Date to = new GregorianCalendar(2011, 1, 15).getTime();
    Period period = new Period(from, to);
    List<Project> projects = asList(project, subproject);
    Filter filter = new Filter();
    filter.setProjects(projects);
    filter.setApproved(null);
    RangePeriodSelector rangePeriodSelector = new RangePeriodSelector(period);
    filter.setRangePeriodSelector(rangePeriodSelector);
    HoursSearchCriteria criteria = new HoursSearchCriteria(from, to, false, asList("TEST-PROJECT"));
    criteria.setIncludeSubprojects(true);
    Project anotherProject = new Project();
    Project anotherSubproject = new Project();
    anotherProject.setCode("ANOTHER-PROJECT");
    anotherSubproject.setCode("ANOTHER-SUBPROJECT");
    List<Project> allProjects = Arrays.asList(project, subproject, anotherProject, anotherSubproject);
    expect(projectService.getAll()).andReturn(allProjects).anyTimes();
    expect(hoursService.getHours(eq(filter))).andReturn(expecteds);
    replay(projectService, hoursRepository, hoursService);
    List<Hours> actuals = facade.getHours(criteria);
    verify(projectService, hoursRepository);
    assertSame(expecteds, actuals);
}
Also used : Filter(com.artezio.arttime.filter.Filter) RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Test(org.junit.Test)

Aggregations

RangePeriodSelector (com.artezio.arttime.web.criteria.RangePeriodSelector)19 Filter (com.artezio.arttime.filter.Filter)16 Test (org.junit.Test)14 Hours (com.artezio.arttime.datamodel.Hours)5 Project (com.artezio.arttime.datamodel.Project)5 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)5 Date (java.util.Date)5 HourType (com.artezio.arttime.datamodel.HourType)4 Employee (com.artezio.arttime.datamodel.Employee)2 Period (com.artezio.arttime.datamodel.Period)2 Date (java.sql.Date)2 HoursRepository (com.artezio.arttime.repositories.HoursRepository)1 Before (org.junit.Before)1