public boolean equals(Object other) { if ((this == other)) { return true; } if (!(other instanceof TimesheetCommentId)) { return false; } TimesheetCommentId castOther = (TimesheetCommentId) other; return new EqualsBuilder().append(this.getUserId(), castOther.getUserId()).append(this.getCommentDate(), castOther.getCommentDate()).isEquals(); }
public TimesheetCommentId(Integer userId, Date commentDate) { setUserId(userId); setCommentDate(commentDate); }
@SuppressWarnings("deprecation") @Test public void should_get_timesheet_comments_for_date() { TimesheetComment comment = timesheetCommentDao.findById(new TimesheetCommentId(1, new Date(2007 - 1900, Calendar.JANUARY, 7))); assertNotNull(comment); }
@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_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_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)); }
public String toString() { return new ToStringBuilder(this).append("userId", getUserId()) .append("commentDate", getCommentDate()).toString(); }
@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))); }
public int hashCode() { return new HashCodeBuilder().append(getUserId()).append(getCommentDate()).toHashCode(); }
@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)); } }
/** * @see java.lang.Comparable#compareTo(Object) */ public int compareTo(TimesheetCommentId object) { return new CompareToBuilder() .append(this.getCommentDate(), object.getCommentDate()) .append(this.getUserId(), object.getUserId()).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_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)); }
/** * Get week overview for a date. Week number of supplied requested week is used */ public WeekOverview getWeekOverview(User user, Calendar requestedWeek) { Calendar reqWeek = (Calendar) requestedWeek.clone(); reqWeek.setFirstDayOfWeek(configuration.getFirstDayOfWeek()); DateRange range = DateUtil.getDateRangeForWeek(reqWeek); List<TimesheetEntry> timesheetEntries = timesheetDAO.getTimesheetEntriesInRange(user.getUserId(), range); TimesheetComment comment = timesheetCommentDAO.findById(new TimesheetCommentId(user.getUserId(), range.getDateStart())); List<ProjectAssignment> assignments = projectAssignmentService.getProjectAssignmentsForUser(user.getUserId(), range); Seq<Interval> lockedDatesAsIntervals = timesheetLockService.findLockedDatesInRange(range.getDateStart(), range.getDateEnd(), user); List<Date> lockedDates = TimesheetLockService$.MODULE$.intervalToJavaDates(lockedDatesAsIntervals); return new WeekOverview(timesheetEntries, comment, assignments, range, user, lockedDates); } }