public String toString() { return new ToStringBuilder(this).append("commentId", getCommentId()) .append("comment", getComment()).toString(); }
public TimesheetComment(TimesheetCommentId id, String comment) { setComment(comment); setCommentId(id); }
@Transactional @Override public List<ProjectAssignmentStatus> persistTimesheetWeek(Collection<TimesheetEntry> timesheetEntries, TimesheetComment comment, DateRange weekRange, User forUser) { Map<ProjectAssignment, List<TimesheetEntry>> timesheetRows = getTimesheetAsRows(timesheetEntries); List<ProjectAssignmentStatus> errorStatusses = new ArrayList<>(); Seq<Interval> lockedDatesInRange = timesheetLockService.findLockedDatesInRange(weekRange.getDateStart(), weekRange.getDateEnd(), forUser); List<Date> lockedDates = TimesheetLockService$.MODULE$.intervalToJavaDates(lockedDatesInRange); for (Map.Entry<ProjectAssignment, List<TimesheetEntry>> entry : timesheetRows.entrySet()) { try { getTimesheetPersister().validateAndPersist(entry.getKey(), entry.getValue(), weekRange, lockedDates); } catch (OverBudgetException e) { errorStatusses.add(e.getStatus()); } } // only update the comment when // - the whole week is not locked // - comment is an update // - or the comment is empty boolean wholeWeekLocked = TimesheetLockService$.MODULE$.isRangeLocked(weekRange.getDateStart(), weekRange.getDateEnd(), lockedDatesInRange); if (!wholeWeekLocked && (!comment.getNewComment() || StringUtils.isNotBlank(comment.getComment()))) { timesheetCommentDAO.persist(comment); } return errorStatusses; }
@Test public void should_find_entries_in_range_for_users() { Interval i = new Interval(new LocalDate(2007, DateTimeConstants.JANUARY, 1).toDateTimeAtCurrentTime(), new LocalDate(2007, DateTimeConstants.JANUARY, 30).toDateTimeAtCurrentTime()); List<TimesheetComment> comments = timesheetCommentDao.findCommentBetweenForUsers(Lists.newArrayList(2, 3), new DateRange(i)); assertEquals(2, comments.get(0).getCommentId().getUserId().intValue()); assertEquals(3, comments.get(1).getCommentId().getUserId().intValue()); } }
@Test public void should_not_persist_comment_when_whole_week_is_locked() 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); withLock(new Interval(baseDate, end)); persister.persistTimesheetWeek(newEntries, comment, new DateRange(s, e), user); verify(timesheetDAO, never()).persist((any(TimesheetEntry.class))); verify(commentDao, never()).persist(any(TimesheetComment.class)); }
@Test public void should_find_entries_in_range() { Interval i = new Interval(new LocalDate(2007, DateTimeConstants.JANUARY, 13).toDateTimeAtCurrentTime(), new LocalDate(2007, DateTimeConstants.JANUARY, 22).toDateTimeAtCurrentTime()); List<TimesheetComment> comments = timesheetCommentDao.findCommentBetween(new DateRange(i)); assertEquals(2, comments.size()); assertThat(comments.get(0).getCommentId().getCommentDate().toString(), startsWith("2007-01-14")); assertThat(comments.get(1).getCommentId().getCommentDate().toString(), startsWith("2007-01-21")); }
@Test public void should_not_persist_when_whole_week_is_locked() 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); withLock(new Interval(baseDate, end)); persister.persistTimesheetWeek(newEntries, comment, new DateRange(s, e), user); verify(timesheetDAO, never()).persist((any(TimesheetEntry.class))); }
/** * @see java.lang.Comparable#compareTo(Object) */ public int compareTo(TimesheetComment object) { return new CompareToBuilder() .append(this.getComment(), object.getComment()) .append(this.getCommentId(), object.getCommentId()).toComparison(); }
@Test public void should_persist_individual_timesheet_entries_for_a_week() { TimesheetCommentId commentId = new TimesheetCommentId(1, new Date()); TimesheetComment comment = new TimesheetComment(commentId, "comment"); when(context.getBean(IPersistTimesheet.class)).thenReturn(persister); // through Spring for new TX per entr=y okStatus(); noLocks(); persister.persistTimesheetWeek(newEntries, comment, new DateRange(), UserObjectMother.createUser()); verify(commentDao).persist(comment); }
@Test public void should_get_timesheet_entries() { Date da = new Date(2006 - 1900, Calendar.DECEMBER, 31); Date db = new Date(2007 - 1900, Calendar.JANUARY, 6); DateRange range = new DateRange(da, db); DateRange rangeB = new DateRange(new Date(2006 - 1900, Calendar.DECEMBER, 31), new Date(2007 - 1900, Calendar.JANUARY, 6)); when(timesheetDAO.getTimesheetEntriesInRange(1, range)).thenReturn(new ArrayList<TimesheetEntry>()); when(timesheetCommentDAO.findById(new TimesheetCommentId(1, range.getDateStart()))).thenReturn(new TimesheetComment()); when(projectAssignmentService.getProjectAssignmentsForUser(1, rangeB)).thenReturn(new ArrayList<ProjectAssignment>()); when(config.getFirstDayOfWeek()).thenReturn(1); when(timesheetLockService.findLockedDatesInRange(any(Date.class), any(Date.class), any(User.class))).thenReturn(new Vector<Interval>(0, 0, 1)); timesheetService.getWeekOverview(new User(1), new GregorianCalendar(2007, Calendar.JANUARY, 1)); verify(timesheetDAO).getTimesheetEntriesInRange(1, range); verify(timesheetCommentDAO).findById(new TimesheetCommentId(1, range.getDateStart())); verify(projectAssignmentService).getProjectAssignmentsForUser(1, rangeB); verify(config).getFirstDayOfWeek(); verify(timesheetLockService).findLockedDatesInRange(any(Date.class), any(Date.class), any(User.class)); } }
@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)); }