use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.
the class PortletAdministrationHelper method addSubscribePermissionsToForm.
/*
* Add to the form SUBSCRIBE and BROWSE activity permissions, along with their principals,
* assigned to the portlet.
*/
private void addSubscribePermissionsToForm(IPortletDefinition def, PortletDefinitionForm form) {
final String portletTargetId = PermissionHelper.permissionTargetIdForPortletDefinition(def);
/* We are concerned with PORTAL_SUBSCRIBE system */
final IPermissionManager pm = authorizationService.newPermissionManager(IPermission.PORTAL_SUBSCRIBE);
for (String activity : PORTLET_SUBSCRIBE_ACTIVITIES) {
/* Obtain the principals that have permission for the activity on this portlet */
final IAuthorizationPrincipal[] principals = pm.getAuthorizedPrincipals(activity, portletTargetId);
for (IAuthorizationPrincipal principal : principals) {
JsonEntityBean principalBean;
// first assume this is a group
IEntityGroup group = GroupService.findGroup(principal.getKey());
if (group != null) {
// principal is a group
principalBean = new JsonEntityBean(group, EntityEnum.GROUP);
} else {
// not a group, so it must be a person
IGroupMember member = authorizationService.getGroupMember(principal);
principalBean = new JsonEntityBean(member, EntityEnum.PERSON);
// set the name
String name = groupListHelper.lookupEntityName(principalBean);
principalBean.setName(name);
}
/* Make sure we capture the principal just once*/
if (!form.getPrincipals().contains(principalBean)) {
form.addPrincipal(principalBean);
}
form.addPermission(principalBean.getTypeAndIdHash() + "_" + activity);
}
}
}
use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.
the class GroupAdministrationHelper method getGroupForm.
/**
* Construct a group form for the group with the specified key.
*
* @param key
* @param entityEnum
* @return
*/
public GroupForm getGroupForm(String key) {
log.debug("Initializing group form for group key " + key);
// find the current version of this group entity
IEntityGroup group = GroupService.findGroup(key);
// update the group form with the existing group's main information
GroupForm form = new GroupForm();
form.setKey(key);
form.setName(group.getName());
form.setDescription(group.getDescription());
form.setCreatorId(group.getCreatorID());
form.setType(groupListHelper.getEntityType(group).toString());
// add child groups to our group form bean
for (IGroupMember child : group.getChildren()) {
JsonEntityBean childBean = groupListHelper.getEntity(child);
form.addMember(childBean);
}
return form;
}
use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.
the class GroupAdministrationHelper method createGroup.
/**
* Create a new group under the specified parent. The new group will automatically be added to
* the parent group.
*
* @param groupForm form object representing the new group
* @param parent parent group for this new group
* @param creator the uPortal user creating the new group
*/
public void createGroup(GroupForm groupForm, JsonEntityBean parent, IPerson creator) {
if (!canCreateMemberGroup(creator, parent.getId())) {
throw new RuntimeAuthorizationException(creator, IPermission.CREATE_GROUP_ACTIVITY, groupForm.getKey());
}
if (log.isDebugEnabled()) {
log.debug("Creating new group for group form [" + groupForm.toString() + "] and parent [" + parent.toString() + "]");
}
// get the entity type of the parent group
EntityEnum type = EntityEnum.getEntityEnum(groupForm.getType());
// create a new group with the parent's entity type
IEntityGroup group = GroupService.newGroup(type.getClazz());
// find the current version of this group entity
group.setCreatorID(creator.getUserName());
group.setName(groupForm.getName());
group.setDescription(groupForm.getDescription());
// to the group
for (JsonEntityBean child : groupForm.getMembers()) {
EntityEnum childType = EntityEnum.getEntityEnum(child.getEntityTypeAsString());
if (childType.isGroup()) {
IEntityGroup member = GroupService.findGroup(child.getId());
group.addChild(member);
} else {
IGroupMember member = GroupService.getGroupMember(child.getId(), type.getClazz());
group.addChild(member);
}
}
// save the group, updating both its basic information and group membership
group.update();
// add this group to the membership list for the specified parent
IEntityGroup parentGroup = GroupService.findGroup(parent.getId());
parentGroup.addChild(group);
parentGroup.updateMembers();
}
use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.
the class JsonEntityBeanTest method testConstructFromGroupMemberWithPortlet.
@Test
public void testConstructFromGroupMemberWithPortlet() {
String key = "test-key";
Mockito.when(groupMember.getKey()).thenReturn(key);
JsonEntityBean jeb = new JsonEntityBean(groupMember, EntityEnum.PORTLET);
assertEquals(EntityEnum.PORTLET, jeb.getEntityType());
assertEquals(key, jeb.getId());
assertEquals(IPermission.PORTLET_PREFIX + key, jeb.getTargetString());
}
use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.
the class JsonEntityBeanTest method testEqualsDiffChildrenInit.
@Test
public void testEqualsDiffChildrenInit() {
JsonEntityBean jeb1 = buildNullBean();
jeb1.setChildrenInitialized(true);
JsonEntityBean jeb2 = buildNullBean();
jeb2.setChildrenInitialized(false);
assertFalse(jeb1.equals(jeb2));
}
Aggregations