Search in sources :

Example 1 with HourType

use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.

the class HourTypeRepository method remove.

@FacesMessage(onCompleteMessageKey = "message.hourTypeIsDeleted")
@WebCached(resetCache = true)
@Log(logParams = true)
public void remove(@DetailedLogged HourType hourType) throws ActualTimeRemovalException {
    if (hourType.isActualTime()) {
        throw new ActualTimeRemovalException("Attempt to delete an actual time.");
    }
    HourType type = entityManager.find(HourType.class, hourType.getId());
    entityManager.remove(type);
    entityManager.flush();
}
Also used : ActualTimeRemovalException(com.artezio.arttime.exceptions.ActualTimeRemovalException) HourType(com.artezio.arttime.datamodel.HourType) WebCached(com.artezio.arttime.admin_tool.cache.WebCached) Log(com.artezio.arttime.admin_tool.log.Log) FacesMessage(com.artezio.arttime.web.interceptors.FacesMessage)

Example 2 with HourType

use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.

the class EmployeeEffortsSpreadSheetTest method testCalculateKeysOfTotals.

@Test
public void testCalculateKeysOfTotals() throws NoSuchFieldException {
    Date date = new Date(2017, 1, 1);
    Employee employee = new Employee("test");
    Project project = new Project();
    HourType hourType = new HourType("test");
    List<Hours> hours = Collections.singletonList(new Hours(project, date, employee, hourType));
    List<Integer> expected = Collections.singletonList(employee.hashCode() + project.hashCode() + hourType.hashCode() + 1237);
    List<HoursSpreadSheetRow> hoursSpreadSheetRows = Collections.singletonList(new HoursSpreadSheetRow(project, employee, hourType, hours));
    TotalsSpreadSheetRow totalRow = new TotalsSpreadSheetRow(project, hourType, hoursSpreadSheetRows);
    totalRow.setEmployee(employee);
    List<SpreadSheetRow> spreadSheetRows = Arrays.asList(new HeadSpreadSheetRow(employee), new HoursSpreadSheetRow(project, employee, hourType, hours), totalRow);
    spreadSheet = new EmployeeEffortsSpreadSheet(hoursRepository, projectRepository, hourTypeRepository, employeeRepository, projectService, workTimeService, filter);
    setField(spreadSheet, "rows", spreadSheetRows);
    SpreadSheetRow spreadSheetRow = new HoursSpreadSheetRow(project, employee, hourType, hours);
    List<Integer> actual = spreadSheet.calculateKeysOfTotalsRows(spreadSheetRow);
    ListAssert.assertEquals(expected, actual);
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Example 3 with HourType

use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.

the class EmployeeEffortsSpreadSheetTest method testBuildSpreadSheetRows.

@Test
public void testBuildSpreadSheetRows() throws ParseException, NoSuchFieldException {
    Employee employee1 = filter.getEmployees().get(0);
    Employee employee2 = filter.getEmployees().get(1);
    Project project1 = filter.getProjects().get(0);
    Project project2 = filter.getProjects().get(1);
    HourType hourType1 = filter.getHourTypes().get(0);
    HourType hourType2 = filter.getHourTypes().get(1);
    spreadSheet = new EmployeeEffortsSpreadSheet(hoursRepository, projectRepository, hourTypeRepository, employeeRepository, projectService, workTimeService, filter);
    setField(spreadSheet, "rows", new LinkedList<SpreadSheetRow>());
    List<Hours> hours = getHours();
    expect(hoursRepository.getHours(filter)).andReturn(hours);
    Map<Project, List<Project>> subprojects = new HashMap<>();
    expect(projectRepository.getSubprojectsMap(EasyMock.anyObject(List.class))).andReturn(subprojects).anyTimes();
    expect(workTimeService.getEmployees(filter)).andReturn(Arrays.asList(employee1, employee2));
    replay(hoursRepository, projectRepository, workTimeService);
    List<SpreadSheetRow<?>> actual = spreadSheet.buildSpreadSheetRows(employee1);
    verify(hoursRepository, projectRepository);
    SpreadSheetRow<?> expected1 = new HeadSpreadSheetRow(employee1);
    SpreadSheetRow<?> expected2 = createSpreadSheetRow(project1, employee1, hourType1, findHours(hours, project1, employee1, hourType1));
    SpreadSheetRow<?> expected3 = createSpreadSheetRow(project1, employee1, hourType2, findHours(hours, project1, employee1, hourType2));
    SpreadSheetRow<?> expected4 = createSpreadSheetRow(project2, employee1, hourType1, findHours(hours, project2, employee1, hourType1));
    SpreadSheetRow<?> expected5 = createTotalsSpreadSheetRow(employee1, hourType1, Arrays.asList((HoursSpreadSheetRow) expected2, (HoursSpreadSheetRow) expected4));
    SpreadSheetRow<?> expected6 = createTotalsSpreadSheetRow(employee1, hourType2, Arrays.asList((HoursSpreadSheetRow) expected3));
    SpreadSheetRow<?> expected7 = new HeadSpreadSheetRow(employee2);
    SpreadSheetRow<?> expected8 = createSpreadSheetRow(project2, employee2, hourType1, findHours(hours, project2, employee2, hourType1));
    SpreadSheetRow<?> expected9 = createTotalsSpreadSheetRow(employee2, hourType1, Arrays.asList((HoursSpreadSheetRow) expected8));
    assertEquals(9, actual.size());
    assertEquals(expected1, actual.get(0));
    assertEquals(expected2, actual.get(1));
    assertEquals(expected3, actual.get(2));
    assertEquals(expected4, actual.get(3));
    assertEquals(expected5, actual.get(4));
    assertEquals(expected6, actual.get(5));
    assertEquals(expected7, actual.get(6));
    assertEquals(expected8, actual.get(7));
    assertEquals(expected9, actual.get(8));
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Example 4 with HourType

use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.

the class PersonalEffortsSpreadSheetTest method testGetValue_FromHoursSpreadSheetRow_EmployeeIsTeamMember.

@Test
public void testGetValue_FromHoursSpreadSheetRow_EmployeeIsTeamMember() {
    Project prj = new Project();
    Employee emp = new Employee();
    prj.getTeam().add(emp);
    HourType hourType = new HourType();
    Date date = new Date();
    List<Hours> hours = Collections.singletonList(new Hours(prj, date, emp, hourType));
    HoursSpreadSheetRow hoursSpreadSheetRow = new HoursSpreadSheetRow(prj, emp, hourType, hours);
    Hours expected = hours.get(0);
    Object actual = spreadSheet.getValue(hoursSpreadSheetRow, date);
    assertEquals(Hours.class, actual.getClass());
    assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Test(org.junit.Test)

Example 5 with HourType

use of com.artezio.arttime.datamodel.HourType in project ART-TIME by Artezio.

the class PersonalEffortsSpreadSheetTest method testCalculateKeysOfTotals.

@Test
public void testCalculateKeysOfTotals() throws NoSuchFieldException {
    Date date = new Date(2017, 1, 1);
    Employee employee = new Employee("test");
    Project project = new Project();
    HourType hourType = new HourType("test");
    List<Hours> hours = Collections.singletonList(new Hours(project, date, employee, hourType));
    List<Integer> expected = Collections.singletonList(employee.hashCode() + project.hashCode() + hourType.hashCode() + 1237);
    List<HoursSpreadSheetRow> hoursSpreadSheetRows = Collections.singletonList(new HoursSpreadSheetRow(project, employee, hourType, hours));
    TotalsSpreadSheetRow totalRow = new TotalsSpreadSheetRow(project, hourType, hoursSpreadSheetRows);
    totalRow.setEmployee(employee);
    List<SpreadSheetRow> spreadSheetRows = Arrays.asList(new HeadSpreadSheetRow(employee), new HoursSpreadSheetRow(project, employee, hourType, hours), totalRow);
    spreadSheet = new PersonalEffortsSpreadSheet(hoursRepository, projectRepository, hourTypeRepository, employeeRepository, workTimeService, filter);
    setField(spreadSheet, "rows", spreadSheetRows);
    SpreadSheetRow spreadSheetRow = new HoursSpreadSheetRow(project, employee, hourType, hours);
    List<Integer> actual = spreadSheet.calculateKeysOfTotalsRows(spreadSheetRow);
    ListAssert.assertEquals(expected, actual);
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Aggregations

HourType (com.artezio.arttime.datamodel.HourType)172 Test (org.junit.Test)158 Project (com.artezio.arttime.datamodel.Project)120 Employee (com.artezio.arttime.datamodel.Employee)115 Hours (com.artezio.arttime.datamodel.Hours)103 Date (java.util.Date)60 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)54 Period (com.artezio.arttime.datamodel.Period)45 BigDecimal (java.math.BigDecimal)41 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)21 HashMap (java.util.HashMap)16 HoursRepository (com.artezio.arttime.repositories.HoursRepository)13 Map (java.util.Map)11 Arrays.asList (java.util.Arrays.asList)10 List (java.util.List)10 Filter (com.artezio.arttime.filter.Filter)7 Mail (com.artezio.arttime.services.mailing.Mail)7 ArrayList (java.util.ArrayList)7 HourTypeRepository (com.artezio.arttime.repositories.HourTypeRepository)6 RangePeriodSelector (com.artezio.arttime.web.criteria.RangePeriodSelector)6