Search in sources :

Example 6 with IPortletType

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

the class ExternalPortletDefinitionUnmarshallerTest method testUnmarshallLifecycle.

@Test
public void testUnmarshallLifecycle() {
    final long currentTimeMillis = System.currentTimeMillis();
    final String createdUser = "createdUser";
    final String approvedUser = "approvedUser";
    final String publishedUser = "publishedUser";
    final String expiredUser = "expiredUser";
    final String maintenanceUser = "maintenanceUser";
    final Calendar createdCalendar = getCalendarForMillis(currentTimeMillis - (5L * MILLIS_IN_ONE_DAY));
    final Calendar approvedCalendar = getCalendarForMillis(currentTimeMillis - (4L * MILLIS_IN_ONE_DAY));
    final Calendar publishedCalendar = getCalendarForMillis(currentTimeMillis - (3L * MILLIS_IN_ONE_DAY));
    final Calendar expiredCalendar = getCalendarForMillis(currentTimeMillis + MILLIS_IN_ONE_DAY);
    final Calendar maintenanceCalendar = getCalendarForMillis(currentTimeMillis - (2L * MILLIS_IN_ONE_DAY));
    // Created 5 days in the past
    final LifecycleEntry created = new LifecycleEntry();
    created.setName("CREATED");
    created.setUser(createdUser);
    created.setValue(createdCalendar);
    // Approved 4 days in the past
    final LifecycleEntry approved = new LifecycleEntry();
    approved.setName("APPROVED");
    approved.setUser(approvedUser);
    approved.setValue(approvedCalendar);
    // Published 3 days in the past
    final LifecycleEntry published = new LifecycleEntry();
    published.setName("PUBLISHED");
    published.setUser(publishedUser);
    published.setValue(publishedCalendar);
    // Expired 1 day in the future
    final LifecycleEntry expired = new LifecycleEntry();
    expired.setName("EXPIRED");
    expired.setUser(expiredUser);
    expired.setValue(expiredCalendar);
    // Maintenance mode 2 days in the past
    final LifecycleEntry maintenance = new LifecycleEntry();
    maintenance.setName("MAINTENANCE");
    maintenance.setUser(maintenanceUser);
    maintenance.setValue(maintenanceCalendar);
    final Lifecycle lifecycle1 = new Lifecycle();
    lifecycle1.getEntries().add(created);
    final Lifecycle lifecycle2 = new Lifecycle();
    lifecycle2.getEntries().add(created);
    lifecycle2.getEntries().add(approved);
    final Lifecycle lifecycle3 = new Lifecycle();
    lifecycle3.getEntries().add(published);
    lifecycle3.getEntries().add(expired);
    final Lifecycle lifecycle4 = new Lifecycle();
    lifecycle4.getEntries().add(created);
    lifecycle4.getEntries().add(approved);
    lifecycle4.getEntries().add(published);
    lifecycle4.getEntries().add(maintenance);
    lifecycle4.getEntries().add(expired);
    final Lifecycle[] lifecyclesToTest = new Lifecycle[] { lifecycle1, lifecycle2, lifecycle3, lifecycle4 };
    final IPortletLifecycleEntry[][] expectedPortletLifecycles = new IPortletLifecycleEntry[][] { // 1
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()) }, // 2
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()), new PortletLifecycleEntryImpl(approvedUser.hashCode(), PortletLifecycleState.APPROVED, approvedCalendar.getTime()) }, // 3
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(publishedUser.hashCode(), PortletLifecycleState.PUBLISHED, publishedCalendar.getTime()), new PortletLifecycleEntryImpl(expiredUser.hashCode(), PortletLifecycleState.EXPIRED, expiredCalendar.getTime()) }, // 4
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()), new PortletLifecycleEntryImpl(approvedUser.hashCode(), PortletLifecycleState.APPROVED, approvedCalendar.getTime()), new PortletLifecycleEntryImpl(publishedUser.hashCode(), PortletLifecycleState.PUBLISHED, publishedCalendar.getTime()), new PortletLifecycleEntryImpl(maintenanceUser.hashCode(), PortletLifecycleState.MAINTENANCE, maintenanceCalendar.getTime()), new PortletLifecycleEntryImpl(expiredUser.hashCode(), PortletLifecycleState.EXPIRED, expiredCalendar.getTime()) } };
    final ExternalPortletDefinitionUnmarshaller unmarshaller = new ExternalPortletDefinitionUnmarshaller();
    unmarshaller.setUserIdentityStore(new MockUserIdentityStore());
    final IPortletType portletType = new PortletTypeImpl("FakePortletType", "http://not/a/real/uri");
    for (int i = 0; i < lifecyclesToTest.length; i++) {
        final Lifecycle lifecycle = lifecyclesToTest[i];
        final IPortletDefinition pDef = new PortletDefinitionImpl(portletType, "fake-portlet", "Fake Portlet", "Fake Portlet", "FakePortletApp", "fake-portlet-def", false);
        unmarshaller.unmarshallLifecycle(lifecycle, pDef);
        final IPortletLifecycleEntry[] expectedLifecycle = expectedPortletLifecycles[i];
        for (IPortletLifecycleEntry y : pDef.getLifecycle()) {
            System.out.println(" ## ");
            System.out.println(" ## y.getLifecycleState()=" + y.getLifecycleState());
        }
        assertArrayEquals(pDef.getLifecycle().toArray(), expectedLifecycle);
    }
}
Also used : IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) PortletTypeImpl(org.apereo.portal.portlet.dao.jpa.PortletTypeImpl) Calendar(java.util.Calendar) PortletLifecycleEntryImpl(org.apereo.portal.portlet.dao.jpa.PortletLifecycleEntryImpl) IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) IPortletType(org.apereo.portal.portlet.om.IPortletType) PortletDefinitionImpl(org.apereo.portal.portlet.dao.jpa.PortletDefinitionImpl) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) Test(org.junit.Test)

