Search in sources :

Example 11 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class JpaPortletEntityDao method getPortletEntities.

@Override
@DialectAwareTransactional(value = PostgreSQL81Dialect.class, exclude = false)
@PortalTransactionalReadOnly
@OpenEntityManager(unitName = PERSISTENCE_UNIT_NAME)
public Set<IPortletEntity> getPortletEntities(IPortletDefinitionId portletDefinitionId) {
    Validate.notNull(portletDefinitionId, "portletEntity can not be null");
    final IPortletDefinition portletDefinition = this.portletDefinitionDao.getPortletDefinition(portletDefinitionId);
    final TypedQuery<PortletEntityImpl> query = this.createCachedQuery(this.findEntitiesForDefinitionQuery);
    query.setParameter(this.portletDefinitionParameter, (PortletDefinitionImpl) portletDefinition);
    final List<PortletEntityImpl> portletEntities = query.getResultList();
    return new HashSet<IPortletEntity>(portletEntities);
}
Also used : IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) HashSet(java.util.HashSet) DialectAwareTransactional(org.apereo.portal.spring.tx.DialectAwareTransactional) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager)

Example 12 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class JpaPortletDaoTest method testAllDefinitionDaoMethods.

@Test
public void testAllDefinitionDaoMethods() throws Exception {
    final IPortletDefinitionId portletDefinitionId = execute(new Callable<IPortletDefinitionId>() {

        @Override
        public IPortletDefinitionId call() {
            final IPortletType channelType = jpaChannelTypeDao.createPortletType("BaseType", "foobar");
            //Create a definition
            final IPortletDefinition chanDef1 = new PortletDefinitionImpl(channelType, "fname1", "Test Portlet 1", "Test Portlet 1 Title", "/context1", "portletName1", false);
            jpaPortletDefinitionDao.savePortletDefinition(chanDef1);
            //Try all of the retrieval options
            final IPortletDefinition portDef1a = jpaPortletDefinitionDao.getPortletDefinition(chanDef1.getPortletDefinitionId());
            jpaPortletDefinitionDao.savePortletDefinition(chanDef1);
            assertEquals(chanDef1, portDef1a);
            //Create a second definition with the same app/portlet
            final IPortletDefinition chanDef2 = new PortletDefinitionImpl(channelType, "fname2", "Test Portlet 2", "Test Portlet 2 Title", "/uPortal", "portletName2", true);
            jpaPortletDefinitionDao.savePortletDefinition(chanDef2);
            return chanDef2.getPortletDefinitionId();
        }
    });
    execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final IPortletDefinition chanDef2 = jpaPortletDefinitionDao.getPortletDefinitionByFname("fname2");
            // Add some preferences
            final List<IPortletPreference> prefsList2 = chanDef2.getPortletPreferences();
            prefsList2.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
            prefsList2.add(new PortletPreferenceImpl("prefName2", true, "val3", "val4"));
            jpaPortletDefinitionDao.savePortletDefinition(chanDef2);
        }
    });
    execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final IPortletDefinition chanDef2 = jpaPortletDefinitionDao.getPortletDefinitionByFname("fname2");
            // verify preferences
            final List<IPortletPreference> prefsList2 = chanDef2.getPortletPreferences();
            assertEquals(2, prefsList2.size());
        }
    });
    execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            // Check prefs, remove one and another
            final IPortletDefinition portDef3 = jpaPortletDefinitionDao.getPortletDefinitionByName("Test Portlet 2");
            final List<IPortletPreference> prefsList3 = portDef3.getPortletPreferences();
            final List<IPortletPreference> expectedPrefsList3 = new ArrayList<IPortletPreference>();
            expectedPrefsList3.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
            expectedPrefsList3.add(new PortletPreferenceImpl("prefName2", true, "val3", "val4"));
            assertEquals(expectedPrefsList3, prefsList3);
            prefsList3.remove(1);
            prefsList3.add(new PortletPreferenceImpl("prefName3", false, "val5", "val6"));
            jpaPortletDefinitionDao.savePortletDefinition(portDef3);
        }
    });
    execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            // Check prefs
            final IPortletDefinition portDef4 = jpaPortletDefinitionDao.getPortletDefinition(portletDefinitionId);
            final List<IPortletPreference> prefsList4 = portDef4.getPortletPreferences();
            final List<IPortletPreference> expectedPrefsList4 = new ArrayList<IPortletPreference>();
            expectedPrefsList4.add(new PortletPreferenceImpl("prefName1", false, "val1", "val2"));
            expectedPrefsList4.add(new PortletPreferenceImpl("prefName3", false, "val5", "val6"));
            assertEquals(expectedPrefsList4, prefsList4);
        }
    });
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) IPortletType(org.apereo.portal.portlet.om.IPortletType) ArrayList(java.util.ArrayList) List(java.util.List) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Example 13 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class JpaPortletDaoTest method testAllEntityDaoMethods.

