Search in sources :

Example 16 with MarketplacePortletDefinition

use of org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition in project uPortal by Jasig.

the class DefinitionHeaderProvider method createHeader.

@Override
public Header createHeader(RenderRequest renderRequest, RenderResponse renderResponse) {
    // Include?
    if (!isIncluded(renderRequest, INCLUDE_PREFERENCE)) {
        return null;
    }
    // Username
    final String username = getUsername(renderRequest);
    // Obtain the MarketplacePortletDefinition for this soffit
    final HttpServletRequest httpr = portalRequestUtils.getCurrentPortalRequest();
    final IPortletWindowId portletWindowId = portletWindowRegistry.getPortletWindowId(httpr, renderRequest.getWindowID());
    final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(httpr, portletWindowId);
    final IPortletDefinition pdef = portletWindow.getPortletEntity().getPortletDefinition();
    final MarketplacePortletDefinition mpdef = this.marketplaceService.getOrCreateMarketplacePortletDefinition(pdef);
    final IPerson user = personManager.getPerson(httpr);
    final Locale locale = getUserLocale(user);
    // Title
    final String title = mpdef.getTitle(locale.toString());
    // FName
    final String fname = mpdef.getFName();
    // Description
    final String description = mpdef.getDescription(locale.toString());
    // Categories
    List<String> categories = new ArrayList<>();
    for (PortletCategory pc : mpdef.getCategories()) {
        categories.add(pc.getName());
    }
    // Parameters
    Map<String, List<String>> parameters = new HashMap<>();
    for (IPortletDefinitionParameter param : mpdef.getParameters()) {
        parameters.put(param.getName(), Collections.singletonList(param.getValue()));
    }
    final Definition definition = definitionService.createDefinition(title, fname, description, categories, parameters, username, getExpiration(renderRequest));
    final Header rslt = new BasicHeader(Headers.DEFINITION.getName(), definition.getEncryptedToken());
    logger.debug("Produced the following {} header for username='{}':  {}", Headers.DEFINITION.getName(), username, rslt);
    return rslt;
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) Definition(org.apereo.portal.soffit.model.v1_0.Definition) MarketplacePortletDefinition(org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) MarketplacePortletDefinition(org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) ArrayList(java.util.ArrayList) List(java.util.List) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) BasicHeader(org.apache.http.message.BasicHeader) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletCategory(org.apereo.portal.portlet.om.PortletCategory)

Aggregations

MarketplacePortletDefinition (org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition)16 PortletDefinitionBean (org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean)12 Test (org.junit.Test)10 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)4 ArrayList (java.util.ArrayList)3 IPerson (org.apereo.portal.security.IPerson)3 HashMap (java.util.HashMap)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)2 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)2 MarketplaceEntry (org.apereo.portal.rest.layout.MarketplaceEntry)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2 List (java.util.List)1 Locale (java.util.Locale)1 PortletPreferences (javax.portlet.PortletPreferences)1 Header (org.apache.http.Header)1 BasicHeader (org.apache.http.message.BasicHeader)1 IMarketplaceRating (org.apereo.portal.portlet.marketplace.IMarketplaceRating)1 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)1 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)1