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();
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations