Search in sources :

Example 91 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class LearningGroupWebService method addParticipant.

/**
 * Adds a participant to the group.
 * @response.representation.200.doc The user is added as participant of the group
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The business group or the user cannot be found
 * @param groupKey The key of the group
 * @param identityKey The user's id
 * @param request The HTTP request
 * @return
 */
@PUT
@Path("{groupKey}/participants/{identityKey}")
public Response addParticipant(@PathParam("groupKey") Long groupKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
    try {
        if (!isGroupManager(request)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
        final UserRequest ureq = RestSecurityHelper.getUserRequest(request);
        final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
        final BusinessGroup group = bgs.loadBusinessGroup(groupKey);
        final Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
        if (identity == null || group == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        BusinessGroupAddResponse state = bgs.addParticipants(ureq.getIdentity(), ureq.getUserSession().getRoles(), Collections.singletonList(identity), group, null);
        if (state.getAddedIdentities().contains(identity)) {
            return Response.ok().build();
        } else if (state.getIdentitiesAlreadyInGroup().contains(identity)) {
            return Response.ok().status(Status.NOT_MODIFIED).build();
        }
        return Response.serverError().status(Status.PRECONDITION_FAILED).build();
    } catch (Exception e) {
        log.error("Trying to add a participant to a group", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupAddResponse(org.olat.group.BusinessGroupAddResponse) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 92 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class GroupsAndRightsController method loadModel.

private void loadModel() {
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, courseEntry, 0, -1);
    List<Group> baseGroups = getAllBaseGroups(groups);
    List<BGRights> currentRights = rightManager.findBGRights(baseGroups, courseEntry.getOlatResource());
    Map<Group, BGRights> tutorToRightsMap = new HashMap<>();
    Map<Group, BGRights> participantToRightsMap = new HashMap<>();
    for (BGRights right : currentRights) {
        if (right.getRole() == BGRightsRole.tutor) {
            tutorToRightsMap.put(right.getBaseGroup(), right);
        } else if (right.getRole() == BGRightsRole.participant) {
            participantToRightsMap.put(right.getBaseGroup(), right);
        }
    }
    List<BGRightsRow> options = new ArrayList<>();
    String courseName = courseEntry.getDisplayname();
    Group defGroup = repositoryService.getDefaultGroup(courseEntry);
    options.add(getRightsOption(defGroup, courseName, tutorToRightsMap.get(defGroup), BGRightsRole.tutor, BGRightsResourceType.repositoryEntry));
    options.add(getRightsOption(defGroup, courseName, participantToRightsMap.get(defGroup), BGRightsRole.participant, BGRightsResourceType.repositoryEntry));
    for (BusinessGroup group : groups) {
        String name = group.getName();
        Group bGroup = group.getBaseGroup();
        options.add(getRightsOption(bGroup, name, tutorToRightsMap.get(bGroup), BGRightsRole.tutor, BGRightsResourceType.businessGroup));
        options.add(getRightsOption(bGroup, name, participantToRightsMap.get(bGroup), BGRightsRole.participant, BGRightsResourceType.businessGroup));
    }
    tableDataModel.setObjects(options);
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BGRights(org.olat.group.right.BGRights) BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 93 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class PersistingCourseGroupManager method getBusinessGroupEnvironment.

/**
 * This operation load all business groups and areas. Use with caution, costly!
 * @param resource
 * @param fGroupExportXML
 * @return
 */
public CourseEnvironmentMapper getBusinessGroupEnvironment() {
    CourseEnvironmentMapper env = new CourseEnvironmentMapper();
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, getCourseEntry(), 0, -1);
    for (BusinessGroup group : groups) {
        env.getGroups().add(new BusinessGroupReference(group));
    }
    List<BGArea> areas = areaManager.findBGAreasInContext(getCourseResource());
    for (BGArea area : areas) {
        env.getAreas().add(new BGAreaReference(area));
    }
    return env;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupReference(org.olat.group.model.BusinessGroupReference) BGArea(org.olat.group.area.BGArea) BGAreaReference(org.olat.group.model.BGAreaReference) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper)

Example 94 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class PersistingCourseGroupManager method getNumberOfMembersFromGroups.

/**
 * @param groups List of business groups
 * @return list of Integers that contain the number of participants for each
 *         group
 */
public List<Integer> getNumberOfMembersFromGroups(List<BusinessGroup> groups) {
    List<Integer> members = new ArrayList<Integer>();
    for (BusinessGroup group : groups) {
        int numbMembers = businessGroupService.countMembers(group, GroupRoles.participant.name());
        members.add(new Integer(numbMembers));
    }
    return members;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList)

Example 95 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class PersistingCourseGroupManager method getUniqueBusinessGroupNames.

/**
 * @see org.olat.course.groupsandrights.CourseGroupManager#getUniqueBusinessGroupNames()
 */
public List<String> getUniqueBusinessGroupNames() {
    List<BusinessGroup> groups = getAllBusinessGroups();
    List<String> groupNames = new ArrayList<String>();
    for (BusinessGroup group : groups) {
        if (!groupNames.contains(group.getName())) {
            groupNames.add(group.getName().trim());
        }
    }
    Collections.sort(groupNames);
    return groupNames;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList)

Aggregations

BusinessGroup (org.olat.group.BusinessGroup)1034 Test (org.junit.Test)536 Identity (org.olat.core.id.Identity)536 RepositoryEntry (org.olat.repository.RepositoryEntry)324 ArrayList (java.util.ArrayList)224 BusinessGroupService (org.olat.group.BusinessGroupService)116 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)84 BGArea (org.olat.group.area.BGArea)70 CollaborationTools (org.olat.collaboration.CollaborationTools)58 OLATResource (org.olat.resource.OLATResource)56 Date (java.util.Date)54 HashSet (java.util.HashSet)50 File (java.io.File)46 Path (javax.ws.rs.Path)42 Group (org.olat.basesecurity.Group)42 HashMap (java.util.HashMap)38 Roles (org.olat.core.id.Roles)38 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)38 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)38 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)38