Package org.apache.jetspeed.om.common.portlet

Examples of org.apache.jetspeed.om.common.portlet.MutablePortletEntity


    public MutablePortletEntity generateEntityFromFragment( ContentFragment fragment, String principal )
            throws PortletEntityNotGeneratedException
    {
        PortletDefinition pd = registry.getPortletDefinitionByUniqueName(fragment.getName());
        ObjectID entityKey = generateEntityKey(fragment, principal);
        MutablePortletEntity 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();
            log.warn(msg);
            portletEntity = new PortletEntityImpl();
            fragment.overrideRenderedContent(msg);
        }
       
        portletEntity.setId(entityKey.toString());

        return portletEntity;
    }
View Full Code Here


            prepareTransaction(store);

            Filter filter = store.newFilter();
            filter.addEqualTo("id", entityId.toString());
            Object q = store.newQuery(PortletEntityImpl.class, filter);
            MutablePortletEntity portletEntity = (MutablePortletEntity) store.getObjectByQuery(q);
            if (portletEntity == null)
            {
                return null;
            }
            else
            {

                String portletUniqueName = portletEntity.getPortletUniqueName();
                PortletDefinitionComposite parentPortletDef = registry
                        .getPortletDefinitionByUniqueName(portletUniqueName);
                ((PortletEntityCtrl) portletEntity).setPortletDefinition(parentPortletDef);
                entityCache.put(entityId, portletEntity);
                return (PortletEntityImpl) portletEntity;
View Full Code Here

    public MutablePortletEntity generateEntityFromFragment( ContentFragment fragment, String principal )
            throws PortletEntityNotGeneratedException
    {
        PortletDefinition pd = registry.getPortletDefinitionByUniqueName(fragment.getName());
        ObjectID entityKey = generateEntityKey(fragment, principal);
        MutablePortletEntity 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.overrideRenderedContent(msg);
        }

        portletEntity.setId(entityKey.toString());

        return portletEntity;
    }
View Full Code Here

    public MutablePortletEntity getPortletEntity( ObjectID id )
    {
        Criteria c = new Criteria();
        c.addEqualTo("id", id.toString());
        Query q = QueryFactory.newQuery(PortletEntityImpl.class, c);
        MutablePortletEntity portletEntity = (MutablePortletEntity) getPersistenceBrokerTemplate().getObjectByQuery(q);
        if (portletEntity == null)
        {
            return null;
        }
        else
        {

            String portletUniqueName = portletEntity.getPortletUniqueName();
            PortletDefinitionComposite parentPortletDef = registry.getPortletDefinitionByUniqueName(portletUniqueName);
            if(parentPortletDef != null)
            {
                ((PortletEntityCtrl) portletEntity).setPortletDefinition(parentPortletDef);
                return (MutablePortletEntity) portletEntity;
            }
            else
            {
                logger.warn("No parent portlet definition could be located using unique name: "+portletUniqueName+
                            ".  Unless you plan on redploying this portlet definition, it is highly recommended "+
                            "that you delete the orphaned portlet entity with the id: "+portletEntity.getId());
                return (MutablePortletEntity) portletEntity;
            }
               
        }
    }
