Search in sources :

Example 1 with IPortletDescriptorKey

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

the class HtmlPortletPreferenceSearchContentExtractorTest method testAppliesToMatchAll.

@Test
public void testAppliesToMatchAll() {
    final IPortletDescriptorKey portletDescriptorKey = mock(IPortletDescriptorKey.class);
    when(portletDescriptorKey.getPortletName()).thenAnswer(invocation -> PORTLET_NAME);
    when(portletDescriptorKey.getWebAppName()).thenAnswer(invocation -> WEBAPP_NAME);
    final IPortletPreference portletPreference = mock(IPortletPreference.class);
    when(portletPreference.getName()).thenAnswer(invocation -> PREFERENCE_NAME);
    final IPortletDefinition portletDefinition = mock(IPortletDefinition.class);
    when(portletDefinition.getPortletDescriptorKey()).thenAnswer(invocation -> portletDescriptorKey);
    when(portletDefinition.getPortletPreferences()).thenAnswer(invocation -> Collections.singletonList(portletPreference));
    assertTrue(EXTRACTOR.appliesTo(portletDefinition));
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) IPortletDescriptorKey(org.apereo.portal.portlet.om.IPortletDescriptorKey) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) Test(org.junit.Test)

Example 2 with IPortletDescriptorKey

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

the class HtmlPortletPreferenceSearchContentExtractorTest method testAppliesToWebappMatch.

@Test
public void testAppliesToWebappMatch() {
    final IPortletDescriptorKey portletDescriptorKey = mock(IPortletDescriptorKey.class);
    when(portletDescriptorKey.getPortletName()).thenAnswer(invocation -> NOT_A_MATCH);
    when(portletDescriptorKey.getWebAppName()).thenAnswer(invocation -> WEBAPP_NAME);
    final IPortletDefinition portletDefinition = mock(IPortletDefinition.class);
    when(portletDefinition.getPortletDescriptorKey()).thenAnswer(invocation -> portletDescriptorKey);
    when(portletDefinition.getPortletPreferences()).thenAnswer(invocation -> Collections.emptyList());
    assertFalse(EXTRACTOR.appliesTo(portletDefinition));
}
Also used : IPortletDescriptorKey(org.apereo.portal.portlet.om.IPortletDescriptorKey) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) Test(org.junit.Test)

Example 3 with IPortletDescriptorKey

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

the class PortletExecutionManager method getPortletExecutionCounts.

