Search in sources :

Example 6 with ViteroStatus

use of org.olat.modules.vitero.model.ViteroStatus in project OpenOLAT by OpenOLAT.

the class ViteroManager method removeFromRoom.

public ViteroStatus removeFromRoom(ViteroBooking booking, Identity identity) throws VmsNotAvailableException {
    GetUserInfo userInfo = getVmsUserId(identity, true);
    int userId = userInfo.getUserId();
    if (userId < 0) {
        // nothing to remove
        return new ViteroStatus();
    }
    return removeFromRoom(booking, userId);
}
Also used : GetUserInfo(org.olat.modules.vitero.model.GetUserInfo) ViteroStatus(org.olat.modules.vitero.model.ViteroStatus)

Example 7 with ViteroStatus

use of org.olat.modules.vitero.model.ViteroStatus in project OpenOLAT by OpenOLAT.

the class ViteroManager method createBooking.

public ViteroStatus createBooking(BusinessGroup group, OLATResourceable ores, String subIdentifier, ViteroBooking vBooking) throws VmsNotAvailableException {
    Bookingtype booking = getVmsBookingById(vBooking.getBookingId());
    if (booking != null) {
        log.info("Booking already exists: " + vBooking.getBookingId());
        return new ViteroStatus();
    }
    try {
        // a group per meeting
        String groupName = vBooking.getGroupName();
        int groupId = createGroup(groupName);
        if (groupId < 0) {
            return new ViteroStatus(ErrorCode.unkown);
        }
        vBooking.setGroupId(groupId);
        // create the meeting with the new group
        Booking bookingWs = getBookingWebService();
        CreateBookingRequest createRequest = new CreateBookingRequest();
        Newbookingtype newBooking = new Newbookingtype();
        // mandatory
        newBooking.setStart(format(vBooking.getStart()));
        newBooking.setEnd(format(vBooking.getEnd()));
        newBooking.setStartbuffer(vBooking.getStartBuffer());
        newBooking.setEndbuffer(vBooking.getEndBuffer());
        newBooking.setGroupid(groupId);
        newBooking.setRoomsize(vBooking.getRoomSize());
        newBooking.setTimezone(viteroModule.getTimeZoneId());
        if (StringHelper.containsNonWhitespace(vBooking.getEventName())) {
            newBooking.setEventname(vBooking.getEventName());
        }
        createRequest.setBooking(newBooking);
        CreateBookingResponse response = bookingWs.createBooking(createRequest);
        Boolean bookingCollision = response.isBookingcollision();
        Boolean moduleCollision = response.isModulecollision();
        int bookingId = response.getBookingid();
        if (bookingCollision != null && bookingCollision.booleanValue()) {
            return new ViteroStatus(ErrorCode.bookingCollision);
        } else if (moduleCollision != null && moduleCollision.booleanValue()) {
            return new ViteroStatus(ErrorCode.moduleCollision);
        }
        vBooking.setBookingId(bookingId);
        getOrCreateProperty(group, ores, subIdentifier, vBooking);
        return new ViteroStatus();
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            case invalidTimezone:
                log.error("Invalid time zone!", f);
                break;
            case bookingCollision:
                log.error("Booking collision!", f);
                break;
            case moduleCollision:
                log.error("Invalid module selection!", f);
                break;
            case bookingInPast:
                log.error("Booking in the past!", f);
                break;
            case licenseExpired:
                log.error("License/customer expired!", f);
                break;
            default:
                logAxisError("Cannot create a booking.", f);
        }
        return new ViteroStatus(code);
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot create a booking.", e);
        return new ViteroStatus(ErrorCode.remoteException);
    }
}
Also used : CreateBookingRequest(de.vitero.schema.booking.CreateBookingRequest) CreateBookingResponse(de.vitero.schema.booking.CreateBookingResponse) WebServiceException(javax.xml.ws.WebServiceException) Booking(de.vitero.schema.booking.Booking) ViteroBooking(org.olat.modules.vitero.model.ViteroBooking) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Bookingtype(de.vitero.schema.booking.Bookingtype) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ViteroStatus(org.olat.modules.vitero.model.ViteroStatus) Newbookingtype(de.vitero.schema.booking.Newbookingtype) ConnectException(java.net.ConnectException)

