@Test public void testExecuteWhenNoData() { getEntityManager().createQuery("DELETE FROM DailyUsageSummary").executeUpdate(); getEntityManager().clear(); SublistWithResultCount<StreamDTO> results = sut.execute(null); Assert.assertEquals(new Long(0L), results.getTotalResultsCount()); Assert.assertEquals(0, results.getResultsSublist().size()); }
@Override public SublistWithResultCount<StreamDTO> execute(final Serializable inIgnored) { List<StreamDTO> results = new ArrayList<StreamDTO>(); Query q = getEntityManager().createQuery( "SELECT dus.streamViewStreamScopeId, " + "sum(dus.messageCount * 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.messageCount IS NOT NULL " + "AND dus.usageDateTimeStampInMs = week.dateTimeStampInMilliseconds " + "GROUP BY streamViewStreamScopeId HAVING MAX(week.numberOfWeekdaysSinceDate * 1.0) > 0 " + "AND sum(dus.messageCount * 1.0) > 0 " + "ORDER BY SUM(dus.messageCount * 1.0)/MAX(week.numberOfWeekdaysSinceDate * 1.0) DESC"); List<Object[]> scopeIdAndMessageCountArray = q.getResultList(); if (streamCount > 0 && scopeIdAndMessageCountArray.size() > streamCount) { scopeIdAndMessageCountArray = scopeIdAndMessageCountArray.subList(0, streamCount); } List<Long> streamScopeIds = new ArrayList<Long>(); for (Object[] streamObj : scopeIdAndMessageCountArray) { streamScopeIds.add((Long) streamObj[0]); } if (streamScopeIds.size() == 0) { return new SublistWithResultCount<StreamDTO>(results, new Long(0)); } 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, followersCount, dateAdded, streamScope.id, publicGroup) FROM DomainGroup " + "WHERE streamScope.id IN(:streamScopeIds)").setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); Long streamScopeId, messageCount; for (Object[] streamObj : scopeIdAndMessageCountArray) { streamScopeId = (Long) streamObj[0]; messageCount = -1L; if (streamObj[1] != null) { messageCount = Math.round(Math.ceil((Double) streamObj[1])); } if (messageCount > -1) { for (StreamDTO streamDTO : streamDtos) { if (streamDTO.getStreamScopeId().equals(streamScopeId)) { if (streamDTO.getEntityType() == EntityType.PERSON) { ((PersonModelView) streamDTO).setFollowersCount(messageCount.intValue()); } else if (streamDTO.getEntityType() == EntityType.GROUP) { ((DomainGroupModelView) streamDTO).setFollowersCount(messageCount.intValue()); } results.add(streamDTO); break; } } } } return new SublistWithResultCount<StreamDTO>(results, new Long(results.size())); }
GetStreamsByDailyAverageMessageCountDbMapper extends
        BaseArgDomainMapper<Serializable, SublistWithResultCount<StreamDTO>> { @Override public SublistWithResultCount<StreamDTO> execute(final Serializable inIgnored) { List<StreamDTO> results = new ArrayList<StreamDTO>(); Query q = getEntityManager().createQuery( "SELECT dus.streamViewStreamScopeId, " + "sum(dus.messageCount * 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.messageCount IS NOT NULL " + "AND dus.usageDateTimeStampInMs = week.dateTimeStampInMilliseconds " + "GROUP BY streamViewStreamScopeId HAVING MAX(week.numberOfWeekdaysSinceDate * 1.0) > 0 " + "AND sum(dus.messageCount * 1.0) > 0 " + "ORDER BY SUM(dus.messageCount * 1.0)/MAX(week.numberOfWeekdaysSinceDate * 1.0) DESC"); List<Object[]> scopeIdAndMessageCountArray = q.getResultList(); if (streamCount > 0 && scopeIdAndMessageCountArray.size() > streamCount) { scopeIdAndMessageCountArray = scopeIdAndMessageCountArray.subList(0, streamCount); } List<Long> streamScopeIds = new ArrayList<Long>(); for (Object[] streamObj : scopeIdAndMessageCountArray) { streamScopeIds.add((Long) streamObj[0]); } if (streamScopeIds.size() == 0) { return new SublistWithResultCount<StreamDTO>(results, new Long(0)); } 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, followersCount, dateAdded, streamScope.id, publicGroup) FROM DomainGroup " + "WHERE streamScope.id IN(:streamScopeIds)").setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); Long streamScopeId, messageCount; for (Object[] streamObj : scopeIdAndMessageCountArray) { streamScopeId = (Long) streamObj[0]; messageCount = -1L; if (streamObj[1] != null) { messageCount = Math.round(Math.ceil((Double) streamObj[1])); } if (messageCount > -1) { for (StreamDTO streamDTO : streamDtos) { if (streamDTO.getStreamScopeId().equals(streamScopeId)) { if (streamDTO.getEntityType() == EntityType.PERSON) { ((PersonModelView) streamDTO).setFollowersCount(messageCount.intValue()); } else if (streamDTO.getEntityType() == EntityType.GROUP) { ((DomainGroupModelView) streamDTO).setFollowersCount(messageCount.intValue()); } results.add(streamDTO); break; } } } } return new SublistWithResultCount<StreamDTO>(results, new Long(results.size())); } }
GetStreamsByDailyAverageMessageCountDbMapper extends
        BaseArgDomainMapper<Serializable, SublistWithResultCount<StreamDTO>> { @Override public SublistWithResultCount<StreamDTO> execute(final Serializable inIgnored) { List<StreamDTO> results = new ArrayList<StreamDTO>(); Query q = getEntityManager().createQuery( "SELECT dus.streamViewStreamScopeId, " + "sum(dus.messageCount * 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.messageCount IS NOT NULL " + "AND dus.usageDateTimeStampInMs = week.dateTimeStampInMilliseconds " + "GROUP BY streamViewStreamScopeId HAVING MAX(week.numberOfWeekdaysSinceDate * 1.0) > 0 " + "AND sum(dus.messageCount * 1.0) > 0 " + "ORDER BY SUM(dus.messageCount * 1.0)/MAX(week.numberOfWeekdaysSinceDate * 1.0) DESC"); List<Object[]> scopeIdAndMessageCountArray = q.getResultList(); if (streamCount > 0 && scopeIdAndMessageCountArray.size() > streamCount) { scopeIdAndMessageCountArray = scopeIdAndMessageCountArray.subList(0, streamCount); } List<Long> streamScopeIds = new ArrayList<Long>(); for (Object[] streamObj : scopeIdAndMessageCountArray) { streamScopeIds.add((Long) streamObj[0]); } if (streamScopeIds.size() == 0) { return new SublistWithResultCount<StreamDTO>(results, new Long(0)); } 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, followersCount, dateAdded, streamScope.id, publicGroup) FROM DomainGroup " + "WHERE streamScope.id IN(:streamScopeIds)").setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); Long streamScopeId, messageCount; for (Object[] streamObj : scopeIdAndMessageCountArray) { streamScopeId = (Long) streamObj[0]; messageCount = -1L; if (streamObj[1] != null) { messageCount = Math.round(Math.ceil((Double) streamObj[1])); } if (messageCount > -1) { for (StreamDTO streamDTO : streamDtos) { if (streamDTO.getStreamScopeId().equals(streamScopeId)) { if (streamDTO.getEntityType() == EntityType.PERSON) { ((PersonModelView) streamDTO).setFollowersCount(messageCount.intValue()); } else if (streamDTO.getEntityType() == EntityType.GROUP) { ((DomainGroupModelView) streamDTO).setFollowersCount(messageCount.intValue()); } results.add(streamDTO); break; } } } } return new SublistWithResultCount<StreamDTO>(results, new Long(results.size())); } GetStreamsByDailyAverageMessageCountDbMapper(final Integer inStreamCount); }
GetStreamsByDailyAverageMessageCountDbMapper extends
        BaseArgDomainMapper<Serializable, SublistWithResultCount<StreamDTO>> { @Override public SublistWithResultCount<StreamDTO> execute(final Serializable inIgnored) { List<StreamDTO> results = new ArrayList<StreamDTO>(); Query q = getEntityManager().createQuery( "SELECT dus.streamViewStreamScopeId, " + "sum(dus.messageCount * 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.messageCount IS NOT NULL " + "AND dus.usageDateTimeStampInMs = week.dateTimeStampInMilliseconds " + "GROUP BY streamViewStreamScopeId HAVING MAX(week.numberOfWeekdaysSinceDate * 1.0) > 0 " + "AND sum(dus.messageCount * 1.0) > 0 " + "ORDER BY SUM(dus.messageCount * 1.0)/MAX(week.numberOfWeekdaysSinceDate * 1.0) DESC"); List<Object[]> scopeIdAndMessageCountArray = q.getResultList(); if (streamCount > 0 && scopeIdAndMessageCountArray.size() > streamCount) { scopeIdAndMessageCountArray = scopeIdAndMessageCountArray.subList(0, streamCount); } List<Long> streamScopeIds = new ArrayList<Long>(); for (Object[] streamObj : scopeIdAndMessageCountArray) { streamScopeIds.add((Long) streamObj[0]); } if (streamScopeIds.size() == 0) { return new SublistWithResultCount<StreamDTO>(results, new Long(0)); } 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, followersCount, dateAdded, streamScope.id, publicGroup) FROM DomainGroup " + "WHERE streamScope.id IN(:streamScopeIds)").setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); Long streamScopeId, messageCount; for (Object[] streamObj : scopeIdAndMessageCountArray) { streamScopeId = (Long) streamObj[0]; messageCount = -1L; if (streamObj[1] != null) { messageCount = Math.round(Math.ceil((Double) streamObj[1])); } if (messageCount > -1) { for (StreamDTO streamDTO : streamDtos) { if (streamDTO.getStreamScopeId().equals(streamScopeId)) { if (streamDTO.getEntityType() == EntityType.PERSON) { ((PersonModelView) streamDTO).setFollowersCount(messageCount.intValue()); } else if (streamDTO.getEntityType() == EntityType.GROUP) { ((DomainGroupModelView) streamDTO).setFollowersCount(messageCount.intValue()); } results.add(streamDTO); break; } } } } return new SublistWithResultCount<StreamDTO>(results, new Long(results.size())); } GetStreamsByDailyAverageMessageCountDbMapper(final Integer inStreamCount); @Override SublistWithResultCount<StreamDTO> execute(final Serializable inIgnored); }
GetStreamsByDailyAverageMessageCountDbMapper extends
        BaseArgDomainMapper<Serializable, SublistWithResultCount<StreamDTO>> { @Override public SublistWithResultCount<StreamDTO> execute(final Serializable inIgnored) { List<StreamDTO> results = new ArrayList<StreamDTO>(); Query q = getEntityManager().createQuery( "SELECT dus.streamViewStreamScopeId, " + "sum(dus.messageCount * 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.messageCount IS NOT NULL " + "AND dus.usageDateTimeStampInMs = week.dateTimeStampInMilliseconds " + "GROUP BY streamViewStreamScopeId HAVING MAX(week.numberOfWeekdaysSinceDate * 1.0) > 0 " + "AND sum(dus.messageCount * 1.0) > 0 " + "ORDER BY SUM(dus.messageCount * 1.0)/MAX(week.numberOfWeekdaysSinceDate * 1.0) DESC"); List<Object[]> scopeIdAndMessageCountArray = q.getResultList(); if (streamCount > 0 && scopeIdAndMessageCountArray.size() > streamCount) { scopeIdAndMessageCountArray = scopeIdAndMessageCountArray.subList(0, streamCount); } List<Long> streamScopeIds = new ArrayList<Long>(); for (Object[] streamObj : scopeIdAndMessageCountArray) { streamScopeIds.add((Long) streamObj[0]); } if (streamScopeIds.size() == 0) { return new SublistWithResultCount<StreamDTO>(results, new Long(0)); } 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, followersCount, dateAdded, streamScope.id, publicGroup) FROM DomainGroup " + "WHERE streamScope.id IN(:streamScopeIds)").setParameter("streamScopeIds", streamScopeIds); streamDtos.addAll(q.getResultList()); Long streamScopeId, messageCount; for (Object[] streamObj : scopeIdAndMessageCountArray) { streamScopeId = (Long) streamObj[0]; messageCount = -1L; if (streamObj[1] != null) { messageCount = Math.round(Math.ceil((Double) streamObj[1])); } if (messageCount > -1) { for (StreamDTO streamDTO : streamDtos) { if (streamDTO.getStreamScopeId().equals(streamScopeId)) { if (streamDTO.getEntityType() == EntityType.PERSON) { ((PersonModelView) streamDTO).setFollowersCount(messageCount.intValue()); } else if (streamDTO.getEntityType() == EntityType.GROUP) { ((DomainGroupModelView) streamDTO).setFollowersCount(messageCount.intValue()); } results.add(streamDTO); break; } } } } return new SublistWithResultCount<StreamDTO>(results, new Long(results.size())); } GetStreamsByDailyAverageMessageCountDbMapper(final Integer inStreamCount); @Override SublistWithResultCount<StreamDTO> execute(final Serializable inIgnored);  }