@Override
public Map<String, Integer> getPortletExecutionCounts() {
    final Map<String, Integer> counts = new TreeMap<String, Integer>();
    for (final Map.Entry<IPortletDescriptorKey, AtomicInteger> entry : this.executionCount.entrySet()) {
        final IPortletDescriptorKey key = entry.getKey();
        final AtomicInteger value = entry.getValue();
        counts.put(key.getWebAppName() + "/" + key.getPortletName(), value.get());
    }
    return counts;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TreeMap(java.util.TreeMap) IPortletDescriptorKey(org.apereo.portal.portlet.om.IPortletDescriptorKey) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 4 with IPortletDescriptorKey

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

Example 5 with IPortletDescriptorKey

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

the class PortletDefinitionImporterExporter method convert.

protected ExternalPortletDefinition convert(IPortletDefinition def) {
    ExternalPortletDefinition rep = new ExternalPortletDefinition();
    rep.setFname(def.getFName());
    rep.setDesc(def.getDescription());
    rep.setName(def.getName());
    rep.setTimeout(BigInteger.valueOf(def.getTimeout()));
    rep.setActionTimeout(convertToBigInteger(def.getActionTimeout()));
    rep.setEventTimeout(convertToBigInteger(def.getEventTimeout()));
    rep.setRenderTimeout(convertToBigInteger(def.getRenderTimeout()));
    rep.setResourceTimeout(convertToBigInteger(def.getResourceTimeout()));
    rep.setTitle(def.getTitle());
    rep.setType(def.getType().getName());
    final Lifecycle lifecycle = new Lifecycle();
    for (IPortletLifecycleEntry ple : def.getLifecycle()) {
        final LifecycleEntry entry = new LifecycleEntry();
        entry.setName(ple.getLifecycleState().toString());
        entry.setUser(getUsernameForUserId(ple.getUserId()));
        entry.setValue(getCalendar(ple.getDate()));
        lifecycle.getEntries().add(entry);
    }
    rep.setLifecycle(lifecycle);
    final org.apereo.portal.xml.PortletDescriptor portletDescriptor = new org.apereo.portal.xml.PortletDescriptor();
    final IPortletDescriptorKey portletDescriptorKey = def.getPortletDescriptorKey();
    if (portletDescriptorKey.isFrameworkPortlet()) {
        portletDescriptor.setIsFramework(true);
    } else {
        portletDescriptor.setWebAppName(portletDescriptorKey.getWebAppName());
    }
    portletDescriptor.setPortletName(portletDescriptorKey.getPortletName());
    rep.setPortletDescriptor(portletDescriptor);
    final List<ExternalPortletParameter> parameterList = rep.getParameters();
    for (IPortletDefinitionParameter param : def.getParameters()) {
        final ExternalPortletParameter externalPortletParameter = new ExternalPortletParameter();
        externalPortletParameter.setName(param.getName());
        externalPortletParameter.setDescription(param.getDescription());
        externalPortletParameter.setValue(param.getValue());
        parameterList.add(externalPortletParameter);
    }
    parameterList.sort(ExternalPortletParameterNameComparator.INSTANCE);
    final List<ExternalPortletPreference> portletPreferenceList = rep.getPortletPreferences();
    for (IPortletPreference pref : def.getPortletPreferences()) {
        final ExternalPortletPreference externalPortletPreference = new ExternalPortletPreference();
        externalPortletPreference.setName(pref.getName());
        externalPortletPreference.setReadOnly(pref.isReadOnly());
        final List<String> value = externalPortletPreference.getValues();
        value.addAll(Arrays.asList(pref.getValues()));
        // no sorting of preference values, order is specified by the portlet
        portletPreferenceList.add(externalPortletPreference);
    }
    portletPreferenceList.sort(ExternalPortletPreferenceNameComparator.INSTANCE);
    final List<String> categoryList = rep.getCategories();
    final IGroupMember gm = GroupService.getGroupMember(def.getPortletDefinitionId().getStringId(), IPortletDefinition.class);
    @SuppressWarnings("unchecked") final Iterator<IEntityGroup> categories = GroupService.getCompositeGroupService().findParentGroups(gm);
    while (categories.hasNext()) {
        IEntityGroup category = categories.next();
        categoryList.add(category.getName());
    }
    Collections.sort(categoryList);
    // handle the SUBSCRIBER_ACTIVITY perm separately...
    final List<String> groupList = rep.getGroups();
    final List<String> userList = rep.getUsers();
    exportPermission(def, ExternalPermissionDefinition.SUBSCRIBE, groupList, userList);
    // handle other supported perms (currently just BROWSE)
    ExternalPermissions externalPermissions = new ExternalPermissions();
    for (ExternalPermissionDefinition perm : ExternalPermissionDefinition.values()) {
        if (!perm.getExportForPortletDef()) {
            continue;
        }
        ExternalPermissionMemberList members = new ExternalPermissionMemberList();
        members.setSystem(perm.getSystem());
        members.setActivity(perm.getActivity());
        List<String> groups = members.getGroups();
        boolean found = exportPermission(def, perm, groups, null);
        if (found) {
            externalPermissions.getPermissions().add(members);
        }
    }
    if (!externalPermissions.getPermissions().isEmpty()) {
        rep.setPermissions(externalPermissions);
    }
    return rep;
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) IPortletDescriptorKey(org.apereo.portal.portlet.om.IPortletDescriptorKey) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) ExternalPermissionDefinition(org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition) IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember)

Aggregations

IPortletDescriptorKey (org.apereo.portal.portlet.om.IPortletDescriptorKey)11 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)8 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)4 Test (org.junit.Test)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 QName (javax.xml.namespace.QName)1 Attribute (javax.xml.stream.events.Attribute)1 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1 IGroupMember (org.apereo.portal.groups.IGroupMember)1 ExternalPermissionDefinition (org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition)1