Package org.eurekastreams.server.search.modelview

Examples of org.eurekastreams.server.search.modelview.SharedResourceDTO


     * Test execute when the SharedResource is found, but with no likers or sharers, and dto had nulls for liked ids.
     */
    @Test
    public void testExecuteWhenFoundAndNoSharersOrLikersWithNullDtoIdLists()
    {
        final SharedResourceDTO dto = new SharedResourceDTO();
        dto.setLikerPersonIds(null);
        dto.setSharerPersonIds(null);

        context.checking(new Expectations()
        {
            {
                oneOf(mapper).execute(request);
                will(returnValue(dto));
            }
        });

        sut.execute(actionContext);

        Assert.assertEquals(0, dto.getLikerPersonIds().size());
        Assert.assertEquals(0, dto.getSharerPersonIds().size());
        Assert.assertEquals(0, dto.getSharersSample().size());
        Assert.assertEquals(0, dto.getSharersSample().size());
        Assert.assertFalse(dto.isLiked());
        Assert.assertEquals(0, dto.getLikeCount());
        Assert.assertEquals(0, dto.getShareCount());

        context.assertIsSatisfied();
    }
View Full Code Here


     * ids.
     */
    @Test
    public void testExecuteWhenFoundAndNoSharersOrLikersWithNonNullDtoIdLists()
    {
        final SharedResourceDTO dto = new SharedResourceDTO();
        dto.setLikerPersonIds(new ArrayList<Long>());
        dto.setSharerPersonIds(new ArrayList<Long>());

        context.checking(new Expectations()
        {
            {
                oneOf(mapper).execute(request);
                will(returnValue(dto));
            }
        });

        sut.execute(actionContext);

        Assert.assertEquals(0, dto.getLikerPersonIds().size());
        Assert.assertEquals(0, dto.getSharerPersonIds().size());
        Assert.assertEquals(0, dto.getSharersSample().size());
        Assert.assertEquals(0, dto.getSharersSample().size());
        Assert.assertFalse(dto.isLiked());
        Assert.assertEquals(0, dto.getLikeCount());
        Assert.assertEquals(0, dto.getShareCount());

        context.assertIsSatisfied();
    }
View Full Code Here

    @Test
    public void testTransform()
    {
        Assert.assertEquals(0, sut.transform(null).size());

        SharedResourceDTO dto = new SharedResourceDTO();
        dto.setLikerPersonIds(null);
        Assert.assertEquals(0, sut.transform(dto).size());

        ArrayList<Long> peopleIds = new ArrayList<Long>();
        dto.setLikerPersonIds(peopleIds);
        Assert.assertSame(peopleIds, sut.transform(dto));
    }