Example 7 with IPortletType

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

the class PortletAdministrationHelper method savePortletRegistration.

/**
 * Persist a new or edited PortletDefinition from a form, replacing existing values.
 *
 * @param publisher {@code IPerson} that requires permission to save this definition
 * @param form form data to persist
 * @return new {@code PortletDefinitionForm} for this portlet ID
 */
public PortletDefinitionForm savePortletRegistration(IPerson publisher, PortletDefinitionForm form) throws Exception {
    logger.trace("In savePortletRegistration() - for: {}", form.getPortletName());
    // is made when the user enters the lifecycle-selection step in the wizard.)
    if (!hasLifecyclePermission(publisher, form.getLifecycleState(), form.getCategories())) {
        logger.warn("User '" + publisher.getUserName() + "' attempted to save the following portlet without the selected MANAGE permission:  " + form);
        throw new SecurityException("Not Authorized");
    }
    if (!form.isNew()) {
        // User must have the previous lifecycle permission
        // in AT LEAST ONE previous category as well
        IPortletDefinition def = this.portletDefinitionRegistry.getPortletDefinition(form.getId());
        Set<PortletCategory> categories = portletCategoryRegistry.getParentCategories(def);
        SortedSet<JsonEntityBean> categoryBeans = new TreeSet<>();
        for (PortletCategory cat : categories) {
            categoryBeans.add(new JsonEntityBean(cat));
        }
        if (!hasLifecyclePermission(publisher, def.getLifecycleState(), categoryBeans)) {
            logger.warn("User '" + publisher.getUserName() + "' attempted to save the following portlet without the previous MANAGE permission:  " + form);
            throw new SecurityException("Not Authorized");
        }
    }
    if (form.isNew() || portletDefinitionRegistry.getPortletDefinition(form.getId()).getType().getId() != form.getTypeId()) {
        // User must have access to the selected CPD if s/he selected it in this interaction
        final int selectedTypeId = form.getTypeId();
        final PortletPublishingDefinition cpd = portletPublishingDefinitionDao.getChannelPublishingDefinition(selectedTypeId);
        final Map<IPortletType, PortletPublishingDefinition> allowableCpds = this.getAllowableChannelPublishingDefinitions(publisher);
        if (!allowableCpds.containsValue(cpd)) {
            logger.warn("User '" + publisher.getUserName() + "' attempted to administer the following portlet without the selected " + IPermission.PORTLET_MANAGER_SELECT_PORTLET_TYPE + " permission:  " + form);
            throw new SecurityException("Not Authorized");
        }
    }
    // create the principal array from the form's principal list -- only principals with
    // permissions
    final Set<IGroupMember> subscribePrincipalSet = new HashSet<>(form.getPrincipals().size());
    final Set<IGroupMember> browsePrincipalSet = new HashSet<>(form.getPrincipals().size());
    final Set<IGroupMember> configurePrincipalSet = new HashSet<>(form.getPrincipals().size());
    for (JsonEntityBean bean : form.getPrincipals()) {
        final String subscribePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_SUBSCRIBER_ACTIVITY;
        final String browsePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_BROWSE_ACTIVITY;
        final String configurePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_MODE_CONFIG;
        final EntityEnum entityEnum = bean.getEntityType();
        final IGroupMember principal = entityEnum.isGroup() ? (GroupService.findGroup(bean.getId())) : (GroupService.getGroupMember(bean.getId(), entityEnum.getClazz()));
        if (form.getPermissions().contains(subscribePerm)) {
            logger.info("In savePortletRegistration() - Found a subscribePerm for principal: {}", principal);
            subscribePrincipalSet.add(principal);
        }
        if (form.getPermissions().contains(browsePerm)) {
            logger.info("In savePortletRegistration() - Found a browsePerm for principal: {}", principal);
            browsePrincipalSet.add(principal);
        }
        if (form.getPermissions().contains(configurePerm)) {
            logger.info("In savePortletRegistration() - Found a configurePerm for principal: {}", principal);
            configurePrincipalSet.add(principal);
        }
    }
    // create the category list from the form's category bean list
    List<PortletCategory> categories = new ArrayList<>();
    for (JsonEntityBean category : form.getCategories()) {
        String id = category.getId();
        String iCatID = id.startsWith("cat") ? id.substring(3) : id;
        categories.add(portletCategoryRegistry.getPortletCategory(iCatID));
    }
    final IPortletType portletType = portletTypeRegistry.getPortletType(form.getTypeId());
    if (portletType == null) {
        throw new IllegalArgumentException("No IPortletType exists for ID " + form.getTypeId());
    }
    IPortletDefinition portletDef;
    if (form.getId() == null) {
        portletDef = new PortletDefinitionImpl(portletType, form.getFname(), form.getName(), form.getTitle(), form.getApplicationId(), form.getPortletName(), form.isFramework());
    } else {
        portletDef = portletDefinitionRegistry.getPortletDefinition(form.getId());
        portletDef.setType(portletType);
        portletDef.setFName(form.getFname());
        portletDef.setName(form.getName());
        portletDef.setTitle(form.getTitle());
        portletDef.getPortletDescriptorKey().setWebAppName(form.getApplicationId());
        portletDef.getPortletDescriptorKey().setPortletName(form.getPortletName());
        portletDef.getPortletDescriptorKey().setFrameworkPortlet(form.isFramework());
    }
    portletDef.setDescription(form.getDescription());
    portletDef.setTimeout(form.getTimeout());
    // portletDef reflect the state of the form, in case any have changed.
    for (String key : form.getParameters().keySet()) {
        String value = form.getParameters().get(key).getValue();
        if (!StringUtils.isBlank(value)) {
            portletDef.addParameter(key, value);
        }
    }
    portletDef.addParameter(IPortletDefinition.EDITABLE_PARAM, Boolean.toString(form.isEditable()));
    portletDef.addParameter(IPortletDefinition.CONFIGURABLE_PARAM, Boolean.toString(form.isConfigurable()));
    portletDef.addParameter(IPortletDefinition.HAS_HELP_PARAM, Boolean.toString(form.isHasHelp()));
    portletDef.addParameter(IPortletDefinition.HAS_ABOUT_PARAM, Boolean.toString(form.isHasAbout()));
    // Now add portlet preferences
    List<IPortletPreference> preferenceList = new ArrayList<>();
    for (String key : form.getPortletPreferences().keySet()) {
        List<String> prefValues = form.getPortletPreferences().get(key).getValue();
        if (prefValues != null && prefValues.size() > 0) {
            String[] values = prefValues.toArray(new String[prefValues.size()]);
            BooleanAttribute readOnly = form.getPortletPreferenceReadOnly().get(key);
            preferenceList.add(new PortletPreferenceImpl(key, readOnly.getValue(), values));
        }
    }
    portletDef.setPortletPreferences(preferenceList);
    // Lastly update the PortletDefinition's lifecycle state & lifecycle-related metadata
    updateLifecycleState(form, portletDef, publisher);
    // The final parameter of IGroupMembers is used to set the initial SUBSCRIBE permission set
    portletPublishingService.savePortletDefinition(portletDef, publisher, categories, new ArrayList<>(subscribePrincipalSet));
    // updatePermissions(portletDef, subscribePrincipalSet,
    // IPermission.PORTLET_SUBSCRIBER_ACTIVITY);
    updatePermissions(portletDef, browsePrincipalSet, IPermission.PORTAL_SUBSCRIBE, IPermission.PORTLET_BROWSE_ACTIVITY);
    updatePermissions(portletDef, configurePrincipalSet, IPermission.PORTAL_PUBLISH, IPermission.PORTLET_MODE_CONFIG);
    return this.createPortletDefinitionForm(publisher, portletDef.getPortletDefinitionId().getStringId());
}
Also used : BooleanAttribute(org.apereo.portal.portlets.BooleanAttribute) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) ArrayList(java.util.ArrayList) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) TreeSet(java.util.TreeSet) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) HashSet(java.util.HashSet) IGroupMember(org.apereo.portal.groups.IGroupMember) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) IPortletType(org.apereo.portal.portlet.om.IPortletType) PortletDefinitionImpl(org.apereo.portal.portlet.dao.jpa.PortletDefinitionImpl)

