use of org.apereo.portal.soffit.model.v1_0.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;
}
use of org.apereo.portal.soffit.model.v1_0.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]));
}
}
use of org.apereo.portal.soffit.model.v1_0.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);
}
Aggregations