public String toString() { return new ToStringBuilder(this) .append("hours", this.getHours()) .append("entryId", this.getEntryId()) .append("comment", this.getComment()) .append("updateDate", this.getUpdateDate()) .toString(); }
private void persistEntry(boolean bookOnlyLessHoursThanExistingHours, TimesheetEntry newEntry, TimesheetEntry existingEntry) throws OverBudgetException { if (bookOnlyLessHoursThanExistingHours && (existingEntry == null || (newEntry.getHours().compareTo(existingEntry.getHours()) > 0))) { throw new OverBudgetException(); } newEntry.setUpdateDate(new Date()); if (existingEntry != null) { timesheetDAO.merge(newEntry); } else { timesheetDAO.persist(newEntry); } }
private void persistEntries(ProjectAssignment assignment, List<TimesheetEntry> entries, DateRange weekRange, boolean onlyLessThanExisting, List<Date> lockedDates) throws OverBudgetException { List<TimesheetEntry> previousEntries = Lists.newArrayList(timesheetDAO.getTimesheetEntriesInRange(assignment, weekRange)); for (TimesheetEntry entry : entries) { if (!entry.getEntryId().getProjectAssignment().equals(assignment)) { LOGGER.error("Invalid entry in assignment list, skipping: " + entry); previousEntries.remove(entry); continue; } if (lockedDates.contains(entry.getEntryId().getEntryDate())) { LOGGER.error("Date is locked but still trying to update " + entry); previousEntries.remove(entry); continue; } if (!entry.isEmptyEntry()) { persistEntry(onlyLessThanExisting, entry, getEntry(previousEntries, entry)); previousEntries.remove(entry); } } removeOldEntries(previousEntries); }
public static TimesheetEntry createTimesheetEntry(int prjId, Date date, float hours) { TimesheetEntryId id = new TimesheetEntryId(); id.setEntryDate(date); id.setProjectAssignment(ProjectAssignmentObjectMother.createProjectAssignment(prjId, prjId, 1)); TimesheetEntry entry = new TimesheetEntry(); entry.setEntryId(id); entry.setHours(hours); return entry; }
@Test public void shouldParseTwoTimesheetEntries() throws XMLStreamException, InstantiationException, IllegalAccessException, ImportException { EntityParser parser = createParser("<TIMESHEET_ENTRIES CLASS=\"net.rrm.ehour.domain.TimesheetEntry\">\n<TIMESHEET_ENTRY>\n<ASSIGNMENT_ID>1</ASSIGNMENT_ID>\n<ENTRY_DATE>2007-03-26</ENTRY_DATE>\n<HOURS>8.0</HOURS>\n <COMMENT>jaja</COMMENT>\n </TIMESHEET_ENTRY>\n <TIMESHEET_ENTRY>\n <ASSIGNMENT_ID>2</ASSIGNMENT_ID>\n <ENTRY_DATE>2007-03-26</ENTRY_DATE>\n <HOURS>0.0</HOURS>\n </TIMESHEET_ENTRY>\n </TIMESHEET_ENTRIES>\n", ProjectAssignmentObjectMother.createProjectAssignment(1), 1); keyCache.putKey(ProjectAssignment.class, 1, 1); keyCache.putKey(ProjectAssignment.class, 2, 2); List<TimesheetEntry> result = parser.parse(TimesheetEntry.class, new JoinTables(), status); assertEquals(2, result.size()); assertNotNull(result.get(0).getEntryId().getEntryDate()); assertNotNull(result.get(0).getEntryId().getProjectAssignment()); assertEquals(8.0, result.get(0).getHours(), 0); assertEquals("jaja", result.get(0).getComment()); assertEquals(2, daoValidator.getTotalPersistCount()); }
@Override public boolean equals(final Object other) { if (!(other instanceof TimesheetEntry)) return false; TimesheetEntry castOther = (TimesheetEntry) other; return new EqualsBuilder().append(getEntryId(), castOther.getEntryId()).isEquals(); }
public boolean isEmptyEntry() { return getHours() == null; }
@Test public final void testGetAssignmentStatusDateOut() { ProjectAssignment assignment = ProjectAssignmentObjectMother.createProjectAssignment(1); ProjectAssignmentType type = new ProjectAssignmentType(); type.setAssignmentTypeId(EhourConstants.ASSIGNMENT_DATE); assignment.setAssignmentType(type); Calendar startCal = new GregorianCalendar(); startCal.add(Calendar.DAY_OF_YEAR, -5); assignment.setDateStart(startCal.getTime()); Date start = startCal.getTime(); Calendar endCal = new GregorianCalendar(); endCal.add(Calendar.DAY_OF_YEAR, -2); assignment.setDateEnd(endCal.getTime()); Date end = endCal.getTime(); when(timesheetDAO.getTimesheetEntriesBefore(assignment, start)) .thenReturn(new ArrayList<TimesheetEntry>()); List<TimesheetEntry> entry = new ArrayList<>(); entry.add(new TimesheetEntry()); when(timesheetDAO.getTimesheetEntriesAfter(assignment, end)) .thenReturn(entry); ProjectAssignmentStatus status = util.getAssignmentStatus(assignment); assertTrue(status.getStatusses().contains(ProjectAssignmentStatus.Status.AFTER_DEADLINE)); assertEquals(1, status.getStatusses().size()); }
@Test public void should_process_column_with_embeddable() throws InstantiationException, IllegalAccessException { FieldMap fieldDefinitionMap = FieldMapFactory.buildFieldMapForEntity(TimesheetEntry.class); FieldDefinition fieldDef = fieldDefinitionMap.get("assignment_id"); TimesheetEntry timesheetEntry = TimesheetEntryObjectMother.createTimesheetEntry(1, new Date(), 5f); timesheetEntry.setEntryId(null); Map<Class<?>, Object> embeddables = Maps.newHashMap(); ProjectAssignment projectAssignment = ProjectAssignmentObjectMother.createProjectAssignment(1); fieldDef.process(timesheetEntry, embeddables, projectAssignment); assertEquals(projectAssignment, ((TimesheetEntryId) embeddables.get(TimesheetEntryId.class)).getProjectAssignment()); } }
public static TimesheetEntry createTimesheetEntry(User user, Date date, float hours) { TimesheetEntryId id = new TimesheetEntryId(); id.setEntryDate(date); ProjectAssignment projectAssignment = ProjectAssignmentObjectMother.createProjectAssignment(1, 1, 1); projectAssignment.setUser(user); id.setProjectAssignment(projectAssignment); TimesheetEntry entry = new TimesheetEntry(); entry.setEntryId(id); entry.setHours(hours); return entry; }
private Map<ProjectAssignment, List<TimesheetEntry>> getTimesheetAsRows(Collection<TimesheetEntry> entries) { Map<ProjectAssignment, List<TimesheetEntry>> timesheetRows = new HashMap<>(); for (TimesheetEntry timesheetEntry : entries) { ProjectAssignment assignment = timesheetEntry.getEntryId().getProjectAssignment(); List<TimesheetEntry> assignmentEntries = (timesheetRows.containsKey(assignment)) ? timesheetRows.get(assignment) : new ArrayList<TimesheetEntry>(); assignmentEntries.add(timesheetEntry); timesheetRows.put(assignment, assignmentEntries); } return timesheetRows; }
@Test public void shouldGetLatestTimesheetEntryForAssignment() { TimesheetEntry entry = timesheetDAO.getLatestTimesheetEntryForAssignment(1); assertEquals(9.2f, entry.getHours(), 0.01f); }
@Test public void should_get_timesheet_overview() throws Exception { List<TimesheetEntry> daoResults = new ArrayList<>(); List<AssignmentAggregateReportElement> reportResults = new ArrayList<>(); Calendar cal = new GregorianCalendar(); TimesheetEntry entryA, entryB; TimesheetEntryId idA, idB; idA = new TimesheetEntryId(new Date(2006 - 1900, Calendar.OCTOBER, 2), null); entryA = new TimesheetEntry(); entryA.setEntryId(idA); entryA.setHours((float) 5); daoResults.add(entryA); idB = new TimesheetEntryId(new Date(2006 - 1900, Calendar.OCTOBER, 6), null); entryB = new TimesheetEntry(); entryB.setEntryId(idB); entryB.setHours((float) 3); daoResults.add(entryB); AssignmentAggregateReportElement agg = new AssignmentAggregateReportElement(); ProjectAssignment pa = ProjectAssignmentObjectMother.createProjectAssignment(0); agg.setProjectAssignment(pa); reportResults.add(agg); when(timesheetDAO.getTimesheetEntriesInRange(1, DateUtil.calendarToMonthRange(cal))).thenReturn(daoResults); when(aggregateReportService.getHoursPerAssignmentInRange(1, DateUtil.calendarToMonthRange(cal))).thenReturn(reportResults); timesheetService.getTimesheetOverview(new User(1), cal); verify(timesheetDAO).getTimesheetEntriesInRange(1, DateUtil.calendarToMonthRange(cal)); verify(aggregateReportService).getHoursPerAssignmentInRange(1, DateUtil.calendarToMonthRange(cal)); }
private Map<ProjectAssignment, Map<String, TimesheetEntry>> createAssignmentMap() { Map<ProjectAssignment, Map<String, TimesheetEntry>> assignmentMap = new HashMap<>(); for (TimesheetEntry entry : getTimesheetEntries()) { ProjectAssignment assignment = entry.getEntryId().getProjectAssignment(); Map<String, TimesheetEntry> entryDateMap = assignmentMap.containsKey(assignment) ? assignmentMap.get(assignment) : new HashMap<String, TimesheetEntry>(); entryDateMap.put(formatter.format(entry.getEntryId().getEntryDate()), entry); assignmentMap.put(assignment, entryDateMap); } return assignmentMap; }
TimesheetEntry entry = new TimesheetEntry(); TimesheetEntryId id = new TimesheetEntryId(); id.setProjectAssignment(assignment); id.setEntryDate(dateA); entry.setEntryId(id); entry.setHours(8f); newEntries.add(entry); TimesheetEntry entryDel = new TimesheetEntry(); TimesheetEntryId idDel = new TimesheetEntryId(); idDel.setProjectAssignment(assignment); idDel.setEntryDate(dateB); entryDel.setEntryId(idDel); entryDel.setHours(null); newEntries.add(entryDel); TimesheetEntry entry = new TimesheetEntry(); TimesheetEntryId id = new TimesheetEntryId(); id.setProjectAssignment(assignment); id.setEntryDate(dateA); entry.setEntryId(id); entry.setHours(5f); existingEntries.add(entry); TimesheetEntry entryDel = new TimesheetEntry(); TimesheetEntryId idDel = new TimesheetEntryId(); idDel.setProjectAssignment(assignment); idDel.setEntryDate(dateB); entryDel.setEntryId(idDel);
public int compareTo(TimesheetEntry object) { return new CompareToBuilder() .append(this.getEntryId(), object.getEntryId()).toComparison(); }
@Test public void should_not_persist_for_locked_day() throws OverBudgetException { okStatus(); TimesheetCommentId commentId = new TimesheetCommentId(1, new Date()); TimesheetComment comment = new TimesheetComment(commentId, "comment"); Date s = baseDate.toDate(); DateTime end = baseDate.plusWeeks(1); Date e = end.toDate(); User user = UserObjectMother.createUser(); when(context.getBean(IPersistTimesheet.class)).thenReturn(persister); TimesheetEntry entry = new TimesheetEntry(); TimesheetEntryId id = new TimesheetEntryId(); id.setProjectAssignment(assignment); id.setEntryDate(baseDate.plusDays(2).toDate()); entry.setEntryId(id); entry.setHours(5f); newEntries.add(entry); withLock(new Interval(baseDate.plusDays(2), end));// cancelling out the just created entry persister.persistTimesheetWeek(newEntries, comment, new DateRange(s, e), user); verify(timesheetDAO, times(1)).persist((any(TimesheetEntry.class))); verify(timesheetDAO, never()).delete((any(TimesheetEntry.class))); verify(commentDao, times(1)).persist(any(TimesheetComment.class)); }
/** * Put the timesheet entries in a map where the day is the key and * the value is a list of timesheet entries filled out for that date * * @param timesheetEntries * @return */ private Map<Integer, List<TimesheetEntry>> entriesToCalendarMap(List<TimesheetEntry> timesheetEntries) { Map<Integer, List<TimesheetEntry>> calendarMap; Calendar cal; Integer dayKey; List<TimesheetEntry> dayEntries; calendarMap = new HashMap<>(); for (TimesheetEntry entry : timesheetEntries) { if (entry == null) { continue; } cal = new GregorianCalendar(); cal.setTime(entry.getEntryId().getEntryDate()); dayKey = cal.get(Calendar.DAY_OF_MONTH); if (calendarMap.containsKey(dayKey)) { dayEntries = calendarMap.get(dayKey); } else { dayEntries = new ArrayList<>(); } dayEntries.add(entry); calendarMap.put(dayKey, dayEntries); } return calendarMap; }
TimesheetEntry entryDel = new TimesheetEntry(); TimesheetEntryId idDel = new TimesheetEntryId(); idDel.setProjectAssignment(assignment); idDel.setEntryDate(dateC); entryDel.setEntryId(idDel); entryDel.setHours(7f); newEntries.add(entryDel); TimesheetEntry entryDel = new TimesheetEntry(); TimesheetEntryId idDel = new TimesheetEntryId(); idDel.setProjectAssignment(assignment); idDel.setEntryDate(dateC); entryDel.setEntryId(idDel); entryDel.setHours(8f); existingEntries.add(entryDel);
@Test public void when_finding_should_set_proper_id_for_embeddable_id() { TimesheetEntryId timesheetEntryId = new TimesheetEntryId(new Date(), ProjectAssignmentObjectMother.createProjectAssignment(1)); TimesheetEntry entry = subject.find(timesheetEntryId, TimesheetEntry.class); assertEquals(timesheetEntryId, entry.getEntryId()); }