Example 8 with ViteroStatus

use of org.olat.modules.vitero.model.ViteroStatus in project OpenOLAT by OpenOLAT.

the class ViteroManager method changeGroupRole.

public ViteroStatus changeGroupRole(int groupId, int vmsUserId, int roleId) throws VmsNotAvailableException {
    try {
        Group groupWs = getGroupWebService();
        ChangeGroupRoleRequest roleRequest = new ChangeGroupRoleRequest();
        roleRequest.setGroupid(groupId);
        roleRequest.setUserid(vmsUserId);
        roleRequest.setRole(roleId);
        groupWs.changeGroupRole(roleRequest);
        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;
            default:
                logAxisError("Cannot add an user to a group", f);
        }
        return new ViteroStatus(code);
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot add an user to a group", e);
        return new ViteroStatus(ErrorCode.unkown);
    }
}
Also used : Group(de.vitero.schema.group.Group) ViteroGroup(org.olat.modules.vitero.model.ViteroGroup) BusinessGroup(org.olat.group.BusinessGroup) WebServiceException(javax.xml.ws.WebServiceException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ChangeGroupRoleRequest(de.vitero.schema.group.ChangeGroupRoleRequest) ViteroStatus(org.olat.modules.vitero.model.ViteroStatus) ConnectException(java.net.ConnectException)

Example 9 with ViteroStatus

use of org.olat.modules.vitero.model.ViteroStatus in project openolat by klemens.

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);
    }
}
Also used : Groupiduserid(de.vitero.schema.group.Groupiduserid) WebServiceException(javax.xml.ws.WebServiceException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ViteroStatus(org.olat.modules.vitero.model.ViteroStatus) ConnectException(java.net.ConnectException)

Example 10 with ViteroStatus

use of org.olat.modules.vitero.model.ViteroStatus 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();
    }
}
Also used : ViteroGroupRoles(org.olat.modules.vitero.model.ViteroGroupRoles) VmsNotAvailableException(org.olat.modules.vitero.manager.VmsNotAvailableException) ArrayList(java.util.ArrayList) ViteroBooking(org.olat.modules.vitero.model.ViteroBooking) GroupRole(org.olat.modules.vitero.model.GroupRole) Identity(org.olat.core.id.Identity) ViteroStatus(org.olat.modules.vitero.model.ViteroStatus) SearchIdentityParams(org.olat.basesecurity.SearchIdentityParams) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

ViteroStatus (org.olat.modules.vitero.model.ViteroStatus)26 VmsNotAvailableException (org.olat.modules.vitero.manager.VmsNotAvailableException)12 ConnectException (java.net.ConnectException)10 WebServiceException (javax.xml.ws.WebServiceException)10 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)10 ErrorCode (org.olat.modules.vitero.model.ErrorCode)10 ViteroBooking (org.olat.modules.vitero.model.ViteroBooking)8 ChangeGroupRoleRequest (de.vitero.schema.group.ChangeGroupRoleRequest)4 Group (de.vitero.schema.group.Group)4 Groupiduserid (de.vitero.schema.group.Groupiduserid)4 Identity (org.olat.core.id.Identity)4 BusinessGroup (org.olat.group.BusinessGroup)4 GetUserInfo (org.olat.modules.vitero.model.GetUserInfo)4 GroupRole (org.olat.modules.vitero.model.GroupRole)4 ViteroGroup (org.olat.modules.vitero.model.ViteroGroup)4 Booking (de.vitero.schema.booking.Booking)2 Bookingtype (de.vitero.schema.booking.Bookingtype)2 CreateBookingRequest (de.vitero.schema.booking.CreateBookingRequest)2 CreateBookingResponse (de.vitero.schema.booking.CreateBookingResponse)2 Newbookingtype (de.vitero.schema.booking.Newbookingtype)2