use of org.olat.modules.vitero.model.ViteroStatus in project OpenOLAT by OpenOLAT.
the class ViteroUserToGroupController method signIn.
private void signIn(List<Identity> identities) {
try {
ResourceMembers members = ((UserToGroupDataModel) tableCtr.getTableDataModel()).getMembers();
for (Identity identity : identities) {
boolean upgrade = members.getCoaches().contains(identity) || members.getOwners().contains(identity);
GroupRole role = upgrade ? GroupRole.teamleader : null;
ViteroStatus status = viteroManager.addToRoom(booking, identity, role);
if (status.isOk()) {
showInfo("signin.ok");
} else {
showInfo("signin.nok");
break;
}
}
loadModel();
} catch (VmsNotAvailableException e) {
showError(VmsNotAvailableException.I18N_KEY);
}
}
use of org.olat.modules.vitero.model.ViteroStatus 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.ViteroStatus in project OpenOLAT by OpenOLAT.
the class ViteroBookingWebService method saveRoom.
private Response saveRoom(ViteroBookingVO booking) {
try {
ViteroBooking vBooking = new ViteroBooking();
vBooking.setBookingId(booking.getBookingId());
vBooking.setExternalId(booking.getExternalId());
vBooking.setGroupId(booking.getGroupId());
vBooking.setGroupName(booking.getGroupName());
vBooking.setEventName(booking.getEventName());
vBooking.setStart(booking.getStart());
vBooking.setStartBuffer(booking.getStartBuffer());
vBooking.setEnd(booking.getEnd());
vBooking.setEndBuffer(booking.getEndBuffer());
vBooking.setRoomSize(booking.getRoomSize());
vBooking.setAutoSignIn(booking.isAutoSignIn());
vBooking.setTimeZoneId(viteroModule.getTimeZoneId());
ViteroStatus status;
if (booking.getBookingId() > 0) {
status = viteroManager.updateVmsBooking(vBooking);
} else {
status = viteroManager.createBooking(null, ores, subIdentifier, vBooking);
}
Response response;
if (status.isOk()) {
response = Response.ok(new ViteroBookingVO(vBooking)).build();
} else {
response = handleViteroError(status);
}
return response;
} catch (VmsNotAvailableException e) {
log.error("", e);
return handleNotAvailableException();
}
}
use of org.olat.modules.vitero.model.ViteroStatus in project OpenOLAT by OpenOLAT.
the class ViteroBookingWebService method handleNotAvailableException.
private Response handleNotAvailableException() {
ViteroStatus status = new ViteroStatus(ErrorCode.unkown);
ViteroErrorVO error = new ViteroErrorVO(status, "vitero server is probable not avalailable at this time");
return Response.serverError().entity(error).status(Status.SERVICE_UNAVAILABLE).build();
}
use of org.olat.modules.vitero.model.ViteroStatus in project OpenOLAT by OpenOLAT.
the class ViteroManager method removeFromRoom.
public ViteroStatus removeFromRoom(ViteroBooking booking, int userId) throws VmsNotAvailableException {
try {
Groupiduserid groupuserId = new Groupiduserid();
groupuserId.setGroupid(booking.getGroupId());
groupuserId.setUserid(userId);
getGroupWebService().removeUserFromGroup(groupuserId);
return new ViteroStatus();
} catch (SOAPFaultException f) {
ErrorCode code = handleAxisFault(f);
switch(code) {
case userDoesntExist:
log.error("The user doesn ́t exist!", f);
break;
case groupDoesntExist:
log.error("The group doesn ́t exist", f);
break;
case invalidAttribut:
log.error("An id <= 0", f);
break;
default:
logAxisError("Cannot remove an user from a group", f);
}
return new ViteroStatus(code);
} catch (WebServiceException e) {
if (e.getCause() instanceof ConnectException) {
throw new VmsNotAvailableException();
}
log.error("Cannot remove an user from a group", e);
return new ViteroStatus(ErrorCode.unkown);
}
}
Aggregations