@Test
public void testAllEntityDaoMethods() throws Exception {
    final IPortletDefinitionId portletDefinitionId = execute(new Callable<IPortletDefinitionId>() {

        @Override
        public IPortletDefinitionId call() throws Exception {
            final IPortletType channelType = jpaChannelTypeDao.createPortletType("BaseType", "foobar");
            //Create a definition
            final IPortletDefinition chanDef1 = new PortletDefinitionImpl(channelType, "fname1", "Test Portlet 1", "Test Portlet 1 Title", "/context1", "portletName1", false);
            jpaPortletDefinitionDao.savePortletDefinition(chanDef1);
            return chanDef1.getPortletDefinitionId();
        }
    });
    final IPortletEntityId portletEntityId = execute(new Callable<IPortletEntityId>() {

        @Override
        public IPortletEntityId call() throws Exception {
            IPortletEntity portEnt1 = jpaPortletEntityDao.createPortletEntity(portletDefinitionId, "chanSub1", 1);
            return portEnt1.getPortletEntityId();
        }
    });
    execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            final IPortletEntity portEnt1a = jpaPortletEntityDao.getPortletEntity(portletEntityId);
            assertNotNull(portEnt1a);
            final IPortletEntity portEnt1b = jpaPortletEntityDao.getPortletEntity("chanSub1", 1);
            assertEquals(portEnt1a, portEnt1b);
            final IPortletEntity portEnt1c = jpaPortletEntityDao.getPortletEntity("chanSub1", 1);
            assertEquals(portEnt1b, portEnt1c);
            final Set<IPortletEntity> portletEntities1 = jpaPortletEntityDao.getPortletEntities(portletDefinitionId);
            assertEquals(Collections.singleton(portEnt1a), portletEntities1);
            final Set<IPortletEntity> portletEntitiesByUser = jpaPortletEntityDao.getPortletEntitiesForUser(1);
            assertEquals(Collections.singleton(portEnt1a), portletEntitiesByUser);
            return null;
        }
    });
    execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            //Add entity and preferences
            final IPortletDefinition portDef1 = jpaPortletDefinitionDao.getPortletDefinition(portletDefinitionId);
            portDef1.getPortletPreferences().add(new PortletPreferenceImpl("defpref1", false, "dpv1", "dpv2"));
            jpaPortletDefinitionDao.savePortletDefinition(portDef1);
            final IPortletEntity portEnt1 = jpaPortletEntityDao.getPortletEntity(portletEntityId);
            portEnt1.getPortletPreferences().add(new PortletPreferenceImpl("entpref1", false, "epv1", "epv2"));
            //                portEnt1.setWindowState(WindowState.MINIMIZED);
            jpaPortletEntityDao.updatePortletEntity(portEnt1);
            return null;
        }
    });
    execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            //Delete whole tree
            final IPortletDefinition portDef2 = jpaPortletDefinitionDao.getPortletDefinition(portletDefinitionId);
            jpaPortletDefinitionDao.deletePortletDefinition(portDef2);
            return null;
        }
    });
    execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            //Verify it is gone
            final Set<IPortletEntity> portletEntities2 = jpaPortletEntityDao.getPortletEntities(portletDefinitionId);
            assertEquals(Collections.emptySet(), portletEntities2);
            return null;
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletType(org.apereo.portal.portlet.om.IPortletType) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Example 14 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class GuestPortletEntityPreferencesImpl method loadBasePortletPreferences.

@Override
protected void loadBasePortletPreferences(IPortletEntity portletEntity, Map<String, IPortletPreference> basePortletPreferences) {
    final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
    //Add descriptor prefs to base Map
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
    final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
    for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
        final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
        basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
    }
    //Add definition prefs to base Map
    final List<IPortletPreference> definitionPreferences = portletDefinition.getPortletPreferences();
    for (final IPortletPreference preference : definitionPreferences) {
        basePortletPreferences.put(preference.getName(), preference);
    }
    //Add entity prefs to base Map
    final List<IPortletPreference> entityPreferences = portletEntity.getPortletPreferences();
    for (final IPortletPreference preference : entityPreferences) {
        basePortletPreferences.put(preference.getName(), preference);
    }
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Preference(org.apache.pluto.container.om.portlet.Preference) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Preferences(org.apache.pluto.container.om.portlet.Preferences) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Example 15 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class PortletDefinitionPreferencesImpl method loadBasePortletPreferences.

@Override
protected void loadBasePortletPreferences(IPortletDefinition portletDefinition, Map<String, IPortletPreference> basePortletPreferences) {
    //Add descriptor prefs to base Map
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
    final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
    for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
        final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
        basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
    }
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Preference(org.apache.pluto.container.om.portlet.Preference) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Preferences(org.apache.pluto.container.om.portlet.Preferences) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Aggregations

IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)103 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)24 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)23 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)17 ArrayList (java.util.ArrayList)14 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)14 HashSet (java.util.HashSet)13 IPerson (org.apereo.portal.security.IPerson)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)12 EntityIdentifier (org.apereo.portal.EntityIdentifier)10 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)9 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)9 HashMap (java.util.HashMap)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 IUserInstance (org.apereo.portal.user.IUserInstance)7 Locale (java.util.Locale)6 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)6 PortalException (org.apereo.portal.PortalException)6 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)6