@Test public void test() { List<StreamDTO> results = sut.execute(10); Assert.assertEquals(2L, results.size()); StreamDTO dto1 = results.get(0); StreamDTO dto2 = results.get(1); Assert.assertEquals("fordp2", dto1.getUniqueId()); Assert.assertEquals("fordp", dto2.getUniqueId()); Assert.assertEquals(66667, dto1.getFollowersCount()); Assert.assertEquals(33334, dto2.getFollowersCount()); }
@Override public List<StreamDTO> execute(final Serializable inIgnored) { List<StreamDTO> results = new ArrayList<StreamDTO>(); Query q; q = getEntityManager().createQuery( "SELECT dus.streamViewStreamScopeId, " + "sum(dus.streamViewerCount * 1.0)/max(week.numberOfWeekdaysSinceDate * 1.0) " + "FROM DailyUsageSummary dus, TempWeekdaysSinceDate week " + "WHERE dus.streamViewStreamScopeId IS NOT NULL " + "AND week.numberOfWeekdaysSinceDate IS NOT NULL AND dus.streamViewerCount IS NOT NULL " + "AND dus.usageDateTimeStampInMs = week.dateTimeStampInMilliseconds " + "GROUP BY streamViewStreamScopeId HAVING MAX(week.numberOfWeekdaysSinceDate * 1.0) > 0 " + "AND sum(dus.streamViewerCount * 1.0) > 0 " + "ORDER BY SUM(dus.streamViewerCount * 1.0)/MAX(week.numberOfWeekdaysSinceDate * 1.0) DESC"); if (streamCount > 0) { q.setMaxResults(streamCount); } List<Object[]> streamObjs = q.getResultList(); List<Long> streamScopeIds = new ArrayList<Long>(); for (Object[] streamObj : streamObjs) { streamScopeIds.add((Long) streamObj[0]); } if (streamScopeIds.size() == 0) { return results; } List<StreamDTO> streamDtos = new ArrayList<StreamDTO>(); q = getEntityManager().createQuery( "SELECT new org.eurekastreams.server.search.modelview.PersonModelView(id, accountId, " + "preferredName, lastName, displayName, displayNameSuffix, followersCount, " + "dateAdded, streamScope.id) FROM Person " + "WHERE streamScope.id IN(:streamScopeIds)") .setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); q = getEntityManager().createQuery( "SELECT new org.eurekastreams.server.search.modelview.DomainGroupModelView(id, " + "shortName, name, 0, dateAdded, streamScope.id, publicGroup) FROM DomainGroup " + "WHERE streamScope.id IN(:streamScopeIds)").setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); Long streamScopeId, viewerCount; for (Object[] streamObj : streamObjs) { streamScopeId = (Long) streamObj[0]; viewerCount = -1L; if (streamObj[1] != null) { viewerCount = Math.round(Math.ceil((Double) streamObj[1])); } if (viewerCount > -1) { for (StreamDTO streamDTO : streamDtos) { if (streamDTO.getStreamScopeId().equals(streamScopeId)) { if (streamDTO.getEntityType() == EntityType.PERSON) { ((PersonModelView) streamDTO).setFollowersCount(viewerCount.intValue()); } else if (streamDTO.getEntityType() == EntityType.GROUP) { ((DomainGroupModelView) streamDTO).setFollowersCount(viewerCount.intValue()); } results.add(streamDTO); break; } } } } return results; }
GetStreamsByDailyAverageViewersDbMapper extends BaseArgDomainMapper<Serializable, List<StreamDTO>> { @Override public List<StreamDTO> execute(final Serializable inIgnored) { List<StreamDTO> results = new ArrayList<StreamDTO>(); Query q; q = getEntityManager().createQuery( "SELECT dus.streamViewStreamScopeId, " + "sum(dus.streamViewerCount * 1.0)/max(week.numberOfWeekdaysSinceDate * 1.0) " + "FROM DailyUsageSummary dus, TempWeekdaysSinceDate week " + "WHERE dus.streamViewStreamScopeId IS NOT NULL " + "AND week.numberOfWeekdaysSinceDate IS NOT NULL AND dus.streamViewerCount IS NOT NULL " + "AND dus.usageDateTimeStampInMs = week.dateTimeStampInMilliseconds " + "GROUP BY streamViewStreamScopeId HAVING MAX(week.numberOfWeekdaysSinceDate * 1.0) > 0 " + "AND sum(dus.streamViewerCount * 1.0) > 0 " + "ORDER BY SUM(dus.streamViewerCount * 1.0)/MAX(week.numberOfWeekdaysSinceDate * 1.0) DESC"); if (streamCount > 0) { q.setMaxResults(streamCount); } List<Object[]> streamObjs = q.getResultList(); List<Long> streamScopeIds = new ArrayList<Long>(); for (Object[] streamObj : streamObjs) { streamScopeIds.add((Long) streamObj[0]); } if (streamScopeIds.size() == 0) { return results; } List<StreamDTO> streamDtos = new ArrayList<StreamDTO>(); q = getEntityManager().createQuery( "SELECT new org.eurekastreams.server.search.modelview.PersonModelView(id, accountId, " + "preferredName, lastName, displayName, displayNameSuffix, followersCount, " + "dateAdded, streamScope.id) FROM Person " + "WHERE streamScope.id IN(:streamScopeIds)") .setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); q = getEntityManager().createQuery( "SELECT new org.eurekastreams.server.search.modelview.DomainGroupModelView(id, " + "shortName, name, 0, dateAdded, streamScope.id, publicGroup) FROM DomainGroup " + "WHERE streamScope.id IN(:streamScopeIds)").setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); Long streamScopeId, viewerCount; for (Object[] streamObj : streamObjs) { streamScopeId = (Long) streamObj[0]; viewerCount = -1L; if (streamObj[1] != null) { viewerCount = Math.round(Math.ceil((Double) streamObj[1])); } if (viewerCount > -1) { for (StreamDTO streamDTO : streamDtos) { if (streamDTO.getStreamScopeId().equals(streamScopeId)) { if (streamDTO.getEntityType() == EntityType.PERSON) { ((PersonModelView) streamDTO).setFollowersCount(viewerCount.intValue()); } else if (streamDTO.getEntityType() == EntityType.GROUP) { ((DomainGroupModelView) streamDTO).setFollowersCount(viewerCount.intValue()); } results.add(streamDTO); break; } } } } return results; } }
GetStreamsByDailyAverageViewersDbMapper extends BaseArgDomainMapper<Serializable, List<StreamDTO>> { @Override public List<StreamDTO> execute(final Serializable inIgnored) { List<StreamDTO> results = new ArrayList<StreamDTO>(); Query q; q = getEntityManager().createQuery( "SELECT dus.streamViewStreamScopeId, " + "sum(dus.streamViewerCount * 1.0)/max(week.numberOfWeekdaysSinceDate * 1.0) " + "FROM DailyUsageSummary dus, TempWeekdaysSinceDate week " + "WHERE dus.streamViewStreamScopeId IS NOT NULL " + "AND week.numberOfWeekdaysSinceDate IS NOT NULL AND dus.streamViewerCount IS NOT NULL " + "AND dus.usageDateTimeStampInMs = week.dateTimeStampInMilliseconds " + "GROUP BY streamViewStreamScopeId HAVING MAX(week.numberOfWeekdaysSinceDate * 1.0) > 0 " + "AND sum(dus.streamViewerCount * 1.0) > 0 " + "ORDER BY SUM(dus.streamViewerCount * 1.0)/MAX(week.numberOfWeekdaysSinceDate * 1.0) DESC"); if (streamCount > 0) { q.setMaxResults(streamCount); } List<Object[]> streamObjs = q.getResultList(); List<Long> streamScopeIds = new ArrayList<Long>(); for (Object[] streamObj : streamObjs) { streamScopeIds.add((Long) streamObj[0]); } if (streamScopeIds.size() == 0) { return results; } List<StreamDTO> streamDtos = new ArrayList<StreamDTO>(); q = getEntityManager().createQuery( "SELECT new org.eurekastreams.server.search.modelview.PersonModelView(id, accountId, " + "preferredName, lastName, displayName, displayNameSuffix, followersCount, " + "dateAdded, streamScope.id) FROM Person " + "WHERE streamScope.id IN(:streamScopeIds)") .setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); q = getEntityManager().createQuery( "SELECT new org.eurekastreams.server.search.modelview.DomainGroupModelView(id, " + "shortName, name, 0, dateAdded, streamScope.id, publicGroup) FROM DomainGroup " + "WHERE streamScope.id IN(:streamScopeIds)").setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); Long streamScopeId, viewerCount; for (Object[] streamObj : streamObjs) { streamScopeId = (Long) streamObj[0]; viewerCount = -1L; if (streamObj[1] != null) { viewerCount = Math.round(Math.ceil((Double) streamObj[1])); } if (viewerCount > -1) { for (StreamDTO streamDTO : streamDtos) { if (streamDTO.getStreamScopeId().equals(streamScopeId)) { if (streamDTO.getEntityType() == EntityType.PERSON) { ((PersonModelView) streamDTO).setFollowersCount(viewerCount.intValue()); } else if (streamDTO.getEntityType() == EntityType.GROUP) { ((DomainGroupModelView) streamDTO).setFollowersCount(viewerCount.intValue()); } results.add(streamDTO); break; } } } } return results; } GetStreamsByDailyAverageViewersDbMapper(final Integer inStreamCount); }
GetStreamsByDailyAverageViewersDbMapper extends BaseArgDomainMapper<Serializable, List<StreamDTO>> { @Override public List<StreamDTO> execute(final Serializable inIgnored) { List<StreamDTO> results = new ArrayList<StreamDTO>(); Query q; q = getEntityManager().createQuery( "SELECT dus.streamViewStreamScopeId, " + "sum(dus.streamViewerCount * 1.0)/max(week.numberOfWeekdaysSinceDate * 1.0) " + "FROM DailyUsageSummary dus, TempWeekdaysSinceDate week " + "WHERE dus.streamViewStreamScopeId IS NOT NULL " + "AND week.numberOfWeekdaysSinceDate IS NOT NULL AND dus.streamViewerCount IS NOT NULL " + "AND dus.usageDateTimeStampInMs = week.dateTimeStampInMilliseconds " + "GROUP BY streamViewStreamScopeId HAVING MAX(week.numberOfWeekdaysSinceDate * 1.0) > 0 " + "AND sum(dus.streamViewerCount * 1.0) > 0 " + "ORDER BY SUM(dus.streamViewerCount * 1.0)/MAX(week.numberOfWeekdaysSinceDate * 1.0) DESC"); if (streamCount > 0) { q.setMaxResults(streamCount); } List<Object[]> streamObjs = q.getResultList(); List<Long> streamScopeIds = new ArrayList<Long>(); for (Object[] streamObj : streamObjs) { streamScopeIds.add((Long) streamObj[0]); } if (streamScopeIds.size() == 0) { return results; } List<StreamDTO> streamDtos = new ArrayList<StreamDTO>(); q = getEntityManager().createQuery( "SELECT new org.eurekastreams.server.search.modelview.PersonModelView(id, accountId, " + "preferredName, lastName, displayName, displayNameSuffix, followersCount, " + "dateAdded, streamScope.id) FROM Person " + "WHERE streamScope.id IN(:streamScopeIds)") .setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); q = getEntityManager().createQuery( "SELECT new org.eurekastreams.server.search.modelview.DomainGroupModelView(id, " + "shortName, name, 0, dateAdded, streamScope.id, publicGroup) FROM DomainGroup " + "WHERE streamScope.id IN(:streamScopeIds)").setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); Long streamScopeId, viewerCount; for (Object[] streamObj : streamObjs) { streamScopeId = (Long) streamObj[0]; viewerCount = -1L; if (streamObj[1] != null) { viewerCount = Math.round(Math.ceil((Double) streamObj[1])); } if (viewerCount > -1) { for (StreamDTO streamDTO : streamDtos) { if (streamDTO.getStreamScopeId().equals(streamScopeId)) { if (streamDTO.getEntityType() == EntityType.PERSON) { ((PersonModelView) streamDTO).setFollowersCount(viewerCount.intValue()); } else if (streamDTO.getEntityType() == EntityType.GROUP) { ((DomainGroupModelView) streamDTO).setFollowersCount(viewerCount.intValue()); } results.add(streamDTO); break; } } } } return results; } GetStreamsByDailyAverageViewersDbMapper(final Integer inStreamCount); @Override List<StreamDTO> execute(final Serializable inIgnored); }
GetStreamsByDailyAverageViewersDbMapper extends BaseArgDomainMapper<Serializable, List<StreamDTO>> { @Override public List<StreamDTO> execute(final Serializable inIgnored) { List<StreamDTO> results = new ArrayList<StreamDTO>(); Query q; q = getEntityManager().createQuery( "SELECT dus.streamViewStreamScopeId, " + "sum(dus.streamViewerCount * 1.0)/max(week.numberOfWeekdaysSinceDate * 1.0) " + "FROM DailyUsageSummary dus, TempWeekdaysSinceDate week " + "WHERE dus.streamViewStreamScopeId IS NOT NULL " + "AND week.numberOfWeekdaysSinceDate IS NOT NULL AND dus.streamViewerCount IS NOT NULL " + "AND dus.usageDateTimeStampInMs = week.dateTimeStampInMilliseconds " + "GROUP BY streamViewStreamScopeId HAVING MAX(week.numberOfWeekdaysSinceDate * 1.0) > 0 " + "AND sum(dus.streamViewerCount * 1.0) > 0 " + "ORDER BY SUM(dus.streamViewerCount * 1.0)/MAX(week.numberOfWeekdaysSinceDate * 1.0) DESC"); if (streamCount > 0) { q.setMaxResults(streamCount); } List<Object[]> streamObjs = q.getResultList(); List<Long> streamScopeIds = new ArrayList<Long>(); for (Object[] streamObj : streamObjs) { streamScopeIds.add((Long) streamObj[0]); } if (streamScopeIds.size() == 0) { return results; } List<StreamDTO> streamDtos = new ArrayList<StreamDTO>(); q = getEntityManager().createQuery( "SELECT new org.eurekastreams.server.search.modelview.PersonModelView(id, accountId, " + "preferredName, lastName, displayName, displayNameSuffix, followersCount, " + "dateAdded, streamScope.id) FROM Person " + "WHERE streamScope.id IN(:streamScopeIds)") .setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); q = getEntityManager().createQuery( "SELECT new org.eurekastreams.server.search.modelview.DomainGroupModelView(id, " + "shortName, name, 0, dateAdded, streamScope.id, publicGroup) FROM DomainGroup " + "WHERE streamScope.id IN(:streamScopeIds)").setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); Long streamScopeId, viewerCount; for (Object[] streamObj : streamObjs) { streamScopeId = (Long) streamObj[0]; viewerCount = -1L; if (streamObj[1] != null) { viewerCount = Math.round(Math.ceil((Double) streamObj[1])); } if (viewerCount > -1) { for (StreamDTO streamDTO : streamDtos) { if (streamDTO.getStreamScopeId().equals(streamScopeId)) { if (streamDTO.getEntityType() == EntityType.PERSON) { ((PersonModelView) streamDTO).setFollowersCount(viewerCount.intValue()); } else if (streamDTO.getEntityType() == EntityType.GROUP) { ((DomainGroupModelView) streamDTO).setFollowersCount(viewerCount.intValue()); } results.add(streamDTO); break; } } } } return results; } GetStreamsByDailyAverageViewersDbMapper(final Integer inStreamCount); @Override List<StreamDTO> execute(final Serializable inIgnored);  }