Search in sources :

Example 6 with Definition

use of org.eclipse.xtext.linking.lazy.bug311337.Definition in project uPortal by Jasig.

the class DefinitionHeaderProvider method createHeader.

@Override
public Header createHeader(RenderRequest renderRequest, RenderResponse renderResponse) {
    // 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)

Example 7 with Definition

use of org.eclipse.xtext.linking.lazy.bug311337.Definition in project uPortal by Jasig.

the class ModelAttributeServiceTest method testPrepareMethodParameters.

@Test
public void testPrepareMethodParameters() {
    final ModelAttributeService modelAttributeService = new ModelAttributeService();
    final Class[] parameterClasses = new Class[] { HttpServletRequest.class, PortalRequest.class, Bearer.class };
    final Method method;
    try {
        method = getClass().getMethod("soffitModelAttributeMethod", parameterClasses);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
    // Object Model
    final HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
    final HttpServletResponse res = Mockito.mock(HttpServletResponse.class);
    final PortalRequest portalRequest = Mockito.mock(PortalRequest.class);
    final Bearer bearer = Mockito.mock(Bearer.class);
    final Preferences preferences = Mockito.mock(Preferences.class);
    final Definition definition = Mockito.mock(Definition.class);
    final Object[] parameters = modelAttributeService.prepareMethodParameters(method, req, res, portalRequest, bearer, preferences, definition);
    assertEquals("parameterClasses and parameters arrays must be the same length", parameterClasses.length, parameters.length);
    for (int i = 0; i < parameters.length; i++) {
        assertTrue("Mismatched parameter type", parameterClasses[i].isInstance(parameters[i]));
    }
}
Also used : Definition(org.apereo.portal.soffit.model.v1_0.Definition) HttpServletResponse(javax.servlet.http.HttpServletResponse) Method(java.lang.reflect.Method) PortalRequest(org.apereo.portal.soffit.model.v1_0.PortalRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Preferences(org.apereo.portal.soffit.model.v1_0.Preferences) Bearer(org.apereo.portal.soffit.model.v1_0.Bearer) Test(org.junit.Test)

Example 8 with Definition

use of org.eclipse.xtext.linking.lazy.bug311337.Definition in project uPortal by Jasig.

the class DefinitionService method createDefinition.

public Definition createDefinition(String title, String fname, String description, List<String> categories, Map<String, List<String>> parameters, String username, Date expires) {
    final Claims claims = createClaims(Definition.class, username, expires);
    // Title
    claims.put(JwtClaims.TITLE.getName(), title);
    // FName
    claims.put(JwtClaims.FNAME.getName(), fname);
    // Description
    claims.put(JwtClaims.DESCRIPTION.getName(), description);
    // Categories
    claims.put(JwtClaims.CATEGORIES.getName(), categories);
    // Parameters
    claims.put(JwtClaims.PARAMETERS.getName(), parameters);
    return new Definition(generateEncryptedToken(claims), title, fname, description, categories, parameters);
}
Also used : Claims(io.jsonwebtoken.Claims) Definition(org.apereo.portal.soffit.model.v1_0.Definition)

Aggregations

Definition (org.apereo.portal.soffit.model.v1_0.Definition)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Bearer (org.apereo.portal.soffit.model.v1_0.Bearer)3 PortalRequest (org.apereo.portal.soffit.model.v1_0.PortalRequest)3 Preferences (org.apereo.portal.soffit.model.v1_0.Preferences)3 Claims (io.jsonwebtoken.Claims)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Definition (org.eclipse.xtext.linking.lazy.bug311337.Definition)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Header (org.apache.http.Header)1 BasicHeader (org.apache.http.message.BasicHeader)1 MarketplacePortletDefinition (org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition)1 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)1