@Test public void testValues() { final long nowInMs = new Date().getTime(); final long msInDay = 86400000L; final long count = 15; getEntityManager().createQuery("DELETE FROM DailyUsageSummary").executeUpdate(); getEntityManager().flush(); for (int i = 1; i <= 2; i++) { DailyUsageSummary foo = new DailyUsageSummary(); foo.setMessageCount(count * i); foo.setPageViewCount(count * i); foo.setStreamContributorCount(count * i); foo.setStreamViewCount(count * i); foo.setStreamViewerCount(count * i); foo.setUniqueVisitorCount(count * i); foo.setUsageDate(new Date(nowInMs - i * msInDay)); foo.setAvgActivityResponseTime(count * i); foo.setUsageDateTimeStampInMs(1308238511000L); foo.setStreamViewStreamScopeId(null); getEntityManager().persist(foo); getEntityManager().flush(); assertTrue(foo.getId() > 0); } getEntityManager().persist( new DailyUsageSummary(1, 2, 3, 4, 5, 6, 7, new Date(nowInMs - 1 * msInDay), 1308238511000L, 3L, 1L, 2L, 5L)); getEntityManager().persist( new DailyUsageSummary(1, 2, 3, 4, 5, 6, 7, new Date(nowInMs - 1 * msInDay), 1308238511000L, 4L, 1L, 2L, 5L)); getEntityManager().persist( new DailyUsageSummary(1, 2, 3, 4, 5, 6, 7, new Date(nowInMs - 1 * msInDay), 1308238511000L, 5L, 1L, 2L, 5L)); getEntityManager().flush(); getEntityManager().clear(); final int ten = 10; List<DailyUsageSummary> results = sut.execute(new UsageMetricStreamSummaryRequest(ten, null)); assertEquals(2, results.size()); assertEquals(count * 2, results.get(0).getMessageCount()); assertEquals(count * 1, results.get(1).getMessageCount()); }
@SuppressWarnings("unchecked") @Override public List<DailyUsageSummary> execute(final UsageMetricStreamSummaryRequest inRequest) { Query q; if (inRequest.getStreamRecipientStreamScopeId() == null) { q = getEntityManager().createQuery( "FROM DailyUsageSummary WHERE streamViewStreamScopeId IS NULL " + "AND usageDate >= :usageDate ORDER BY usageDate ASC"); } else { q = getEntityManager().createQuery( "FROM DailyUsageSummary WHERE streamViewStreamScopeId = :streamViewStreamScopeId " + "AND usageDate >= :usageDate ORDER BY usageDate ASC").setParameter( "streamViewStreamScopeId", inRequest.getStreamRecipientStreamScopeId()); } Calendar day = Calendar.getInstance(); day.add(Calendar.DATE, -inRequest.getNumberOfDays()); Date oldestReportDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); q.setParameter("usageDate", oldestReportDate); return q.getResultList(); }
GetUsageMetricSummaryDbMapper extends
        BaseArgDomainMapper<UsageMetricStreamSummaryRequest, List<DailyUsageSummary>> { @SuppressWarnings("unchecked") @Override public List<DailyUsageSummary> execute(final UsageMetricStreamSummaryRequest inRequest) { Query q; if (inRequest.getStreamRecipientStreamScopeId() == null) { q = getEntityManager().createQuery( "FROM DailyUsageSummary WHERE streamViewStreamScopeId IS NULL " + "AND usageDate >= :usageDate ORDER BY usageDate ASC"); } else { q = getEntityManager().createQuery( "FROM DailyUsageSummary WHERE streamViewStreamScopeId = :streamViewStreamScopeId " + "AND usageDate >= :usageDate ORDER BY usageDate ASC").setParameter( "streamViewStreamScopeId", inRequest.getStreamRecipientStreamScopeId()); } Calendar day = Calendar.getInstance(); day.add(Calendar.DATE, -inRequest.getNumberOfDays()); Date oldestReportDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); q.setParameter("usageDate", oldestReportDate); return q.getResultList(); } }
