Search in sources :

Example 1 with IPortletDefinitionId

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

the class PortletEventCoordinatationService method supportsEvent.

protected boolean supportsEvent(Event event, IPortletDefinitionId portletDefinitionId) {
    final QName eventName = event.getQName();
    // The cache key to use
    final Tuple<IPortletDefinitionId, QName> key = new Tuple<IPortletDefinitionId, QName>(portletDefinitionId, eventName);
    // Check in the cache if the portlet definition supports this event
    final Element element = this.supportedEventCache.get(key);
    if (element != null) {
        final Boolean supported = (Boolean) element.getObjectValue();
        if (supported != null) {
            return supported;
        }
    }
    final PortletApplicationDefinition portletApplicationDescriptor = this.portletDefinitionRegistry.getParentPortletApplicationDescriptor(portletDefinitionId);
    if (portletApplicationDescriptor == null) {
        return false;
    }
    final Set<QName> aliases = this.getAllAliases(eventName, portletApplicationDescriptor);
    final String defaultNamespace = portletApplicationDescriptor.getDefaultNamespace();
    // No support found so far, do more complex namespace matching
    final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
    if (portletDescriptor == null) {
        return false;
    }
    final List<? extends EventDefinitionReference> supportedProcessingEvents = portletDescriptor.getSupportedProcessingEvents();
    for (final EventDefinitionReference eventDefinitionReference : supportedProcessingEvents) {
        final QName qualifiedName = eventDefinitionReference.getQualifiedName(defaultNamespace);
        if (qualifiedName == null) {
            continue;
        }
        // Look for alias names
        if (qualifiedName.equals(eventName) || aliases.contains(qualifiedName)) {
            this.supportedEventCache.put(new Element(key, Boolean.TRUE));
            return true;
        }
        // Look for namespaced events
        if (StringUtils.isEmpty(qualifiedName.getNamespaceURI())) {
            final QName namespacedName = new QName(defaultNamespace, qualifiedName.getLocalPart());
            if (eventName.equals(namespacedName)) {
                this.supportedEventCache.put(new Element(key, Boolean.TRUE));
                return true;
            }
        }
    }
    this.supportedEventCache.put(new Element(key, Boolean.FALSE));
    return false;
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) EventDefinitionReference(org.apache.pluto.container.om.portlet.EventDefinitionReference) PortletApplicationDefinition(org.apache.pluto.container.om.portlet.PortletApplicationDefinition) QName(javax.xml.namespace.QName) Element(net.sf.ehcache.Element) JAXBElement(javax.xml.bind.JAXBElement) Tuple(org.apereo.portal.utils.Tuple) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Example 2 with IPortletDefinitionId

use of org.apereo.portal.portlet.om.IPortletDefinitionId 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 3 with IPortletDefinitionId

use of org.apereo.portal.portlet.om.IPortletDefinitionId 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 4 with IPortletDefinitionId

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

the class PortletEntityRegistryImplTest method testInterimNoPrefsAlreadyPersistent.

// interim with no prefs & in db - delete db version
@Test
public void testInterimNoPrefsAlreadyPersistent() throws Throwable {
    final IPortletDefinitionId portDefId1 = this.createDefaultPorltetDefinition();
    final String nodeId = "u1l1n1";
    // Mock setup
    final MockHttpServletRequest request = new MockHttpServletRequest();
    when(portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
    when(portalRequestUtils.getOriginalPortletOrPortalRequest(request)).thenReturn(request);
    when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
    when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
    when(userInstance.getPerson()).thenReturn(person);
    when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
    when(userLayoutManager.getNode(nodeId)).thenReturn(node);
    when(node.getType()).thenReturn(LayoutNodeType.PORTLET);
    when(node.getChannelPublishId()).thenReturn(portDefId1.getStringId());
    final IPortletEntityId portletEntityId = this.execute(new Callable<IPortletEntityId>() {

        @Override
        public IPortletEntityId call() throws Exception {
            // T1 - Create the entity
            final IPortletEntity portletEntity = portletEntityRegistry.getOrCreatePortletEntity(request, portDefId1, nodeId, 12);
            ;
            assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
            // T2 - get the entity and add preferences
            final IPortletEntityId portletEntityId = executeInThread("T2.1", new Callable<IPortletEntityId>() {

                @Override
                public IPortletEntityId call() throws Exception {
                    // T2 - Get entity
                    final IPortletEntity localPortletEntity = portletEntityRegistry.getPortletEntity(request, portletEntity.getPortletEntityId().getStringId());
                    assertEquals(portletEntity, localPortletEntity);
                    // T2 - Add a preference
                    final List<IPortletPreference> preferences = localPortletEntity.getPortletPreferences();
                    final IPortletPreference portletPreference = new PortletPreferenceImpl("pref2", false, "value");
                    preferences.add(portletPreference);
                    // T2 - Store the entity
                    portletEntityRegistry.storePortletEntity(request, localPortletEntity);
                    return localPortletEntity.getPortletEntityId();
                }
            });
            // T2 - verify entity was made persistent
            executeInThread("T2.2", new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    // T2 - Verify it was converted from interim to
                    // persistent
                    IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
                    assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
                    List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
                    assertEquals(1, preferences.size());
                    return null;
                }
            });
            // T1 - clear preferences
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            preferences.clear();
            // T1 - Store the entity
            portletEntityRegistry.storePortletEntity(request, portletEntity);
            return portletEntity.getPortletEntityId();
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            // T1 - Verify it was converted from interim to persistent
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            assertEquals(0, preferences.size());
            return null;
        }
    });
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Callable(java.util.concurrent.Callable) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) List(java.util.List) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Example 5 with IPortletDefinitionId

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

the class PortletEntityRegistryImplTest method testInterimNoPrefs.

// interim with no prefs & not in db - noop
@Test
public void testInterimNoPrefs() throws Exception {
    final IPortletDefinitionId portletDefId = this.createDefaultPorltetDefinition();
    final String nodeId = "u1l1n1";
    // Mock setup
    final MockHttpServletRequest request = new MockHttpServletRequest();
    when(portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
    when(portalRequestUtils.getOriginalPortletOrPortalRequest(request)).thenReturn(request);
    when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
    when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
    when(userInstance.getPerson()).thenReturn(person);
    when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
    when(userLayoutManager.getNode(nodeId)).thenReturn(node);
    when(node.getType()).thenReturn(LayoutNodeType.PORTLET);
    when(node.getChannelPublishId()).thenReturn(portletDefId.getStringId());
    final IPortletEntityId portletEntityId = this.execute(new Callable<IPortletEntityId>() {

        @Override
        public IPortletEntityId call() throws Exception {
            // Create the entity
            IPortletEntity portletEntity = portletEntityRegistry.getOrCreatePortletEntity(request, portletDefId, nodeId, 12);
            assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
            return portletEntity.getPortletEntityId();
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            // Store the entity
            portletEntityRegistry.storePortletEntity(request, portletEntity);
            return null;
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            // Verify it is still interim
            assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
            return null;
        }
    });
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Aggregations

IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)29 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)19 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)16 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)14 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)12 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)11 Test (org.junit.Test)11 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)10 List (java.util.List)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)7 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)6 Callable (java.util.concurrent.Callable)4 Preference (org.apache.pluto.container.om.portlet.Preference)3 Preferences (org.apache.pluto.container.om.portlet.Preferences)3 IUserInstance (org.apereo.portal.user.IUserInstance)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2