Search in sources :

Example 6 with GetUserInfo

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

the class ViteroManager method getVmsUserId.

protected GetUserInfo getVmsUserId(Identity identity, boolean create) throws VmsNotAvailableException {
    int userId;
    boolean created = false;
    closeDBSessionSafely();
    Authentication authentication = securityManager.findAuthentication(identity, VMS_PROVIDER);
    if (authentication == null) {
        if (create) {
            created = true;
            userId = createVmsUser(identity);
            if (userId > 0) {
                securityManager.createAndPersistAuthentication(identity, VMS_PROVIDER, Integer.toString(userId), null, null);
            }
        } else {
            userId = -1;
        }
    } else {
        userId = Integer.parseInt(authentication.getAuthusername());
    }
    closeDBSessionSafely();
    return new GetUserInfo(created, userId);
}
Also used : GetUserInfo(org.olat.modules.vitero.model.GetUserInfo) Authentication(org.olat.basesecurity.Authentication)

Example 7 with GetUserInfo

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

the class ViteroManager method isUserOf.

public boolean isUserOf(ViteroBooking booking, Identity identity) throws VmsNotAvailableException {
    boolean member = false;
    GetUserInfo userInfo = getVmsUserId(identity, false);
    int userId = userInfo.getUserId();
    if (userId > 0) {
        List<Usertype> users = getVmsUsersByGroup(booking.getGroupId());
        if (users != null) {
            for (Usertype user : users) {
                if (userId == user.getId()) {
                    member = true;
                }
            }
        }
    }
    return member;
}
Also used : Usertype(de.vitero.schema.user.Usertype) GetUserInfo(org.olat.modules.vitero.model.GetUserInfo)

Example 8 with GetUserInfo

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

the class ViteroManager method createPersonalBookingSessionCode.

/**
 * Create a session code with a one hour expiration date
 * @param identity
 * @param booking
 * @return
 */
