@Test public void testExecute() { getEntityManager().createQuery("DELETE FROM GroupFollower").executeUpdate(); getEntityManager().createQuery("DELETE FROM Follower").executeUpdate(); getEntityManager().persist(new Follower(42, 142)); getEntityManager().persist(new Follower(42, 4507)); getEntityManager().persist(new Follower(42, 98)); getEntityManager().persist(new Follower(42, 99)); getEntityManager().persist(new GroupFollower(142, 5)); getEntityManager().persist(new GroupFollower(4507, 5)); getEntityManager().persist(new GroupFollower(98, 5)); getEntityManager().persist(new GroupFollower(142, 1)); getEntityManager().persist(new GroupFollower(4507, 1)); getEntityManager().persist(new GroupFollower(142, 3)); List<DomainGroupModelView> suggestedGroups = sut.execute(new SuggestedStreamsRequest(42L, 4)); Assert.assertEquals(3, suggestedGroups.size()); Assert.assertEquals(5, suggestedGroups.get(0).getId()); Assert.assertEquals("group5", suggestedGroups.get(0).getShortName()); Assert.assertEquals("A Group 1 Name", suggestedGroups.get(0).getName()); Assert.assertEquals(3, suggestedGroups.get(0).getFollowersCount()); Assert.assertEquals(1, suggestedGroups.get(1).getId()); Assert.assertEquals("group1", suggestedGroups.get(1).getShortName()); Assert.assertEquals("E Group 1 Name", suggestedGroups.get(1).getName()); Assert.assertEquals(2, suggestedGroups.get(1).getFollowersCount()); Assert.assertEquals(3, suggestedGroups.get(2).getId()); Assert.assertEquals("group3", suggestedGroups.get(2).getShortName()); Assert.assertEquals("C Group 1 Name", suggestedGroups.get(2).getName()); Assert.assertEquals(1, suggestedGroups.get(2).getFollowersCount()); suggestedGroups = sut.execute(new SuggestedStreamsRequest(42L, 2)); Assert.assertEquals(2, suggestedGroups.size()); Assert.assertEquals(5, suggestedGroups.get(0).getId()); Assert.assertEquals(1, suggestedGroups.get(1).getId()); getEntityManager().persist(new GroupFollower(42, 1)); suggestedGroups = sut.execute(new SuggestedStreamsRequest(42L, 3)); Assert.assertEquals(2, suggestedGroups.size()); Assert.assertEquals(5, suggestedGroups.get(0).getId()); Assert.assertEquals(3, suggestedGroups.get(1).getId()); }
@Override @SuppressWarnings("unchecked") public List<DomainGroupModelView> execute(final SuggestedStreamsRequest inRequest) { Query query = getEntityManager() .createQuery( "SELECT new org.eurekastreams.server.search.modelview.DomainGroupModelView(g.id, " + "g.shortName, g.name, COUNT(theirGroups.pk.followingId), " + "g.dateAdded, g.streamScope.id, g.publicGroup) " + "FROM Follower peopleIFollow, GroupFollower theirGroups, DomainGroup g " + "WHERE peopleIFollow.pk.followingId = theirGroups.pk.followerId " + "AND theirGroups.pk.followingId = g.id " + "AND peopleIFollow.pk.followerId = :personId AND theirGroups.pk.followingId NOT IN " + "(SELECT pk.followingId FROM GroupFollower WHERE followerId = :personId) " + " AND g.streamScope.id NOT IN " + "(SELECT pk.scopeId FROM PersonBlockedSuggestion WHERE " + "personid = :personBlockedId) " + "GROUP BY theirGroups.pk.followingId, g.id, g.shortName, g.name, g.dateAdded, " + "g.streamScope.id, g.publicGroup ORDER BY COUNT(theirGroups.pk.followingId) DESC") .setParameter("personId", inRequest.getPersonId()) .setParameter("personBlockedId", inRequest.getPersonId()); query.setMaxResults(inRequest.getStreamCount()); return query.getResultList(); }
GetSuggestedGroupsForPersonDbMapper extends
        BaseArgDomainMapper<SuggestedStreamsRequest, List<DomainGroupModelView>> { @Override @SuppressWarnings("unchecked") public List<DomainGroupModelView> execute(final SuggestedStreamsRequest inRequest) { Query query = getEntityManager() .createQuery( "SELECT new org.eurekastreams.server.search.modelview.DomainGroupModelView(g.id, " + "g.shortName, g.name, COUNT(theirGroups.pk.followingId), " + "g.dateAdded, g.streamScope.id, g.publicGroup) " + "FROM Follower peopleIFollow, GroupFollower theirGroups, DomainGroup g " + "WHERE peopleIFollow.pk.followingId = theirGroups.pk.followerId " + "AND theirGroups.pk.followingId = g.id " + "AND peopleIFollow.pk.followerId = :personId AND theirGroups.pk.followingId NOT IN " + "(SELECT pk.followingId FROM GroupFollower WHERE followerId = :personId) " + " AND g.streamScope.id NOT IN " + "(SELECT pk.scopeId FROM PersonBlockedSuggestion WHERE " + "personid = :personBlockedId) " + "GROUP BY theirGroups.pk.followingId, g.id, g.shortName, g.name, g.dateAdded, " + "g.streamScope.id, g.publicGroup ORDER BY COUNT(theirGroups.pk.followingId) DESC") .setParameter("personId", inRequest.getPersonId()) .setParameter("personBlockedId", inRequest.getPersonId()); query.setMaxResults(inRequest.getStreamCount()); return query.getResultList(); } }
