use of org.olat.group.BusinessGroupAddResponse in project OpenOLAT by OpenOLAT.
the class BusinessGroupServiceImpl method addParticipants.
@Override
public BusinessGroupAddResponse addParticipants(Identity ureqIdentity, Roles ureqRoles, List<Identity> addIdentities, BusinessGroup group, MailPackage mailing) {
BusinessGroupAddResponse response = new BusinessGroupAddResponse();
List<BusinessGroupModifiedEvent.Deferred> events = new ArrayList<BusinessGroupModifiedEvent.Deferred>();
BusinessGroup currBusinessGroup = businessGroupDAO.loadForUpdate(group);
for (final Identity identity : addIdentities) {
if (securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_GUESTONLY)) {
response.getIdentitiesWithoutPermission().add(identity);
} else if (addParticipant(ureqIdentity, ureqRoles, identity, currBusinessGroup, mailing, events)) {
response.getAddedIdentities().add(identity);
} else {
response.getIdentitiesAlreadyInGroup().add(identity);
}
}
dbInstance.commit();
BusinessGroupModifiedEvent.fireDeferredEvents(events);
return response;
}
use of org.olat.group.BusinessGroupAddResponse in project OpenOLAT by OpenOLAT.
the class BusinessGroupServiceImpl method addToWaitingList.
@Override
public BusinessGroupAddResponse addToWaitingList(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup group, MailPackage mailing) {
BusinessGroupAddResponse response = new BusinessGroupAddResponse();
// reload business group
BusinessGroup currBusinessGroup = businessGroupDAO.loadForUpdate(group);
List<BusinessGroupModifiedEvent.Deferred> events = new ArrayList<BusinessGroupModifiedEvent.Deferred>();
for (final Identity identity : addIdentities) {
if (securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_GUESTONLY)) {
response.getIdentitiesWithoutPermission().add(identity);
} else // Check if identity is already in group. make a db query in case
// someone in another workflow already added this user to this group. if
// found, add user to model
{
List<String> roles = businessGroupRelationDAO.getRoles(identity, currBusinessGroup);
if (roles.contains(GroupRoles.waiting.name()) || roles.contains(GroupRoles.participant.name())) {
response.getIdentitiesAlreadyInGroup().add(identity);
} else {
// identity has permission and is not already in group => add it
internalAddToWaitingList(ureqIdentity, identity, currBusinessGroup, mailing, events);
response.getAddedIdentities().add(identity);
}
}
}
dbInstance.commit();
BusinessGroupModifiedEvent.fireDeferredEvents(events);
return response;
}
use of org.olat.group.BusinessGroupAddResponse in project openolat by klemens.
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.BusinessGroupAddResponse in project openolat by klemens.
the class ProjectGroupController method handleProjectMemberGroupEvent.
private void handleProjectMemberGroupEvent(UserRequest urequest, Event event) {
if (event instanceof IdentitiesAddEvent) {
IdentitiesAddEvent identitiesAddedEvent = (IdentitiesAddEvent) event;
BusinessGroupAddResponse response = businessGroupService.addParticipants(urequest.getIdentity(), urequest.getUserSession().getRoles(), identitiesAddedEvent.getAddIdentities(), project.getProjectGroup(), null);
identitiesAddedEvent.setIdentitiesAddedEvent(response.getAddedIdentities());
identitiesAddedEvent.setIdentitiesWithoutPermission(response.getIdentitiesWithoutPermission());
identitiesAddedEvent.setIdentitiesAlreadyInGroup(response.getIdentitiesAlreadyInGroup());
getLogger().info("Add users as project-members");
fireEvent(urequest, Event.CHANGED_EVENT);
} else if (event instanceof IdentitiesRemoveEvent) {
businessGroupService.removeParticipants(urequest.getIdentity(), ((IdentitiesRemoveEvent) event).getRemovedIdentities(), project.getProjectGroup(), null);
getLogger().info("Remove users as account-managers");
fireEvent(urequest, Event.CHANGED_EVENT);
}
}
use of org.olat.group.BusinessGroupAddResponse in project openolat by klemens.
the class ProjectGroupController method handleCandidateGroupEvent.
private void handleCandidateGroupEvent(UserRequest urequest, Event event) {
if (event instanceof IdentitiesAddEvent) {
IdentitiesAddEvent identitiesAddEvent = (IdentitiesAddEvent) event;
List<Identity> addedIdentities = projectGroupManager.addCandidates(identitiesAddEvent.getAddIdentities(), project);
identitiesAddEvent.setIdentitiesAddedEvent(addedIdentities);
fireEvent(urequest, Event.CHANGED_EVENT);
} else if (event instanceof IdentitiesRemoveEvent) {
projectGroupManager.removeCandidates(((IdentitiesRemoveEvent) event).getRemovedIdentities(), project);
fireEvent(urequest, Event.CHANGED_EVENT);
} else if (event instanceof IdentitiesMoveEvent) {
final IdentitiesMoveEvent identitiesMoveEvent = (IdentitiesMoveEvent) event;
// OLAT-6342: check identity not in group first!
List<Identity> moveIdents = identitiesMoveEvent.getChosenIdentities();
BusinessGroupAddResponse response = projectGroupManager.acceptCandidates(moveIdents, project, urequest.getIdentity(), projectBrokerModuleConfiguration.isAutoSignOut(), projectBrokerModuleConfiguration.isAcceptSelectionManually());
identitiesMoveEvent.setMovedIdentities(response.getAddedIdentities());
identitiesMoveEvent.setNotMovedIdentities(response.getIdentitiesAlreadyInGroup());
// send mail for all of them
MailTemplate mailTemplate = identitiesMoveEvent.getMailTemplate();
if (mailTemplate != null) {
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
String metaId = UUID.randomUUID().toString().replace("-", "");
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, identitiesMoveEvent.getMovedIdentities(), mailTemplate, null, metaId, result);
result.append(mailManager.sendMessage(bundles));
if (mailTemplate.getCpfrom()) {
MailBundle ccBundle = mailManager.makeMailBundle(context, urequest.getIdentity(), mailTemplate, null, metaId, result);
result.append(mailManager.sendMessage(ccBundle));
}
MailHelper.printErrorsAndWarnings(result, getWindowControl(), urequest.getUserSession().getRoles().isOLATAdmin(), urequest.getLocale());
}
fireEvent(urequest, Event.CHANGED_EVENT);
// Participant and waiting-list were changed => reload both
projectMemberController.reloadData();
// Do only reload data in case of IdentitiesMoveEvent (IdentitiesAddEvent and reload data resulting in doublicate values)
projectCandidatesController.reloadData();
}
}
Aggregations