Search in sources :

Example 11 with IPortletEntity

use of org.apereo.portal.portlet.om.IPortletEntity 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)

Example 12 with IPortletEntity

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

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

the class PortletEntityRegistryImplTest method testPersistentRemovePrefs.

//persistent with no prefs & in db - delete & create interim
@Test
public void testPersistentRemovePrefs() 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);
            //Add a preference
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            final IPortletPreference portletPreference = new PortletPreferenceImpl("pref", false, "value");
            preferences.add(portletPreference);
            //Store the entity
            portletEntityRegistry.storePortletEntity(request, portletEntity);
            return null;
        }
    });
    this.execute(new Callable<Object>() {

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

        @Override
        public Object call() throws Exception {
            //Verify it switched from persistent to interim
            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) 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 14 with IPortletEntity

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

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

the class PortletEntityPreferencesImpl method storeInternal.

@Override
protected boolean storeInternal() throws IOException, ValidatorException {
    final HttpServletRequest containerRequest = portletRequestContext.getContainerRequest();
    final IPortletEntity portletEntity = this.portletEntityRegistry.getPortletEntity(containerRequest, portletEntityId);
    final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
    final Lock portletEntityLock = this.portletEntityRegistry.getPortletEntityLock(containerRequest, portletEntityId);
    //Do a tryLock first so that we can warn about concurrent preference modification if it fails
    boolean locked = portletEntityLock.tryLock();
    try {
        if (!locked) {
            logger.warn("Concurrent portlet preferences modification by: " + portletEntity + " " + "This has the potential for changes to preferences to be lost. " + "This portlet should be modified to synchronize its preference modifications appropriately", new Throwable());
            portletEntityLock.lock();
            locked = true;
        }
        return this.transactionOperations.execute(new TransactionCallback<Boolean>() {

            @Override
            public Boolean doInTransaction(TransactionStatus status) {
                //Refresh the entity to avoid optimistic locking errors
                final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(containerRequest, portletEntityId);
                final Map<String, IPortletPreference> targetPortletPreferences = getTargetPortletPreferences();
                final Collection<IPortletPreference> values = targetPortletPreferences.values();
                final boolean modified = portletEntity.setPortletPreferences(new ArrayList<IPortletPreference>(values));
                if (!modified) {
                    //Nothing actually changed, skip the store
                    return Boolean.FALSE;
                }
                portletEntityRegistry.storePortletEntity(containerRequest, portletEntity);
                return Boolean.TRUE;
            }
        });
    } finally {
        //check if locked, needed due to slightly more complex logic around the tryLock and logging
        if (locked) {
            portletEntityLock.unlock();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus) Lock(java.util.concurrent.locks.Lock) HttpServletRequest(javax.servlet.http.HttpServletRequest) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) Collection(java.util.Collection) Map(java.util.Map) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId)

Aggregations

IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)63 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)32 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)25 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)24 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)19 IUserInstance (org.apereo.portal.user.IUserInstance)12 Test (org.junit.Test)11 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)10 List (java.util.List)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)9 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)9 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)9 IPerson (org.apereo.portal.security.IPerson)7 PortletApplicationDefinition (org.apache.pluto.container.om.portlet.PortletApplicationDefinition)5 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)5 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)5 ArrayList (java.util.ArrayList)4 Callable (java.util.concurrent.Callable)4