GetSuggestedGroupsForPersonDbMapper extends
        BaseArgDomainMapper<SuggestedStreamsRequest, List<DomainGroupModelView>> { @Override @SuppressWarnings("unchecked") public List<DomainGroupModelView> execute(final SuggestedStreamsRequest inRequest) { Query query = getEntityManager() .createQuery( "SELECT new org.eurekastreams.server.search.modelview.DomainGroupModelView(g.id, " + "g.shortName, g.name, COUNT(theirGroups.pk.followingId), " + "g.dateAdded, g.streamScope.id, g.publicGroup) " + "FROM Follower peopleIFollow, GroupFollower theirGroups, DomainGroup g " + "WHERE peopleIFollow.pk.followingId = theirGroups.pk.followerId " + "AND theirGroups.pk.followingId = g.id " + "AND peopleIFollow.pk.followerId = :personId AND theirGroups.pk.followingId NOT IN " + "(SELECT pk.followingId FROM GroupFollower WHERE followerId = :personId) " + " AND g.streamScope.id NOT IN " + "(SELECT pk.scopeId FROM PersonBlockedSuggestion WHERE " + "personid = :personBlockedId) " + "GROUP BY theirGroups.pk.followingId, g.id, g.shortName, g.name, g.dateAdded, " + "g.streamScope.id, g.publicGroup ORDER BY COUNT(theirGroups.pk.followingId) DESC") .setParameter("personId", inRequest.getPersonId()) .setParameter("personBlockedId", inRequest.getPersonId()); query.setMaxResults(inRequest.getStreamCount()); return query.getResultList(); }  }
GetSuggestedGroupsForPersonDbMapper extends
        BaseArgDomainMapper<SuggestedStreamsRequest, List<DomainGroupModelView>> { @Override @SuppressWarnings("unchecked") public List<DomainGroupModelView> execute(final SuggestedStreamsRequest inRequest) { Query query = getEntityManager() .createQuery( "SELECT new org.eurekastreams.server.search.modelview.DomainGroupModelView(g.id, " + "g.shortName, g.name, COUNT(theirGroups.pk.followingId), " + "g.dateAdded, g.streamScope.id, g.publicGroup) " + "FROM Follower peopleIFollow, GroupFollower theirGroups, DomainGroup g " + "WHERE peopleIFollow.pk.followingId = theirGroups.pk.followerId " + "AND theirGroups.pk.followingId = g.id " + "AND peopleIFollow.pk.followerId = :personId AND theirGroups.pk.followingId NOT IN " + "(SELECT pk.followingId FROM GroupFollower WHERE followerId = :personId) " + " AND g.streamScope.id NOT IN " + "(SELECT pk.scopeId FROM PersonBlockedSuggestion WHERE " + "personid = :personBlockedId) " + "GROUP BY theirGroups.pk.followingId, g.id, g.shortName, g.name, g.dateAdded, " + "g.streamScope.id, g.publicGroup ORDER BY COUNT(theirGroups.pk.followingId) DESC") .setParameter("personId", inRequest.getPersonId()) .setParameter("personBlockedId", inRequest.getPersonId()); query.setMaxResults(inRequest.getStreamCount()); return query.getResultList(); }  @Override @SuppressWarnings("unchecked") List<DomainGroupModelView> execute(final SuggestedStreamsRequest inRequest); }
GetSuggestedGroupsForPersonDbMapper extends
        BaseArgDomainMapper<SuggestedStreamsRequest, List<DomainGroupModelView>> { @Override @SuppressWarnings("unchecked") public List<DomainGroupModelView> execute(final SuggestedStreamsRequest inRequest) { Query query = getEntityManager() .createQuery( "SELECT new org.eurekastreams.server.search.modelview.DomainGroupModelView(g.id, " + "g.shortName, g.name, COUNT(theirGroups.pk.followingId), " + "g.dateAdded, g.streamScope.id, g.publicGroup) " + "FROM Follower peopleIFollow, GroupFollower theirGroups, DomainGroup g " + "WHERE peopleIFollow.pk.followingId = theirGroups.pk.followerId " + "AND theirGroups.pk.followingId = g.id " + "AND peopleIFollow.pk.followerId = :personId AND theirGroups.pk.followingId NOT IN " + "(SELECT pk.followingId FROM GroupFollower WHERE followerId = :personId) " + " AND g.streamScope.id NOT IN " + "(SELECT pk.scopeId FROM PersonBlockedSuggestion WHERE " + "personid = :personBlockedId) " + "GROUP BY theirGroups.pk.followingId, g.id, g.shortName, g.name, g.dateAdded, " + "g.streamScope.id, g.publicGroup ORDER BY COUNT(theirGroups.pk.followingId) DESC") .setParameter("personId", inRequest.getPersonId()) .setParameter("personBlockedId", inRequest.getPersonId()); query.setMaxResults(inRequest.getStreamCount()); return query.getResultList(); }  @Override @SuppressWarnings("unchecked") List<DomainGroupModelView> execute(final SuggestedStreamsRequest inRequest);  }