Search in sources :

Example 6 with IPortletPreference

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

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

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

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

the class PortletDefinitionBeanTest method testFromMarketplacePortletDefinition.

@Test
public void testFromMarketplacePortletDefinition() {
    Long id = 345L;
    String name = "testName";
    String[] keywords = new String[] { "val1", "val2" };
    List<IPortletPreference> prefs = new ArrayList<>();
    prefs.add(portletPref);
    Mockito.when(portletPref.getName()).thenReturn("keywords");
    Mockito.when(portletPref.getValues()).thenReturn(keywords);
    Map<String, IPortletDefinitionParameter> params = new HashMap<>();
    params.put("test1", portletDefParam);
    MarketplacePortletDefinition mpd = buildMarketplacePortletDefinition(id, name, prefs, params);
    PortletDefinitionBean pdb = PortletDefinitionBean.fromMarketplacePortletDefinition(mpd, Locale.ENGLISH, false);
    assertEquals(averageRating, pdb.getAverageRating());
    assertEquals(id, (Long) pdb.getId());
    assertEquals(fName, pdb.getFname());
    assertEquals(title, pdb.getTitle());
    assertEquals(name, pdb.getName());
    assertEquals(description, pdb.getDescription());
    assertEquals(state.toString(), pdb.getState());
    assertEquals(typeId, pdb.getTypeId());
    assertEquals(usersRated, (Long) pdb.getRatingsCount());
    assertEquals(params, pdb.getParameters());
    assertEquals(Arrays.asList(keywords), pdb.getKeywords());
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) HashMap(java.util.HashMap) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) MarketplacePortletDefinition(org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition) ArrayList(java.util.ArrayList) PortletDefinitionBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean) Test(org.junit.Test)

Example 10 with IPortletPreference

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

the class ExternalPortletDefinitionUnmarshaller method unmarshall.

/* package-private */
IPortletDefinition unmarshall(ExternalPortletDefinition epd) {
    final PortletDescriptor portletDescriptor = epd.getPortletDescriptor();
    final Boolean isFramework = portletDescriptor.isIsFramework();
    if (isFramework != null && isFramework && "UPGRADED_CHANNEL_IS_NOT_A_PORTLET".equals(portletDescriptor.getPortletName())) {
        if (errorOnChannel) {
            throw new IllegalArgumentException(epd.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and cannot be imported.");
        }
        logger.warn(epd.getFname() + " is not a portlet. It was likely an IChannel from a previous version of uPortal and will not be imported.");
        return null;
    }
    // get the portlet type
    final IPortletType portletType = portletTypeRegistry.getPortletType(epd.getType());
    if (portletType == null) {
        throw new IllegalArgumentException("No portlet type registered for: " + epd.getType());
    }
    final String fname = epd.getFname();
    IPortletDefinition rslt = portletDefinitionDao.getPortletDefinitionByFname(fname);
    if (rslt == null) {
        rslt = new PortletDefinitionImpl(portletType, fname, epd.getName(), epd.getTitle(), portletDescriptor.getWebAppName(), portletDescriptor.getPortletName(), isFramework != null ? isFramework : false);
    } else {
        final IPortletDescriptorKey portletDescriptorKey = rslt.getPortletDescriptorKey();
        portletDescriptorKey.setPortletName(portletDescriptor.getPortletName());
        if (isFramework != null && isFramework) {
            portletDescriptorKey.setFrameworkPortlet(true);
            portletDescriptorKey.setWebAppName(null);
        } else {
            portletDescriptorKey.setFrameworkPortlet(false);
            portletDescriptorKey.setWebAppName(portletDescriptor.getWebAppName());
        }
        rslt.setName(epd.getName());
        rslt.setTitle(epd.getTitle());
        rslt.setType(portletType);
    }
    rslt.setDescription(epd.getDesc());
    final BigInteger timeout = epd.getTimeout();
    if (timeout != null) {
        rslt.setTimeout(timeout.intValue());
    }
    final BigInteger actionTimeout = epd.getActionTimeout();
    if (actionTimeout != null) {
        rslt.setActionTimeout(actionTimeout.intValue());
    }
    final BigInteger eventTimeout = epd.getEventTimeout();
    if (eventTimeout != null) {
        rslt.setEventTimeout(eventTimeout.intValue());
    }
    final BigInteger renderTimeout = epd.getRenderTimeout();
    if (renderTimeout != null) {
        rslt.setRenderTimeout(renderTimeout.intValue());
    }
    final BigInteger resourceTimeout = epd.getResourceTimeout();
    if (resourceTimeout != null) {
        rslt.setResourceTimeout(resourceTimeout.intValue());
    }
    unmarshallLifecycle(epd.getLifecycle(), rslt);
    final Set<IPortletDefinitionParameter> parameters = new LinkedHashSet<>();
    for (ExternalPortletParameter param : epd.getParameters()) {
        parameters.add(new PortletDefinitionParameterImpl(param.getName(), param.getValue()));
    }
    rslt.setParameters(parameters);
    final ArrayList<IPortletPreference> preferenceList = new ArrayList<>();
    for (ExternalPortletPreference pref : epd.getPortletPreferences()) {
        final List<String> valueList = pref.getValues();
        final String[] values = valueList.toArray(new String[valueList.size()]);
        final Boolean readOnly = pref.isReadOnly();
        preferenceList.add(new PortletPreferenceImpl(pref.getName(), readOnly != null ? readOnly : false, values));
    }
    rslt.setPortletPreferences(preferenceList);
    return rslt;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) ArrayList(java.util.ArrayList) IPortletDescriptorKey(org.apereo.portal.portlet.om.IPortletDescriptorKey) PortletDescriptor(org.apereo.portal.xml.PortletDescriptor) IPortletType(org.apereo.portal.portlet.om.IPortletType) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) BigInteger(java.math.BigInteger) PortletDefinitionImpl(org.apereo.portal.portlet.dao.jpa.PortletDefinitionImpl) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinitionParameterImpl(org.apereo.portal.portlet.dao.jpa.PortletDefinitionParameterImpl)

Aggregations

IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)37 Test (org.junit.Test)18 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)15 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)12 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)11 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)10 List (java.util.List)8 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)8 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 ArrayList (java.util.ArrayList)6 Callable (java.util.concurrent.Callable)4 IPortletDescriptorKey (org.apereo.portal.portlet.om.IPortletDescriptorKey)4 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)3 Preference (org.apache.pluto.container.om.portlet.Preference)3 Preferences (org.apache.pluto.container.om.portlet.Preferences)3 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)3 IPortletType (org.apereo.portal.portlet.om.IPortletType)3 LinkedHashSet (java.util.LinkedHashSet)2 ReadOnlyException (javax.portlet.ReadOnlyException)2