View Full Code Here

     * Test execute when the SharedResource is NOT found.
     */
    @Test
    public void testExecuteWhenNotFound()
    {
        final SharedResourceDTO dto = new SharedResourceDTO();
        dto.setLikerPersonIds(new ArrayList<Long>());
        dto.setSharerPersonIds(new ArrayList<Long>());

        dto.getLikerPersonIds().add(1L);
        dto.getLikerPersonIds().add(2L);
        dto.getLikerPersonIds().add(3L);
        dto.getLikerPersonIds().add(4L);
        dto.getLikerPersonIds().add(5L);
        dto.getLikerPersonIds().add(8L);

        dto.getSharerPersonIds().add(1L);
        dto.getSharerPersonIds().add(3L);
        dto.getSharerPersonIds().add(5L);
        dto.getSharerPersonIds().add(6L);

        final List<PersonModelView> people = new ArrayList<PersonModelView>();

        PersonModelView mv1 = new PersonModelView();
        mv1.setEntityId(1L);
        people.add(mv1);

        PersonModelView mv2 = new PersonModelView();
        mv2.setEntityId(2L);
        people.add(mv2);

        PersonModelView mv3 = new PersonModelView();
        mv3.setEntityId(3L);
        people.add(mv3);

        PersonModelView mv4 = new PersonModelView();
        mv4.setEntityId(4L);
        people.add(mv4);

        PersonModelView mv5 = new PersonModelView();
        mv5.setEntityId(5L);
        people.add(mv5);

        PersonModelView mv6 = new PersonModelView();
        mv6.setEntityId(6L);
        people.add(mv6);

        final List<Long> peopleIds = new ArrayList<Long>();
        peopleIds.add(1L);
        peopleIds.add(3L);
        peopleIds.add(5L);
        peopleIds.add(6L);
        peopleIds.add(2L);
        peopleIds.add(4L);

        getPeopleModelViewsByIdsMapper.setResponse(people);

        context.checking(new Expectations()
        {
            {
                oneOf(mapper).execute(request);
                will(returnValue(dto));
            }
        });

        sut.execute(actionContext);

        // make sure the right people ids were passed into the getpeoplebyids
        Assert.assertEquals(6, getPeopleModelViewsByIdsMapper.getRequest().size());
        Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(1L));
        Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(2L));
        Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(5L));
        Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(6L));
        Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(2L));
        Assert.assertTrue(getPeopleModelViewsByIdsMapper.getRequest().contains(4L));

        Assert.assertEquals(6, dto.getLikerPersonIds().size());
        Assert.assertEquals(4, dto.getSharerPersonIds().size());

        Assert.assertEquals(4, dto.getLikersSample().size());
        Assert.assertEquals(4, dto.getSharersSample().size());

        Assert.assertTrue(dto.getLikersSample().contains(mv1));
        Assert.assertTrue(dto.getLikersSample().contains(mv2));
        Assert.assertTrue(dto.getLikersSample().contains(mv3));
        Assert.assertTrue(dto.getLikersSample().contains(mv4));

        Assert.assertTrue(dto.getSharersSample().contains(mv1));
        Assert.assertTrue(dto.getSharersSample().contains(mv3));
        Assert.assertTrue(dto.getSharersSample().contains(mv5));
        Assert.assertTrue(dto.getSharersSample().contains(mv6));

        Assert.assertTrue(dto.isLiked());

        context.assertIsSatisfied();
    }
View Full Code Here

    @Test
    public void testTransform()
    {
        Assert.assertEquals(0, sut.transform(null).size());

        SharedResourceDTO dto = new SharedResourceDTO();
        dto.setSharerPersonIds(null);
        Assert.assertEquals(0, sut.transform(dto).size());

        ArrayList<Long> peopleIds = new ArrayList<Long>();
        dto.setSharerPersonIds(peopleIds);
        Assert.assertSame(peopleIds, sut.transform(dto));
    }
View Full Code Here

                oneOf(getResourceStreamScopeByKeyMapper).execute(with(uniqueKey));
                will(returnValue(sharedResourceStreamScope));
            }
        });

        SharedResourceDTO result = sut.execute(request);
        assertNull(result.getStreamScopeId());
        assertEquals(0, result.getLikeCount());
        assertEquals(0, result.getShareCount());
        assertNull(result.getLikersSample());
        assertNull(result.getSharersSample());
        assertEquals(uniqueKey, result.getKey());

        context.assertIsSatisfied();
    }
View Full Code Here

                will(returnValue(likerIds));
            }
        });

        // execute sut
        SharedResourceDTO result = sut.execute(request);

        // make sure the request was updated with the shared resource id
        assertEquals(sharedResourceId, request.getSharedResourceId());

        // make sure the top-level properties look right
        assertEquals(streamScopeId, result.getStreamScopeId());
        assertEquals(5, result.getLikeCount());
        assertEquals(6, result.getShareCount());
        assertNull(result.getLikersSample());
        assertNull(result.getSharersSample());
        assertEquals(uniqueKey, result.getKey());

        context.assertIsSatisfied();
    }
