use of org.apereo.portal.soffit.model.v1_0.Definition in project uPortal by Jasig.
the class SoffitRendererController method render.
@RequestMapping(value = "/{module}", method = RequestMethod.GET)
public ModelAndView render(final HttpServletRequest req, final HttpServletResponse res, @PathVariable final String module) {
logger.debug("Rendering for request URI '{}'", req.getRequestURI());
// Soffit Object Model
final PortalRequest portalRequest = getPortalRequest(req);
final Bearer bearer = getBearer(req);
final Preferences preferences = getPreferences(req);
final Definition definition = getDefinition(req);
// Select a view
final String viewName = selectView(req, module, portalRequest);
final Map<String, Object> model = modelAttributeService.gatherModelAttributes(viewName, req, res, portalRequest, bearer, preferences, definition);
model.put(PORTAL_REQUEST_MODEL_NAME, portalRequest);
model.put(BEARER_MODEL_NAME, bearer);
model.put(PREFERENCES_MODEL_NAME, preferences);
model.put(DEFINITION_MODEL_NAME, definition);
// Set up cache headers appropriately
configureCacheHeaders(res, module);
return new ModelAndView(viewName, model);
}
use of org.apereo.portal.soffit.model.v1_0.Definition in project uPortal by Jasig.
the class ModelAttributeServiceTest method testGetModelAttributeFromMethod.
@Test
public void testGetModelAttributeFromMethod() {
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 modelAttribute = modelAttributeService.getModelAttributeFromMethod(this, method, req, res, portalRequest, bearer, preferences, definition);
assertEquals("Incorrect modelAttribute", modelAttribute, returnValue);
final Method brokenMethod;
try {
brokenMethod = getClass().getMethod("brokenSoffitModelAttributeMethod", parameterClasses);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
try {
modelAttributeService.getModelAttributeFromMethod(this, brokenMethod, req, res, portalRequest, bearer, preferences, definition);
fail("Expected IllegalStateException for void-declaring method");
} catch (IllegalStateException e) {
// Expected; fall through...
}
}
use of org.apereo.portal.soffit.model.v1_0.Definition in project uPortal by Jasig.
the class DefinitionService method parseDefinition.
public Definition parseDefinition(String definitionToken) {
final Jws<Claims> claims = parseEncrypteToken(definitionToken, Definition.class);
final String username = claims.getBody().getSubject();
// Title
final String title = (String) claims.getBody().get(JwtClaims.TITLE.getName());
// FName
final String fname = (String) claims.getBody().get(JwtClaims.FNAME.getName());
// Description
final String description = (String) claims.getBody().get(JwtClaims.DESCRIPTION.getName());
// Categories
@SuppressWarnings("unchecked") final List<String> categories = (List<String>) claims.getBody().get(JwtClaims.CATEGORIES.getName());
// Parameters
@SuppressWarnings("unchecked") final Map<String, List<String>> parameters = (Map<String, List<String>>) claims.getBody().get(JwtClaims.PARAMETERS.getName());
Definition rslt = new Definition(definitionToken, title, fname, description, categories, parameters);
logger.debug("Produced the following Definition for user '{}': {}", username, rslt);
return rslt;
}
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]));
}
}
Aggregations