Search in sources :

Example 26 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.

the class JsonEntityBeanTest method testEqualsEntityTypeNullSource.

@Test
public void testEqualsEntityTypeNullSource() {
    EntityEnum ee = null;
    JsonEntityBean jeb1 = buildNullBean();
    jeb1.setChildrenInitialized(true);
    jeb1.setCreatorId("");
    jeb1.setDescription("");
    jeb1.setEntityType(ee);
    JsonEntityBean jeb2 = buildNullBean();
    jeb2.setChildrenInitialized(true);
    jeb2.setCreatorId("");
    jeb2.setDescription("");
    jeb2.setEntityType(EntityEnum.PORTLET);
    assertFalse(jeb1.equals(jeb2));
}
Also used : EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) Test(org.junit.Test)

Example 27 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum 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();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean)

Example 28 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.

the class GroupListHelperImpl method getEntity.

/*
     * (non-Javadoc)
     * @see org.apereo.portal.layout.dlm.remoting.IGroupListHelper#getEntity(java.lang.String, java.lang.String, boolean)
     */
@Override
public JsonEntityBean getEntity(String entityType, String entityId, boolean populateChildren) {
    // get the EntityEnum for the specified entity type
    EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
    if (entityEnum == null) {
        throw new IllegalArgumentException(String.format("Parameter entityType has an unknown value of [%s]", entityType));
    }
    // to locate it
    if (entityEnum.isGroup()) {
        // attempt to find the entity
        IEntityGroup entity = GroupService.findGroup(entityId);
        if (entity == null) {
            return null;
        } else {
            JsonEntityBean jsonBean = new JsonEntityBean(entity, entityEnum);
            if (populateChildren) {
                Iterator<IGroupMember> members = entity.getChildren().iterator();
                jsonBean = populateChildren(jsonBean, members);
            }
            if (jsonBean.getEntityType().isGroup() || EntityEnum.PERSON.equals(jsonBean.getEntityType())) {
                IAuthorizationPrincipal principal = getPrincipalForEntity(jsonBean);
                jsonBean.setPrincipalString(principal.getPrincipalString());
            }
            return jsonBean;
        }
    } else // otherwise use the getGroupMember method
    {
        IGroupMember entity = GroupService.getGroupMember(entityId, entityEnum.getClazz());
        if (entity == null || entity instanceof IEntityGroup) {
            return null;
        }
        JsonEntityBean jsonBean = new JsonEntityBean(entity, entityEnum);
        // the group member interface doesn't include the entity name, so
        // we'll need to look that up manually
        jsonBean.setName(lookupEntityName(jsonBean));
        if (EntityEnum.GROUP.equals(jsonBean.getEntityType()) || EntityEnum.PERSON.equals(jsonBean.getEntityType())) {
            IAuthorizationPrincipal principal = getPrincipalForEntity(jsonBean);
            jsonBean.setPrincipalString(principal.getPrincipalString());
        }
        return jsonBean;
    }
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal)

Example 29 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.

the class GroupListHelperImpl method getEntity.

/*
     * (non-Javadoc)
     * @see org.apereo.portal.layout.dlm.remoting.IGroupListHelper#getEntity(org.apereo.portal.groups.IGroupMember)
     */
@Override
public JsonEntityBean getEntity(IGroupMember member) {
    // get the type of this member entity
    EntityEnum entityEnum = getEntityType(member);
    // construct a new entity bean for this entity
    JsonEntityBean entity;
    if (entityEnum.isGroup()) {
        entity = new JsonEntityBean((IEntityGroup) member, entityEnum);
    } else {
        entity = new JsonEntityBean(member, entityEnum);
    }
    // if the name hasn't been set yet, look up the entity name
    if (entity.getName() == null) {
        entity.setName(lookupEntityName(entity));
    }
    if (EntityEnum.GROUP.equals(entity.getEntityType()) || EntityEnum.PERSON.equals(entity.getEntityType())) {
        IAuthorizationPrincipal principal = getPrincipalForEntity(entity);
        entity.setPrincipalString(principal.getPrincipalString());
    }
    return entity;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal)

Aggregations

EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)29 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)14 IEntityGroup (org.apereo.portal.groups.IEntityGroup)13 IGroupMember (org.apereo.portal.groups.IGroupMember)13 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)10 Test (org.junit.Test)9 HashSet (java.util.HashSet)7 GroupListHelperImpl (org.apereo.portal.layout.dlm.remoting.GroupListHelperImpl)4 ArrayList (java.util.ArrayList)3 EntityIdentifier (org.apereo.portal.EntityIdentifier)3 Principal (org.apereo.portal.api.Principal)2 PrincipalImpl (org.apereo.portal.api.PrincipalImpl)2 IPermission (org.apereo.portal.security.IPermission)2 RuntimeAuthorizationException (org.apereo.portal.security.RuntimeAuthorizationException)2 AuthorizationServiceFacade (org.apereo.portal.services.AuthorizationServiceFacade)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 TreeSet (java.util.TreeSet)1 IEntityNameFinder (org.apereo.portal.groups.IEntityNameFinder)1