Package org.apache.jetspeed.container

Examples of org.apache.jetspeed.container.PortletEntity


        Mock mockf1 = new Mock(Fragment.class);
        mockf1.expects(new InvokeAtLeastOnceMatcher()).method("getName").will(new ReturnStub(pd.getUniqueName()));
        mockf1.expects(new InvokeAtLeastOnceMatcher()).method("getId").will(new ReturnStub(TEST_ENTITY));
        ContentFragment f1 = new ContentFragmentTestImpl((Fragment) mockf1.proxy(), new HashMap());

        PortletEntity entity = entityAccess
                .generateEntityFromFragment(new ContentFragmentTestImpl(f1, new HashMap()));
        // TODO: how to access prefs of entity??
        /*
        PreferenceSetComposite prefs = (PreferenceSetComposite) entity.getPreferenceSet();
        prefs.remove("pref1");
View Full Code Here


    }

    private void teardownTestData() throws Exception
    {

        PortletEntity entity = entityAccess.getPortletEntity(TEST_ENTITY);
        System.out.println("entity == " + entity);

        if (entity != null)
        {
            entityAccess.removePortletEntity(entity);
View Full Code Here

    public PortletEntity generateEntityFromFragment( ContentFragment fragment)
            throws PortletEntityNotGeneratedException
    {
        PortletDefinition pd = registry.getPortletDefinitionByUniqueName(fragment.getName());
        String entityKey = generateEntityKey(fragment);
        PortletEntity portletEntity = null;

        if (pd != null)
        {
            portletEntity = newPortletEntityInstance(pd);
            if (portletEntity == null)
            {
                throw new PortletEntityNotGeneratedException("Failed to create Portlet Entity for "
                        + fragment.getName());
            }
        }
        else
        {
            String msg = "Failed to retrieve Portlet Definition for " + fragment.getName();
            logger.warn(msg);
            portletEntity = new PortletEntityImpl(fragment);
            fragment.overrideRenderedContent(msg);
        }

        portletEntity.setId(entityKey);

        return portletEntity;
    }
View Full Code Here

    protected PortletEntity getPortletEntity(String id, ContentFragment fragment) throws PortletEntityNotStoredException
    {
        Criteria c = new Criteria();
        c.addEqualTo("id", id.toString());
        Query q = QueryFactory.newQuery(PortletEntityImpl.class, c);
        PortletEntity portletEntity = (PortletEntity) getPersistenceBrokerTemplate().getObjectByQuery(q);
        if (portletEntity == null)
        {
            return null;
        }
        else
        {
            String portletUniqueName = portletEntity.getPortletUniqueName();
            PortletDefinition parentPortletDef = registry.getPortletDefinitionByUniqueName(portletUniqueName);
            if(parentPortletDef != null)
            {
                //Indication that the fragment has changed the portlet it references.
                if(fragment != null && !portletUniqueName.equals(fragment.getName()))
                {
                    parentPortletDef = registry.getPortletDefinitionByUniqueName(fragment.getName());
                    portletEntity.setPortletDefinition(parentPortletDef);
                    storePortletEntity(portletEntity);
                }
                else
                {
                    portletEntity.setPortletDefinition(parentPortletDef);
                }
            }
            else if(fragment != null && parentPortletDef == null)
            {
                // If we have no porlet definition but have a fragment, we see if the
                // unique name has changed and access the portlet definition
                // using that unique name.
                parentPortletDef = registry.getPortletDefinitionByUniqueName(fragment.getName());
                if ( parentPortletDef != null)
                {
                    portletEntity.setPortletDefinition(parentPortletDef);
                    storePortletEntity(portletEntity);
                }
            }
           
            if(parentPortletDef == null)
View Full Code Here

    public void removePortletEntities( PortletDefinition portletDefinition ) throws PortletEntityNotDeletedException
    {
        Iterator entities = getPortletEntities(portletDefinition).iterator();
        while (entities.hasNext())
        {
            PortletEntity entity = (PortletEntity) entities.next();
            removePortletEntity(entity);
        }

    }
View Full Code Here

        }
        assertNotNull("Portlet Def is null", pd);

        ContentFragmentImpl f1 = new ContentFragmentImpl(TEST_ENTITY);
        f1.setName(pd.getUniqueName());
        PortletEntity entity = entityAccess.generateEntityFromFragment(f1);

        // TODO: how to access prefs of entity??
        /*
        PreferenceSetComposite prefs = (PreferenceSetComposite) entity.getPreferenceSet();
        prefs.remove("pref1");
        assertNotNull(prefs);
        assertNull(prefs.get("pref1"));

        // test adding a pref
        prefs.add("pref1", Arrays.asList(new String[]
        { "1" }));
        assertNotNull(prefs.get("pref1"));

        // Remove should return the deleted pref
        assertNotNull(prefs.remove("pref1"));

        // Should be gone
        assertNull(prefs.get("pref1"));

        // Add it back so we can test tole back
        prefs.add("pref1", Arrays.asList(new String[]
        { "1" }));

        entityAccess.storePortletEntity(entity);

        prefs = (PreferenceSetComposite) entity.getPreferenceSet();

        assertNotNull(prefs.get("pref1"));
       
        PreferenceComposite pref = (PreferenceComposite) prefs.get("pref1");
       
        List<String> prefValues = pref.getValuesList();
       
        assertEquals(1, prefValues.size());
              
        prefValues.set(0, "2");
        pref.setValues(prefValues);

        prefValues = pref.getValuesList();
        assertEquals("2", prefValues.get(0));

        prefValues.add("3");
        prefs.add("pref2", prefValues);

        entity.store();

        prefs = (PreferenceSetComposite)entity.getPreferenceSet();
        PreferenceComposite pref2 = (PreferenceComposite) prefs.get("pref2");

        assertNotNull(pref2);

        prefValues = pref2.getValuesList();
        assertEquals(2, prefValues.size());

        pref2.addValue("4");
        prefValues = pref2.getValuesList();
        assertEquals(3, prefValues.size());
        assertEquals("2", prefValues.get(0));
        assertEquals("3", prefValues.get(1));
        assertEquals("4", prefValues.get(2));

        // testing preferences null values assignments fix, issue JS2-607
        prefValues.set(0,null);
        pref2.setValues(prefValues);
        entity.store();
       
        prefs = (PreferenceSetComposite)entity.getPreferenceSet();
        pref2 = (PreferenceComposite) prefs.get("pref2");
       
        prefValues = pref2.getValuesList();
        assertNull("pref2.value[0] should be null", prefValues.get(0));
       
        assertEquals(3, prefValues.size());
        assertEquals("3", prefValues.get(1));
        prefValues.set(0, "2");
        prefValues.set(1, null);
        prefValues.set(2, "3");
        pref2.setValues(prefValues);
       
        entity.store();

        prefs = (PreferenceSetComposite)entity.getPreferenceSet();
        pref2 = (PreferenceComposite) prefs.get("pref2");
       
        prefValues = pref2.getValuesList();
        assertNull("pref2.value[1] should be null", prefValues.get(1));
       
        assertTrue(pref2.isValueSet());
        pref2.setValues(null);       
        assertFalse(pref2.isValueSet());

        entity.store();

        prefs = (PreferenceSetComposite)entity.getPreferenceSet();
        pref2 = (PreferenceComposite) prefs.get("pref2");

        assertNull(pref2);
        */
       
        PortletEntity entity2 = entityAccess.getPortletEntityForFragment(f1);
        assertTrue("entity id ", entity2.getId().toString().equals(TEST_ENTITY));
        assertNotNull("entity's portlet ", entity2.getPortletDefinition());

        PortletEntity entity5 = entityAccess.newPortletEntityInstance(pd);
        System.out.println("before storing entity: " + entity5.getId());

        entityAccess.storePortletEntity(entity5);
        System.out.println("store done: " + entity5.getId());

        ContentFragmentImpl f2 = new ContentFragmentImpl(TEST_ENTITY);
        f2.setName(pd.getUniqueName());

        PortletEntity entity6 = entityAccess.getPortletEntityForFragment(f2);
        assertNotNull(entity6);
        System.out.println("reget : " + entity6.getId());

        entityAccess.removePortletEntity(entity6);
    }
