use of org.olat.modules.vitero.model.ViteroGroupRoles in project OpenOLAT by OpenOLAT.
the class ViteroBookingWebService method addMembers.
/**
* Update the list of members of the booking, it add and mutates the
* members and delete the missing members.
*
* @response.representation.200.qname {http://www.example.com}viteroGroupMemberVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc This is the list of all bookings of a resource
* @response.representation.200.example {@link org.olat.modules.vitero.restapi.Examples#SAMPLE_ViteroGroupMemberVO}
* @param bookingId The id of the booking
* @param members The array of members
* @return Nothing
*/
@POST
@Path("{bookingId}/members")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addMembers(@PathParam("bookingId") int bookingId, ViteroGroupMemberVO[] members) {
try {
ViteroBooking booking = viteroManager.getBookingById(null, ores, subIdentifier, bookingId);
if (booking == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
ViteroGroupRoles roles = viteroManager.getGroupRoles(booking.getGroupId());
if (roles == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
List<ViteroErrorVO> errors = new ArrayList<>();
List<String> currentEmails = new ArrayList<>(roles.getEmailsOfParticipants());
for (ViteroGroupMemberVO member : members) {
GroupRole role = GroupRole.valueOf(member.getGroupRole());
Identity identity = securityManager.loadIdentityByKey(member.getIdentityKey());
String currentEmail = identity.getUser().getProperty(UserConstants.EMAIL, null);
GroupRole currentRole = roles.getEmailsToRole().get(currentEmail);
if (currentRole == null) {
ViteroStatus status = viteroManager.addToRoom(booking, identity, role);
if (!status.isOk()) {
errors.add(viteroErrorVO(status));
}
} else if (!currentRole.equals(role)) {
Integer vmsUserId = roles.getEmailsToVmsUserId().get(currentEmail);
ViteroStatus status = viteroManager.changeGroupRole(booking.getGroupId(), vmsUserId.intValue(), role.getVmsValue());
if (!status.isOk()) {
errors.add(viteroErrorVO(status));
}
}
currentEmails.remove(currentEmail);
}
for (String email : currentEmails) {
SearchIdentityParams params = new SearchIdentityParams();
params.setUserProperties(Collections.singletonMap(UserConstants.EMAIL, email));
List<Identity> identities = securityManager.getIdentitiesByPowerSearch(params, 0, 1);
for (Identity identity : identities) {
ViteroStatus status = viteroManager.removeFromRoom(booking, identity);
if (!status.isOk()) {
errors.add(viteroErrorVO(status));
}
}
}
return Response.ok().build();
} catch (VmsNotAvailableException e) {
log.error("", e);
return handleNotAvailableException();
}
}
use of org.olat.modules.vitero.model.ViteroGroupRoles in project OpenOLAT by OpenOLAT.
the class ViteroBookingWebService method getMembers.
/**
* Returns the list of members of the booking.
*
* @response.representation.200.qname {http://www.example.com}viteroGroupMemberVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc This is the list of all bookings of a resource
* @response.representation.200.example {@link org.olat.modules.vitero.restapi.Examples#SAMPLE_ViteroGroupMemberVO}
* @param bookingId The id of the booking
* @return The list of members in the specified booking
*/
@GET
@Path("{bookingId}/members")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getMembers(@PathParam("bookingId") int bookingId) {
try {
ViteroBooking booking = viteroManager.getBookingById(null, ores, subIdentifier, bookingId);
if (booking == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
ViteroGroupRoles roles = viteroManager.getGroupRoles(booking.getGroupId());
if (roles == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
List<String> currentEmails = new ArrayList<>(roles.getEmailsOfParticipants());
List<ViteroGroupMemberVO> memberList = new ArrayList<>(currentEmails.size());
for (String email : currentEmails) {
SearchIdentityParams params = new SearchIdentityParams();
params.setUserProperties(Collections.singletonMap(UserConstants.EMAIL, email));
List<Identity> identities = securityManager.getIdentitiesByPowerSearch(params, 0, 1);
for (Identity identity : identities) {
GroupRole role = roles.getEmailsToRole().get(email);
memberList.add(new ViteroGroupMemberVO(identity.getKey(), role.name()));
}
}
ViteroGroupMemberVO[] members = memberList.toArray(new ViteroGroupMemberVO[memberList.size()]);
return Response.ok(members).build();
} catch (VmsNotAvailableException e) {
log.error("", e);
return handleNotAvailableException();
}
}
use of org.olat.modules.vitero.model.ViteroGroupRoles in project OpenOLAT by OpenOLAT.
the class ViteroManager method getGroupRoles.
/**
* @param id The group id
* @return
* @throws VmsNotAvailableException
*/
public ViteroGroupRoles getGroupRoles(int id) throws VmsNotAvailableException {
try {
Group groupWs = getGroupWebService();
Groupid groupId = new Groupid();
groupId.setGroupid(id);
Group_Type group = groupWs.getGroup(groupId);
Completegrouptype groupType = group.getGroup();
List<Completegrouptype.Participant> participants = groupType.getParticipant();
int numOfParticipants = participants == null ? 0 : participants.size();
ViteroGroupRoles groupRoles = new ViteroGroupRoles();
if (numOfParticipants > 0) {
Map<Integer, String> idToEmails = new HashMap<Integer, String>();
List<Usertype> vmsUsers = getVmsUsersByGroup(id);
if (vmsUsers != null) {
for (Usertype vmsUser : vmsUsers) {
Integer userId = new Integer(vmsUser.getId());
String email = vmsUser.getEmail();
groupRoles.getEmailsOfParticipants().add(email);
idToEmails.put(userId, email);
}
}
for (int i = 0; i < numOfParticipants; i++) {
Completegrouptype.Participant participant = participants.get(i);
Integer userId = new Integer(participant.getUserid());
String email = idToEmails.get(userId);
if (email != null) {
GroupRole role = GroupRole.valueOf(participant.getRole());
groupRoles.getEmailsToRole().put(email, role);
groupRoles.getEmailsToVmsUserId().put(email, userId);
}
}
}
return groupRoles;
} catch (SOAPFaultException f) {
ErrorCode code = handleAxisFault(f);
switch(code) {
default:
logAxisError("Cannot get group roles", f);
}
return null;
} catch (WebServiceException e) {
if (e.getCause() instanceof ConnectException) {
throw new VmsNotAvailableException();
}
return null;
}
}
use of org.olat.modules.vitero.model.ViteroGroupRoles in project openolat by klemens.
the class ViteroBookingWebService method addMembers.
/**
* Update the list of members of the booking, it add and mutates the
* members and delete the missing members.
*
* @response.representation.200.qname {http://www.example.com}viteroGroupMemberVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc This is the list of all bookings of a resource
* @response.representation.200.example {@link org.olat.modules.vitero.restapi.Examples#SAMPLE_ViteroGroupMemberVO}
* @param bookingId The id of the booking
* @param members The array of members
* @return Nothing
*/
@POST
@Path("{bookingId}/members")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addMembers(@PathParam("bookingId") int bookingId, ViteroGroupMemberVO[] members) {
try {
ViteroBooking booking = viteroManager.getBookingById(null, ores, subIdentifier, bookingId);
if (booking == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
ViteroGroupRoles roles = viteroManager.getGroupRoles(booking.getGroupId());
if (roles == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
List<ViteroErrorVO> errors = new ArrayList<>();
List<String> currentEmails = new ArrayList<>(roles.getEmailsOfParticipants());
for (ViteroGroupMemberVO member : members) {
GroupRole role = GroupRole.valueOf(member.getGroupRole());
Identity identity = securityManager.loadIdentityByKey(member.getIdentityKey());
String currentEmail = identity.getUser().getProperty(UserConstants.EMAIL, null);
GroupRole currentRole = roles.getEmailsToRole().get(currentEmail);
if (currentRole == null) {
ViteroStatus status = viteroManager.addToRoom(booking, identity, role);
if (!status.isOk()) {
errors.add(viteroErrorVO(status));
}
} else if (!currentRole.equals(role)) {
Integer vmsUserId = roles.getEmailsToVmsUserId().get(currentEmail);
ViteroStatus status = viteroManager.changeGroupRole(booking.getGroupId(), vmsUserId.intValue(), role.getVmsValue());
if (!status.isOk()) {
errors.add(viteroErrorVO(status));
}
}
currentEmails.remove(currentEmail);
}
for (String email : currentEmails) {
SearchIdentityParams params = new SearchIdentityParams();
params.setUserProperties(Collections.singletonMap(UserConstants.EMAIL, email));
List<Identity> identities = securityManager.getIdentitiesByPowerSearch(params, 0, 1);
for (Identity identity : identities) {
ViteroStatus status = viteroManager.removeFromRoom(booking, identity);
if (!status.isOk()) {
errors.add(viteroErrorVO(status));
}
}
}
return Response.ok().build();
} catch (VmsNotAvailableException e) {
log.error("", e);
return handleNotAvailableException();
}
}
use of org.olat.modules.vitero.model.ViteroGroupRoles in project openolat by klemens.
the class ViteroUserToGroupController method loadModel.
private void loadModel() {
try {
ViteroGroupRoles groupRoles = viteroManager.getGroupRoles(booking.getGroupId());
ResourceMembers members = getIdentitiesInResource(groupRoles);
tableCtr.setTableDataModel(new UserToGroupDataModel(members, groupRoles));
int numOfFreePlaces = booking.getRoomSize() - groupRoles.size();
mainVC.contextPut("freePlaces", new String[] { Integer.toString(numOfFreePlaces) });
} catch (VmsNotAvailableException e) {
showError(VmsNotAvailableException.I18N_KEY);
}
}
Aggregations