GetUsageMetricSummaryDbMapper extends
        BaseArgDomainMapper<UsageMetricStreamSummaryRequest, List<DailyUsageSummary>> { @SuppressWarnings("unchecked") @Override public List<DailyUsageSummary> execute(final UsageMetricStreamSummaryRequest inRequest) { Query q; if (inRequest.getStreamRecipientStreamScopeId() == null) { q = getEntityManager().createQuery( "FROM DailyUsageSummary WHERE streamViewStreamScopeId IS NULL " + "AND usageDate >= :usageDate ORDER BY usageDate ASC"); } else { q = getEntityManager().createQuery( "FROM DailyUsageSummary WHERE streamViewStreamScopeId = :streamViewStreamScopeId " + "AND usageDate >= :usageDate ORDER BY usageDate ASC").setParameter( "streamViewStreamScopeId", inRequest.getStreamRecipientStreamScopeId()); } Calendar day = Calendar.getInstance(); day.add(Calendar.DATE, -inRequest.getNumberOfDays()); Date oldestReportDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); q.setParameter("usageDate", oldestReportDate); return q.getResultList(); }  }
GetUsageMetricSummaryDbMapper extends
        BaseArgDomainMapper<UsageMetricStreamSummaryRequest, List<DailyUsageSummary>> { @SuppressWarnings("unchecked") @Override public List<DailyUsageSummary> execute(final UsageMetricStreamSummaryRequest inRequest) { Query q; if (inRequest.getStreamRecipientStreamScopeId() == null) { q = getEntityManager().createQuery( "FROM DailyUsageSummary WHERE streamViewStreamScopeId IS NULL " + "AND usageDate >= :usageDate ORDER BY usageDate ASC"); } else { q = getEntityManager().createQuery( "FROM DailyUsageSummary WHERE streamViewStreamScopeId = :streamViewStreamScopeId " + "AND usageDate >= :usageDate ORDER BY usageDate ASC").setParameter( "streamViewStreamScopeId", inRequest.getStreamRecipientStreamScopeId()); } Calendar day = Calendar.getInstance(); day.add(Calendar.DATE, -inRequest.getNumberOfDays()); Date oldestReportDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); q.setParameter("usageDate", oldestReportDate); return q.getResultList(); }  @SuppressWarnings("unchecked") @Override List<DailyUsageSummary> execute(final UsageMetricStreamSummaryRequest inRequest); }
GetUsageMetricSummaryDbMapper extends
        BaseArgDomainMapper<UsageMetricStreamSummaryRequest, List<DailyUsageSummary>> { @SuppressWarnings("unchecked") @Override public List<DailyUsageSummary> execute(final UsageMetricStreamSummaryRequest inRequest) { Query q; if (inRequest.getStreamRecipientStreamScopeId() == null) { q = getEntityManager().createQuery( "FROM DailyUsageSummary WHERE streamViewStreamScopeId IS NULL " + "AND usageDate >= :usageDate ORDER BY usageDate ASC"); } else { q = getEntityManager().createQuery( "FROM DailyUsageSummary WHERE streamViewStreamScopeId = :streamViewStreamScopeId " + "AND usageDate >= :usageDate ORDER BY usageDate ASC").setParameter( "streamViewStreamScopeId", inRequest.getStreamRecipientStreamScopeId()); } Calendar day = Calendar.getInstance(); day.add(Calendar.DATE, -inRequest.getNumberOfDays()); Date oldestReportDate = DateDayExtractor.getStartOfDay(new Date(day.getTimeInMillis())); q.setParameter("usageDate", oldestReportDate); return q.getResultList(); }  @SuppressWarnings("unchecked") @Override List<DailyUsageSummary> execute(final UsageMetricStreamSummaryRequest inRequest);  }