use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.
the class PrincipalsRESTControllerTest method testGetPrincipalsGroup.
@Test
public void testGetPrincipalsGroup() throws Exception {
String query = "test";
Set<JsonEntityBean> beans = new HashSet<JsonEntityBean>();
beans.add(buildJsonGroupEntityBean());
Mockito.when(groupListHelper.search(EntityEnum.GROUP.toString(), "test")).thenReturn(beans);
Mockito.when(groupListHelper.search(EntityEnum.PERSON.toString(), "test")).thenReturn(Collections.emptySet());
ModelAndView modelAndView = principalsRESTController.getPrincipals(query, req, res);
List<JsonEntityBean> returnPersonEntities = (List<JsonEntityBean>) modelAndView.getModel().get("people");
List<JsonEntityBean> returnGroupEntities = (List<JsonEntityBean>) modelAndView.getModel().get("groups");
Assert.assertTrue(returnPersonEntities.isEmpty());
Assert.assertFalse(returnGroupEntities.isEmpty());
}
use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.
the class PrincipalsRESTControllerTest method testGetPrincipalsPerson.
@Test
public void testGetPrincipalsPerson() throws Exception {
String query = "test";
Set<JsonEntityBean> beans = new HashSet<JsonEntityBean>();
beans.add(buildJsonPersonEntityBean());
Mockito.when(groupListHelper.search(EntityEnum.GROUP.toString(), "test")).thenReturn(Collections.emptySet());
Mockito.when(groupListHelper.search(EntityEnum.PERSON.toString(), "test")).thenReturn(beans);
ModelAndView modelAndView = principalsRESTController.getPrincipals(query, req, res);
List<JsonEntityBean> returnPersonEntities = (List<JsonEntityBean>) modelAndView.getModel().get("people");
List<JsonEntityBean> returnGroupEntities = (List<JsonEntityBean>) modelAndView.getModel().get("groups");
Assert.assertFalse(returnPersonEntities.isEmpty());
Assert.assertTrue(returnGroupEntities.isEmpty());
}
use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.
the class PrincipalsRESTControllerTest method buildJsonGroupEntityBean.
private JsonEntityBean buildJsonGroupEntityBean() {
JsonEntityBean groupBean = new JsonEntityBean();
groupBean.setEntityType(EntityEnum.GROUP.toString());
groupBean.setId("group101");
groupBean.setName("test");
groupBean.setDescription("Testing group bean");
return groupBean;
}
use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.
the class PrincipalsRESTControllerTest method testGetPrincipals.
@Test
public void testGetPrincipals() throws Exception {
String query = "test";
Mockito.when(groupListHelper.search(EntityEnum.GROUP.toString(), "test")).thenReturn(Collections.emptySet());
Mockito.when(groupListHelper.search(EntityEnum.PERSON.toString(), "test")).thenReturn(Collections.emptySet());
ModelAndView modelAndView = principalsRESTController.getPrincipals(query, req, res);
List<JsonEntityBean> returnPersonEntities = (List<JsonEntityBean>) modelAndView.getModel().get("people");
List<JsonEntityBean> returnGroupEntities = (List<JsonEntityBean>) modelAndView.getModel().get("groups");
Assert.assertTrue(returnPersonEntities.isEmpty());
Assert.assertTrue(returnGroupEntities.isEmpty());
}
use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.
the class PortletAdministrationHelper method createPortletDefinitionForm.
/**
* Construct a new PortletDefinitionForm for the given IPortletDefinition id. If a
* PortletDefinition matching this ID already exists, the form will be pre-populated with the
* PortletDefinition's current configuration. If the PortletDefinition does not yet exist, a new
* default form will be created.
*
* @param person user that is required to have related lifecycle permission
* @param portletId identifier for the portlet definition
* @return {@PortletDefinitionForm} with set values based on portlet definition or default
* category and principal if no definition is found
*/
public PortletDefinitionForm createPortletDefinitionForm(IPerson person, String portletId) {
IPortletDefinition def = portletDefinitionRegistry.getPortletDefinition(portletId);
// create the new form
final PortletDefinitionForm form;
if (def != null) {
// if this is a pre-existing portlet, set the category and permissions
form = new PortletDefinitionForm(def);
form.setId(def.getPortletDefinitionId().getStringId());
// create a JsonEntityBean for each current category and add it
// to our form bean's category list
Set<PortletCategory> categories = portletCategoryRegistry.getParentCategories(def);
for (PortletCategory cat : categories) {
form.addCategory(new JsonEntityBean(cat));
}
addPrincipalPermissionsToForm(def, form);
} else {
form = createNewPortletDefinitionForm();
}
// hierarchical, so we'll test with the weakest.
if (!hasLifecyclePermission(person, PortletLifecycleState.CREATED, form.getCategories())) {
logger.warn("User '" + person.getUserName() + "' attempted to edit the following portlet without MANAGE permission: " + def);
throw new SecurityException("Not Authorized");
}
return form;
}
Aggregations