View Full Code Here

    }

    private void teardownTestData() throws Exception
    {

        PortletEntity entity = entityAccess.getPortletEntity(TEST_ENTITY);
        System.out.println("entity == " + entity);

        if (entity != null)
        {
            entityAccess.removePortletEntity(entity);
View Full Code Here

    public PortletEntity generateEntityFromFragment( ContentFragment fragment)
            throws PortletEntityNotGeneratedException
    {
        PortletDefinition pd = registry.getPortletDefinitionByUniqueName(fragment.getName());
        String entityKey = generateEntityKey(fragment);
        PortletEntity portletEntity = null;

        if (pd != null)
        {
            portletEntity = newPortletEntityInstance(pd);
            if (portletEntity == null)
            {
                throw new PortletEntityNotGeneratedException("Failed to create Portlet Entity for "
                        + fragment.getName());
            }
        }
        else
        {
            String msg = "Failed to retrieve Portlet Definition for " + fragment.getName();
            logger.warn(msg);
            portletEntity = new PortletEntityImpl(fragment);
            fragment.overrideRenderedContent(msg);
        }

        portletEntity.setId(entityKey);

        return portletEntity;
    }
View Full Code Here

    protected PortletEntity getPortletEntity(String id, ContentFragment fragment) throws PortletEntityNotStoredException
    {
        Criteria c = new Criteria();
        c.addEqualTo("id", id.toString());
        Query q = QueryFactory.newQuery(PortletEntityImpl.class, c);
        PortletEntity portletEntity = (PortletEntity) getPersistenceBrokerTemplate().getObjectByQuery(q);
        if (portletEntity == null)
        {
            return null;
        }
        else
        {
            String portletUniqueName = portletEntity.getPortletUniqueName();
            PortletDefinition parentPortletDef = registry.getPortletDefinitionByUniqueName(portletUniqueName);
            if(parentPortletDef != null)
            {
                //Indication that the fragment has changed the portlet it references.
                if(fragment != null && !portletUniqueName.equals(fragment.getName()))
                {
                    parentPortletDef = registry.getPortletDefinitionByUniqueName(fragment.getName());
                    portletEntity.setPortletDefinition(parentPortletDef);
                    storePortletEntity(portletEntity);
                }
                else
                {
                    portletEntity.setPortletDefinition(parentPortletDef);
                }
            }
            else if(fragment != null && parentPortletDef == null)
            {
                // If we have no porlet definition but have a fragment, we see if the
                // unique name has changed and access the portlet definition
                // using that unique name.
                parentPortletDef = registry.getPortletDefinitionByUniqueName(fragment.getName());
                if ( parentPortletDef != null)
                {
                    portletEntity.setPortletDefinition(parentPortletDef);
                    storePortletEntity(portletEntity);
                }
            }
           
            if(parentPortletDef == null)
View Full Code Here

    public void removePortletEntities( PortletDefinition portletDefinition ) throws PortletEntityNotDeletedException
    {
        Iterator entities = getPortletEntities(portletDefinition).iterator();
        while (entities.hasNext())
        {
            PortletEntity entity = (PortletEntity) entities.next();
            removePortletEntity(entity);
        }

    }
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.container.PortletEntity

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.