Example 8 with IPortletType

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

the class PortletAdministrationHelper method getAllowableChannelPublishingDefinitions.

public Map<IPortletType, PortletPublishingDefinition> getAllowableChannelPublishingDefinitions(IPerson user) {
    Map<IPortletType, PortletPublishingDefinition> rslt;
    final Map<IPortletType, PortletPublishingDefinition> rawMap = portletPublishingDefinitionDao.getChannelPublishingDefinitions();
    final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
    if (principal.hasPermission(IPermission.PORTAL_PUBLISH, IPermission.PORTLET_MANAGER_SELECT_PORTLET_TYPE, IPermission.ALL_PORTLET_TYPES)) {
        // Send the whole collection back...
        rslt = rawMap;
    } else {
        // Filter the collection by permissions...
        rslt = new HashMap<>();
        for (Map.Entry<IPortletType, PortletPublishingDefinition> y : rawMap.entrySet()) {
            if (principal.hasPermission(IPermission.PORTAL_PUBLISH, IPermission.PORTLET_MANAGER_SELECT_PORTLET_TYPE, y.getKey().getName())) {
                rslt.put(y.getKey(), y.getValue());
            }
        }
    }
    return rslt;
}
Also used : IPortletType(org.apereo.portal.portlet.om.IPortletType) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with IPortletType

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