View Full Code Here

   
    private PortletWindow createPortletWindow(ContentFragment fragment, String principal) throws FailedToCreateWindowException
    {
        PortletWindow portletWindow = new PortletWindowImpl(fragment.getId());
               
        MutablePortletEntity portletEntity = entityAccessor.getPortletEntityForFragment(fragment, principal);
        if (portletEntity == null)
        {
            log.info("No portlet entity defined for fragment ID "+fragment.getId()+" attempting to auto-generate...");
            try
            {
                portletEntity = entityAccessor.generateEntityFromFragment(fragment, principal);
                // not portlet definition most likely means that the portlet has not been deployed so dont worry about storing off the entity
                if(portletEntity.getPortletDefinition() != null)
                {
                    entityAccessor.storePortletEntity(portletEntity);
                }
            }
            catch (PortletEntityNotGeneratedException e)
View Full Code Here

        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));
        Fragment f1 =(Fragment) mockf1.proxy();
           
        MutablePortletEntity entity = entityAccess.generateEntityFromFragment(new ContentFragmentImpl(f1, new HashMap()));
        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");
       
        assertEquals("1", pref.getValueAt(0));
       
        pref.setValueAt(0, "2");
       
        assertEquals("2", pref.getValueAt(0));
       
        entity.reset();
       
        pref = (PreferenceComposite) prefs.get("pref1");
       
        assertEquals("1", pref.getValueAt(0));
       
        prefs.remove(pref);      
       
        assertNull(prefs.get("pref1"));
       
        entity.reset();
       
        assertNotNull(prefs.get("pref1"));
       
        prefs.add("pref2", Arrays.asList(new String[]{"2", "3"}));
       
        entity.store();
       
        PreferenceComposite pref2 = (PreferenceComposite) prefs.get("pref2");
       
        assertNotNull(pref2);
       
        Iterator prefsValues = pref2.getValues();
        int count = 0;
        while(prefsValues.hasNext())
        {
            prefsValues.next();
            count++;
        }
       
        assertEquals(2, count);
       
        pref2.addValue("4");
        prefsValues = pref2.getValues();
        count = 0;
        while(prefsValues.hasNext())
        {
            assertEquals(String.valueOf(count+2), prefsValues.next());
            count++;
        }
        assertEquals(3, count);
       
        entity.reset();
       
        prefsValues = pref2.getValues();
        count = 0;
        while(prefsValues.hasNext())
        {
            assertEquals(String.valueOf(count+2), prefsValues.next());
            count++;
        }
        assertEquals(2, count);
       
        MutablePortletEntity entity2 = entityAccess.getPortletEntityForFragment(f1);
        assertTrue("entity id ", entity2.getId().toString().equals(TEST_ENTITY));
        assertNotNull("entity's portlet ", entity2.getPortletDefinition());
        mockf1.verify();
       
       
        Mock mockf2 = new Mock(Fragment.class);
        mockf2.expects(new InvokeAtLeastOnceMatcher()).method("getName").will(new ReturnStub(pd.getUniqueName()));
        Fragment f2 =(Fragment) mockf2.proxy();
       
        MutablePortletEntity entity5 = entityAccess.newPortletEntityInstance(pd);
       
        System.out.println("before storing entity: "  + entity5.getId());
       
        entityAccess.storePortletEntity(entity5);
        System.out.println("store done: " + entity5.getId())
        mockf2.expects(new InvokeAtLeastOnceMatcher()).method("getId").will(new ReturnStub( entity5.getId().toString()));
   
        MutablePortletEntity entity6 = entityAccess.getPortletEntityForFragment(f2);
        assertNotNull(entity6);
        System.out.println("reget : " + entity6.getId());       
       
        entityAccess.removePortletEntity(entity6);
       
               
    }
View Full Code Here

    throws Exception
    {  
       
       
        JetspeedObjectID objId = JetspeedObjectID.createFromString(TEST_ENTITY);
        MutablePortletEntity entity = entityAccess.getPortletEntity(objId);
        System.out.println("entity == " + entity);
       
        if (entity != null)
        {
            entityAccess.removePortletEntity(entity);
View Full Code Here

        if (pd == null)
        {
            throw new PortletEntityNotGeneratedException("Failed to retrieve Portlet Definition for "
                    + fragment.getName());
        }
        MutablePortletEntity portletEntity = newPortletEntityInstance(pd);
        if (portletEntity == null)
        {
            throw new PortletEntityNotGeneratedException("Failed to create Portlet Entity for " + fragment.getName());
        }
        portletEntity.setId(entityKey.toString());

        return portletEntity;
    }
View Full Code Here

            prepareTransaction(store);

            Filter filter = store.newFilter();
            filter.addEqualTo("id", entityId.toString());
            Object q = store.newQuery(PortletEntityImpl.class, filter);
            MutablePortletEntity portletEntity = (MutablePortletEntity) store.getObjectByQuery(q);
            if (portletEntity == null)
            {
                return null;
            }
            else
            {
               
                String portletUniqueName = portletEntity.getPortletUniqueName();
                PortletDefinitionComposite parentPortletDef = registry
                        .getPortletDefinitionByUniqueName(portletUniqueName);
                ((PortletEntityCtrl) portletEntity).setPortletDefinition(parentPortletDef);
                entityCache.put(entityId, portletEntity);
                return (PortletEntityImpl) portletEntity;
View Full Code Here

        {
            throw new PortletEntityNotGeneratedException("Failed to retrieve Portlet Definition for "
                    + fragment.getName());
        }

        MutablePortletEntity portletEntity = newPortletEntityInstance(pd);
        if (portletEntity == null)
        {
            throw new PortletEntityNotGeneratedException("Failed to create Portlet Entity for " + fragment.getName());
        }
        portletEntity.setId(entityKey.toString());

        return portletEntity;
    }
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.om.common.portlet.MutablePortletEntity

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.