View Full Code Here

        log.info("Searching for the cacheable component of the SharedResourceDTO");

        // get the dto in its cacheable state - everything else i do to it here isn't cacheable, including setting
        // whether the current person liked it, and setting some skeleton personmodelviews for avatar display
        SharedResourceDTO dto = mapper.execute(request);

        // --- BEGIN customizing the previously cacheable DTO

        // make sure the collections aren't null
        if (dto.getLikerPersonIds() == null)
        {
            dto.setLikerPersonIds(new ArrayList<Long>());
        }
        if (dto.getSharerPersonIds() == null)
        {
            dto.setSharerPersonIds(new ArrayList<Long>());
        }
        dto.setSharersSample(new ArrayList<PersonModelView>());
        dto.setLikersSample(new ArrayList<PersonModelView>());

        log.info("Now customizing the SharedResourceDTO with info about the current user, and include avatar info");

        // set whether the current user likes the shared resource
        dto.setIsLiked(dto.getLikerPersonIds().contains(currentUserPersonId));

        // --
        // create a sampling of the people that liked and shared a resource - trim the two lists each to 4 people,
        // make a single request to get the person modelviews, then put the modelviews back in the sample lists
        // --

        List<Long> sharedPersonIds = dto.getSharerPersonIds();
        List<Long> likedPersonIds = dto.getLikerPersonIds();

        // 1. trim the list of people in the sample collections
        if (sharedPersonIds.size() > 4)
        {
            sharedPersonIds = sharedPersonIds.subList(0, 4);
        }
        if (likedPersonIds.size() > 4)
        {
            likedPersonIds = likedPersonIds.subList(0, 4);
        }

        // 2. put all the people ids together for a single request to get the skeleton person modelviews
        List<Long> personIds = new ArrayList<Long>();
        personIds.addAll(sharedPersonIds);
        for (long id : likedPersonIds)
        {
            if (!personIds.contains(id))
            {
                personIds.add(id);
            }
        }

        // 3. Create the sample lists of people that shared and liked this resource
        if (personIds.size() > 0)
        {
            List<PersonModelView> people = getPeopleModelViewsByIdsMapper.execute(personIds);
            PersonModelView foundPerson;
            for (long personId : personIds)
            {
                foundPerson = findPersonInList(people, personId);
                if (foundPerson != null)
                {
                    // add the DTO to the people collections
                    if (likedPersonIds.contains(personId))
                    {
                        dto.getLikersSample().add(foundPerson);
                    }
                    if (sharedPersonIds.contains(personId))
                    {
                        dto.getSharersSample().add(foundPerson);
                    }
                }
            }
        }
View Full Code Here

     * @return the shared resource dto
     */
    @Override
    public SharedResourceDTO execute(final SharedResourceRequest inRequest)
    {
        SharedResourceDTO dto = new SharedResourceDTO();
        dto.setKey(inRequest.getUniqueKey());

        log.info("Looking for the stream scope for shared resource with uniqueKey " + inRequest.getUniqueKey());

        // either null or a stream scope id
        StreamScope sharedResourceStreamScope = getResourceStreamScopeByKeyMapper.execute(inRequest.getUniqueKey());

        // if the stream scope doesn't exist, then this resource doesn't either
        if (sharedResourceStreamScope == null)
        {
            // not found - if the shared resource existed, it would have a stream scope, so we can stop looking through
            // the other tables now
            log.info("Couldn't find the stream scope for shared resource with unique key " + inRequest.getUniqueKey()
                    + " - must not exist.  Cache as such.");

            dto.setStreamScopeId(null);
            dto.setIsLiked(false);
            return dto;
        }
        dto.setStreamScopeId(sharedResourceStreamScope.getId());

        // since we know the destination SharedResource id, we can get the likers and sharers much quicker
        inRequest.setSharedResourceId(sharedResourceStreamScope.getDestinationEntityId());

        log.info("Found the shared resource for unique key " + inRequest.getUniqueKey()
                + " - looking for lists of people ids that liked and shared it.");

        List<Long> sharedPersonIds = getPeopleThatSharedResourceMapper.execute(inRequest);
        List<Long> likedPersonIds = getPeopleThatLikedResourceMapper.execute(inRequest);

        if (sharedPersonIds == null)
        {
            sharedPersonIds = new ArrayList<Long>();
        }
        dto.setLikerPersonIds(likedPersonIds);

        if (likedPersonIds == null)
        {
            likedPersonIds = new ArrayList<Long>();
        }
        dto.setSharerPersonIds(sharedPersonIds);
        return dto;
    }
View Full Code Here

TOP

Related Classes of org.eurekastreams.server.search.modelview.SharedResourceDTO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.