Package org.eurekastreams.server.domain

Examples of org.eurekastreams.server.domain.Background


       
        String json = sut.convertBackgroundToJSON(background).toString();
       
        StringRepresentation jsonRep = new StringRepresentation(json);
       
        final Background bg = new Background(new Person());
        bg.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.AFFILIATION);
        bg.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.HONOR);
        bg.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.INTEREST);
        bg.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.SKILL);

        context.checking(new Expectations()
        {
            {
                oneOf(mapper).findOrCreatePersonBackground(with(uuid));
                will(returnValue(bg));

                oneOf(mapper).flush(uuid);
            }
        });

        // precondition, the background is empty
        assertEquals(0, bg.getBackgroundItems(BackgroundItemType.AFFILIATION).size());
        assertEquals(0, bg.getBackgroundItems(BackgroundItemType.HONOR).size());
        assertEquals(0, bg.getBackgroundItems(BackgroundItemType.INTEREST).size());
        assertEquals(0, bg.getBackgroundItems(BackgroundItemType.SKILL).size());
       
        // perform the action to be tested
        sut.storeRepresentation(jsonRep);

        // post condition, make sure mapper was called and items were set
        context.assertIsSatisfied();
        assertEquals(3, bg.getBackgroundItems(BackgroundItemType.AFFILIATION).size());
        assertEquals(3, bg.getBackgroundItems(BackgroundItemType.HONOR).size());
        assertEquals(3, bg.getBackgroundItems(BackgroundItemType.INTEREST).size());
        assertEquals(3, bg.getBackgroundItems(BackgroundItemType.SKILL).size());
        assertEquals("a", bg.getBackgroundItems(BackgroundItemType.AFFILIATION).get(0).toString());
        assertEquals("d", bg.getBackgroundItems(BackgroundItemType.HONOR).get(0).toString());
        assertEquals("1", bg.getBackgroundItems(BackgroundItemType.INTEREST).get(0).toString());
        assertEquals("4", bg.getBackgroundItems(BackgroundItemType.SKILL).get(0).toString());

       
    }
View Full Code Here


        //Dataset with invalid number and type of keys.
        String json = "{\"affiliations\":[\"title\"], \"Invalid Type\":[\"text\"]}";
       
        StringRepresentation jsonRep = new StringRepresentation(json);
       
        final Background mockBg = context.mock(Background.class);

        context.checking(new Expectations()
        {
            {
                oneOf(mapper).findOrCreatePersonBackground(with(uuid));
View Full Code Here

        String json = "{\"affiliations\":[\"badcharacter>\"], \"skillsspecialties\":[\"text\"], "
            + "\"interestshobbies\":[\"title\"], \"honorsawards\":[\"text\"]}";
       
        StringRepresentation jsonRep = new StringRepresentation(json);
       
        final Background mockBg = context.mock(Background.class);

        context.checking(new Expectations()
        {
            {
                oneOf(mapper).findOrCreatePersonBackground(with(uuid));
View Full Code Here

    {

        final long personId = 142L;
        final String openSocialId = "2d359911-0977-418a-9490-57e8252b1142";
        Person person = jpaPersonMapper.findById(personId);
        Background background = new Background(person);

        jpaBackgroundMapper.insert(background);

        List<BackgroundItem> expectedBackgroundItems = new ArrayList<BackgroundItem>();
        expectedBackgroundItems.add(new BackgroundItem("sports", BackgroundItemType.INTEREST));
        expectedBackgroundItems.add(new BackgroundItem("music", BackgroundItemType.INTEREST));
        expectedBackgroundItems.add(new BackgroundItem("software", BackgroundItemType.INTEREST));
        background.setBackgroundItems(expectedBackgroundItems, BackgroundItemType.HONOR);

        jpaBackgroundMapper.getEntityManager().flush();
        jpaBackgroundMapper.getEntityManager().clear();

        background = jpaBackgroundMapper.findPersonBackground(openSocialId);

        assertNotNull("No background items found for person with id fordp", background
                .getBackgroundItems(BackgroundItemType.HONOR));

        jpaBackgroundMapper.flush("2d359911-0977-418a-9490-57e8252b1142");

        // the list.toString() prints out the same thing though they are
        // different objects
        assertEquals(expectedBackgroundItems.toString(), background.getBackgroundItems(BackgroundItemType.HONOR)
                .toString());

    }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public Background findOrCreatePersonBackground(final String inOpenSocialId)
    {

        Background background = findPersonBackground(inOpenSocialId);

        if (null == background)
        {
            logger.debug("background not found, so creating one");

            Query q = getEntityManager().createQuery("from Person where openSocialId = :openSocialId").setParameter(
                    "openSocialId", inOpenSocialId);

            // Can't find the background. Get the person so we can make one.
            List personList = q.getResultList();
            if (personList.size() == 0)
            {
                // We can't even find this openSocialId. Give up.
                return null;
            }

            //
            background = new Background((Person) personList.get(0));

            background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.AFFILIATION);
            background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.HONOR);
            background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.INTEREST);
            background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.SKILL);

            getEntityManager().persist(background);
        }

        return background;
View Full Code Here

        }

        StringBuilder sb = new StringBuilder();
        try
        {
            Background bg = (Background) backgroundObj;

            // note: the extra space in the beginning here is for easier unit testing
            sb.append(" ");

            // we currently only index SKILLS since that's all that's settable
            List<BackgroundItemType> handledTypes = new ArrayList<BackgroundItemType>();
            handledTypes.add(BackgroundItemType.SKILL);

            for (BackgroundItemType itemType : handledTypes)
            {
                sb.append(itemBridge.objectToString(bg.getBackgroundItems(itemType)));
            }

            sb.append(" ");
        }
        catch (Exception ex)
View Full Code Here

        Person person = (Person) personPersister.execute(inActionContext);

        List<BackgroundItem> skills = convertStringToBackgroundItems((String) fields.get(PersonModelView.SKILLS_KEY),
                BackgroundItemType.SKILL);

        Background background = backgroundMapper.findOrCreatePersonBackground(person.getOpenSocialId());
        background.setBackgroundItems(skills, BackgroundItemType.SKILL);

        personMapper.flush();
        deleteCacheKeyDAO.execute(Collections.singleton(CacheKeys.PERSON_BY_ID + person.getId()));

        return person;
View Full Code Here

     *             on error
     */
    @Override
    public Representation represent(final Variant variant) throws ResourceException
    {
        Background bg = mapper.findOrCreatePersonBackground(uuid);
        JSONObject bgAsJson = convertBackgroundToJSON(bg);

        String json = bgAsJson.toString();
        log.debug("PersonBackgroundResource accepted json for uuid: " + uuid);
        log.debug("PersonBackgroundResource constructed json: " + json);
View Full Code Here

     *            the resource's new representation
     */
    @Override
    public void storeRepresentation(final Representation entity)
    {
        Background bg = mapper.findOrCreatePersonBackground(uuid);

        try
        {
            String jsontext = entity.getText();
            log.debug("PersonBackgroundResource accepted json for uuid: " + uuid);
View Full Code Here

TOP

Related Classes of org.eurekastreams.server.domain.Background

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.