the class PortletAdministrationHelper method offerPortletSelection.

public boolean offerPortletSelection(PortletDefinitionForm form) {
    final IPortletType portletType = this.portletTypeRegistry.getPortletType(form.getTypeId());
    final PortletPublishingDefinition portletPublishingDefinition = this.portletPublishingDefinitionDao.getChannelPublishingDefinition(portletType.getId());
    final PortletDescriptor portletDescriptor = portletPublishingDefinition.getPortletDescriptor();
    if (portletDescriptor == null) {
        return true;
    }
    final Boolean isFramework = portletDescriptor.isIsFramework();
    if (isFramework != null && isFramework) {
        form.setFramework(true);
    } else {
        final String webAppName = portletDescriptor.getWebAppName();
        form.setApplicationId(webAppName);
    }
    final String portletName = portletDescriptor.getPortletName();
    form.setPortletName(portletName);
    return false;
}
Also used : PortletDescriptor(org.apereo.portal.xml.PortletDescriptor) IPortletType(org.apereo.portal.portlet.om.IPortletType) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition)

Example 10 with IPortletType

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

Aggregations

IPortletType (org.apereo.portal.portlet.om.IPortletType)16 PortletPublishingDefinition (org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition)7 Test (org.junit.Test)6 PortletDefinitionImpl (org.apereo.portal.portlet.dao.jpa.PortletDefinitionImpl)5 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)5 PortletTypeImpl (org.apereo.portal.portlet.dao.jpa.PortletTypeImpl)4 ArrayList (java.util.ArrayList)3 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)2 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)2 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)2 PortletDescriptor (org.apereo.portal.xml.PortletDescriptor)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 Calendar (java.util.Calendar)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1