@Test public void testExecuteActivityDayOld() { Activity a1 = (Activity) getEntityManager().createQuery("FROM Activity WHERE id = 6789").getSingleResult(); Comment a1c1 = (Comment) getEntityManager().createQuery("FROM Comment WHERE id = 1").getSingleResult(); Comment a1c2 = (Comment) getEntityManager().createQuery("FROM Comment WHERE id = 2").getSingleResult(); a1.setPostedTime(new Date(year, 4, 1, 7, 0, 0)); a1c1.setTimeSent(new Date(year, 4, 2, 7, 2, 0)); a1c2.setTimeSent(new Date(year, 4, 2, 7, 4, 0)); getEntityManager().flush(); getEntityManager().clear(); Assert.assertEquals(0, (long) sut.execute(new Date(year, 4, 2))); }
@SuppressWarnings("unchecked") @Override public Long execute(final Date inDate) { Date startOfDay, endOfDay; Query q; startOfDay = DateDayExtractor.getStartOfDay(inDate); endOfDay = DateDayExtractor.getEndOfDay(inDate); q = getEntityManager().createQuery( "SELECT MIN(c.timeSent), MIN(c.target.postedTime) FROM Comment c INNER JOIN c.target " + "WHERE c.timeSent >= :startDate AND c.timeSent <= :endDate AND " + "c.target.postedTime >= :startDate AND c.target.postedTime <= :endDate " + "GROUP BY c.target.id").setParameter("startDate", startOfDay).setParameter("endDate", endOfDay); List<Object[]> results = q.getResultList(); int numResults = results.size(); if (numResults == 0) { return 0L; } Calendar commentDate = Calendar.getInstance(); Calendar activityDate = Calendar.getInstance(); long commentTimeMillis, activityTimeMillis; long timeDiffInMillis = 0; for (Object[] row : results) { commentDate.setTime((Date) row[0]); activityDate.setTime((Date) row[1]); commentTimeMillis = commentDate.getTimeInMillis(); activityTimeMillis = activityDate.getTimeInMillis(); timeDiffInMillis += (commentTimeMillis - activityTimeMillis); } return (timeDiffInMillis / numResults) / millisInAMinute; }
GetDailyMessageResponseTime extends BaseArgDomainMapper<Date, Long> { @SuppressWarnings("unchecked") @Override public Long execute(final Date inDate) { Date startOfDay, endOfDay; Query q; startOfDay = DateDayExtractor.getStartOfDay(inDate); endOfDay = DateDayExtractor.getEndOfDay(inDate); q = getEntityManager().createQuery( "SELECT MIN(c.timeSent), MIN(c.target.postedTime) FROM Comment c INNER JOIN c.target " + "WHERE c.timeSent >= :startDate AND c.timeSent <= :endDate AND " + "c.target.postedTime >= :startDate AND c.target.postedTime <= :endDate " + "GROUP BY c.target.id").setParameter("startDate", startOfDay).setParameter("endDate", endOfDay); List<Object[]> results = q.getResultList(); int numResults = results.size(); if (numResults == 0) { return 0L; } Calendar commentDate = Calendar.getInstance(); Calendar activityDate = Calendar.getInstance(); long commentTimeMillis, activityTimeMillis; long timeDiffInMillis = 0; for (Object[] row : results) { commentDate.setTime((Date) row[0]); activityDate.setTime((Date) row[1]); commentTimeMillis = commentDate.getTimeInMillis(); activityTimeMillis = activityDate.getTimeInMillis(); timeDiffInMillis += (commentTimeMillis - activityTimeMillis); } return (timeDiffInMillis / numResults) / millisInAMinute; } }
GetDailyMessageResponseTime extends BaseArgDomainMapper<Date, Long> { @SuppressWarnings("unchecked") @Override public Long execute(final Date inDate) { Date startOfDay, endOfDay; Query q; startOfDay = DateDayExtractor.getStartOfDay(inDate); endOfDay = DateDayExtractor.getEndOfDay(inDate); q = getEntityManager().createQuery( "SELECT MIN(c.timeSent), MIN(c.target.postedTime) FROM Comment c INNER JOIN c.target " + "WHERE c.timeSent >= :startDate AND c.timeSent <= :endDate AND " + "c.target.postedTime >= :startDate AND c.target.postedTime <= :endDate " + "GROUP BY c.target.id").setParameter("startDate", startOfDay).setParameter("endDate", endOfDay); List<Object[]> results = q.getResultList(); int numResults = results.size(); if (numResults == 0) { return 0L; } Calendar commentDate = Calendar.getInstance(); Calendar activityDate = Calendar.getInstance(); long commentTimeMillis, activityTimeMillis; long timeDiffInMillis = 0; for (Object[] row : results) { commentDate.setTime((Date) row[0]); activityDate.setTime((Date) row[1]); commentTimeMillis = commentDate.getTimeInMillis(); activityTimeMillis = activityDate.getTimeInMillis(); timeDiffInMillis += (commentTimeMillis - activityTimeMillis); } return (timeDiffInMillis / numResults) / millisInAMinute; }  }
GetDailyMessageResponseTime extends BaseArgDomainMapper<Date, Long> { @SuppressWarnings("unchecked") @Override public Long execute(final Date inDate) { Date startOfDay, endOfDay; Query q; startOfDay = DateDayExtractor.getStartOfDay(inDate); endOfDay = DateDayExtractor.getEndOfDay(inDate); q = getEntityManager().createQuery( "SELECT MIN(c.timeSent), MIN(c.target.postedTime) FROM Comment c INNER JOIN c.target " + "WHERE c.timeSent >= :startDate AND c.timeSent <= :endDate AND " + "c.target.postedTime >= :startDate AND c.target.postedTime <= :endDate " + "GROUP BY c.target.id").setParameter("startDate", startOfDay).setParameter("endDate", endOfDay); List<Object[]> results = q.getResultList(); int numResults = results.size(); if (numResults == 0) { return 0L; } Calendar commentDate = Calendar.getInstance(); Calendar activityDate = Calendar.getInstance(); long commentTimeMillis, activityTimeMillis; long timeDiffInMillis = 0; for (Object[] row : results) { commentDate.setTime((Date) row[0]); activityDate.setTime((Date) row[1]); commentTimeMillis = commentDate.getTimeInMillis(); activityTimeMillis = activityDate.getTimeInMillis(); timeDiffInMillis += (commentTimeMillis - activityTimeMillis); } return (timeDiffInMillis / numResults) / millisInAMinute; }  @SuppressWarnings("unchecked") @Override Long execute(final Date inDate); }
GetDailyMessageResponseTime extends BaseArgDomainMapper<Date, Long> { @SuppressWarnings("unchecked") @Override public Long execute(final Date inDate) { Date startOfDay, endOfDay; Query q; startOfDay = DateDayExtractor.getStartOfDay(inDate); endOfDay = DateDayExtractor.getEndOfDay(inDate); q = getEntityManager().createQuery( "SELECT MIN(c.timeSent), MIN(c.target.postedTime) FROM Comment c INNER JOIN c.target " + "WHERE c.timeSent >= :startDate AND c.timeSent <= :endDate AND " + "c.target.postedTime >= :startDate AND c.target.postedTime <= :endDate " + "GROUP BY c.target.id").setParameter("startDate", startOfDay).setParameter("endDate", endOfDay); List<Object[]> results = q.getResultList(); int numResults = results.size(); if (numResults == 0) { return 0L; } Calendar commentDate = Calendar.getInstance(); Calendar activityDate = Calendar.getInstance(); long commentTimeMillis, activityTimeMillis; long timeDiffInMillis = 0; for (Object[] row : results) { commentDate.setTime((Date) row[0]); activityDate.setTime((Date) row[1]); commentTimeMillis = commentDate.getTimeInMillis(); activityTimeMillis = activityDate.getTimeInMillis(); timeDiffInMillis += (commentTimeMillis - activityTimeMillis); } return (timeDiffInMillis / numResults) / millisInAMinute; }  @SuppressWarnings("unchecked") @Override Long execute(final Date inDate);  }