protected String createPersonalBookingSessionCode(Identity identity, ViteroBooking booking) throws VmsNotAvailableException {
    try {
        GetUserInfo userInfo = getVmsUserId(identity, true);
        int userId = userInfo.getUserId();
        // update user information
        if (!userInfo.isCreated()) {
            try {
                updateVmsUser(identity, userId);
                storePortrait(identity, userId);
            } catch (Exception e) {
                log.error("Cannot update user on vitero system:" + identity.getName(), e);
            }
        }
        CreatePersonalBookingSessionCodeRequest.Sessioncode code = new CreatePersonalBookingSessionCodeRequest.Sessioncode();
        code.setBookingid(booking.getBookingId());
        code.setUserid(userId);
        code.setTimezone(viteroModule.getTimeZoneId());
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.HOUR, 1);
        code.setExpirationdate(format(cal.getTime()));
        CreatePersonalBookingSessionCodeRequest codeRequest = new CreatePersonalBookingSessionCodeRequest();
        codeRequest.setSessioncode(code);
        Codetype myCode = getSessionCodeWebService().createPersonalBookingSessionCode(codeRequest);
        return myCode.getCode();
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            case userDoesntExist:
                log.error("User does not exist.", f);
                break;
            case userNotAssignedToGroup:
                log.error("User not assigned to group.", f);
                break;
            case invalidAttribut:
                log.error("Invalid attribute.", f);
                break;
            case invalidTimezone:
                log.error("Invalid time zone.", f);
                break;
            case bookingDoesntExist:
            case bookingDoesntExistPrime:
                log.error("Booking does not exist.", f);
                break;
            default:
                logAxisError("Cannot create session code.", f);
        }
        return null;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot create session code.", e);
        return null;
    }
}
Also used : CreatePersonalBookingSessionCodeRequest(de.vitero.schema.sessioncode.CreatePersonalBookingSessionCodeRequest) WebServiceException(javax.xml.ws.WebServiceException) Calendar(java.util.Calendar) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Codetype(de.vitero.schema.sessioncode.Codetype) ConnectException(java.net.ConnectException) WebServiceException(javax.xml.ws.WebServiceException) ConnectTimeoutException(org.apache.commons.httpclient.ConnectTimeoutException) ParseException(java.text.ParseException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Date(java.util.Date) GetUserInfo(org.olat.modules.vitero.model.GetUserInfo) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ConnectException(java.net.ConnectException)

Example 9 with GetUserInfo

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

the class ViteroManager method createVMSSessionCode.

/**
 * Create a session code with a one hour expiration date
 * @param identity
 * @param booking
 * @return
 */
protected String createVMSSessionCode(Identity identity) throws VmsNotAvailableException {
    try {
        GetUserInfo userInfo = getVmsUserId(identity, true);
        int userId = userInfo.getUserId();
        // update user information
        if (!userInfo.isCreated()) {
            try {
                updateVmsUser(identity, userId);
                storePortrait(identity, userId);
            } catch (Exception e) {
                log.error("Cannot update user on vitero system:" + identity.getName(), e);
            }
        }
        CreateVmsSessionCodeRequest.Sessioncode code = new CreateVmsSessionCodeRequest.Sessioncode();
        code.setUserid(userId);
        code.setTimezone(viteroModule.getTimeZoneId());
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.HOUR, 1);
        code.setExpirationdate(format(cal.getTime()));
        CreateVmsSessionCodeRequest codeRequest = new CreateVmsSessionCodeRequest();
        codeRequest.setSessioncode(code);
        Codetype myCode = getSessionCodeWebService().createVmsSessionCode(codeRequest);
        return myCode.getCode();
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            case userDoesntExist:
                log.error("User does not exist.", f);
                break;
            case userNotAssignedToGroup:
                log.error("User not assigned to group.", f);
                break;
            case invalidAttribut:
                log.error("Invalid attribute.", f);
                break;
            case invalidTimezone:
                log.error("Invalid time zone.", f);
                break;
            case bookingDoesntExist:
            case bookingDoesntExistPrime:
                log.error("Booking does not exist.", f);
                break;
            default:
                logAxisError("Cannot create session code.", f);
        }
        return null;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot create session code.", e);
        return null;
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Calendar(java.util.Calendar) CreateVmsSessionCodeRequest(de.vitero.schema.sessioncode.CreateVmsSessionCodeRequest) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Codetype(de.vitero.schema.sessioncode.Codetype) ConnectException(java.net.ConnectException) WebServiceException(javax.xml.ws.WebServiceException) ConnectTimeoutException(org.apache.commons.httpclient.ConnectTimeoutException) ParseException(java.text.ParseException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Date(java.util.Date) GetUserInfo(org.olat.modules.vitero.model.GetUserInfo) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ConnectException(java.net.ConnectException)

Example 10 with GetUserInfo

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

the class ViteroManager method addToRoom.

public ViteroStatus addToRoom(ViteroBooking booking, Identity identity, GroupRole role) throws VmsNotAvailableException {
    try {
        GetUserInfo userInfo = getVmsUserId(identity, true);
        int userId = userInfo.getUserId();
        if (userId < 0) {
            return new ViteroStatus(ErrorCode.userDoesntExist);
        }
        if (!userInfo.isCreated()) {
            // update user information
            try {
                updateVmsUser(identity, userId);
            // storePortrait(identity, userId);
            } catch (Exception e) {
                log.error("Cannot update user on vitero system:" + identity.getName(), e);
            }
        }
        Group groupWs = getGroupWebService();
        Groupiduserid groupuserId = new Groupiduserid();
        groupuserId.setGroupid(booking.getGroupId());
        groupuserId.setUserid(userId);
        groupWs.addUserToGroup(groupuserId);
        if (role != null) {
            groupWs = getGroupWebService();
            ChangeGroupRoleRequest roleRequest = new ChangeGroupRoleRequest();
            roleRequest.setGroupid(booking.getGroupId());
            roleRequest.setUserid(userId);
            roleRequest.setRole(role.getVmsValue());
            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 userNotAttachedToCustomer:
                log.error("The user is not attached to the customer (to which this group belongs)", 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 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) Groupiduserid(de.vitero.schema.group.Groupiduserid) GetUserInfo(org.olat.modules.vitero.model.GetUserInfo) 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) ChangeGroupRoleRequest(de.vitero.schema.group.ChangeGroupRoleRequest) ConnectException(java.net.ConnectException) WebServiceException(javax.xml.ws.WebServiceException) ConnectTimeoutException(org.apache.commons.httpclient.ConnectTimeoutException) ParseException(java.text.ParseException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ConnectException(java.net.ConnectException)

Aggregations

GetUserInfo (org.olat.modules.vitero.model.GetUserInfo)16 ConnectException (java.net.ConnectException)6 ParseException (java.text.ParseException)6 WebServiceException (javax.xml.ws.WebServiceException)6 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)6 ConnectTimeoutException (org.apache.commons.httpclient.ConnectTimeoutException)6 ErrorCode (org.olat.modules.vitero.model.ErrorCode)6 Codetype (de.vitero.schema.sessioncode.Codetype)4 Calendar (java.util.Calendar)4 Date (java.util.Date)4 ViteroStatus (org.olat.modules.vitero.model.ViteroStatus)4 Booking_Type (de.vitero.schema.booking.Booking_Type)2 ChangeGroupRoleRequest (de.vitero.schema.group.ChangeGroupRoleRequest)2 Group (de.vitero.schema.group.Group)2 Groupiduserid (de.vitero.schema.group.Groupiduserid)2 CreatePersonalBookingSessionCodeRequest (de.vitero.schema.sessioncode.CreatePersonalBookingSessionCodeRequest)2 CreateVmsSessionCodeRequest (de.vitero.schema.sessioncode.CreateVmsSessionCodeRequest)2 Usertype (de.vitero.schema.user.Usertype)2 Authentication (org.olat.basesecurity.Authentication)2 BusinessGroup (org.olat.group.BusinessGroup)2