Search in sources :

Example 1 with CreatePersonalBookingSessionCodeRequest

use of de.vitero.schema.sessioncode.CreatePersonalBookingSessionCodeRequest 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 2 with CreatePersonalBookingSessionCodeRequest

use of de.vitero.schema.sessioncode.CreatePersonalBookingSessionCodeRequest in project openolat by klemens.

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)

Aggregations

Codetype (de.vitero.schema.sessioncode.Codetype)2 CreatePersonalBookingSessionCodeRequest (de.vitero.schema.sessioncode.CreatePersonalBookingSessionCodeRequest)2 ConnectException (java.net.ConnectException)2 ParseException (java.text.ParseException)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 WebServiceException (javax.xml.ws.WebServiceException)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 ConnectTimeoutException (org.apache.commons.httpclient.ConnectTimeoutException)2 ErrorCode (org.olat.modules.vitero.model.ErrorCode)2 GetUserInfo (org.olat.modules.vitero.model.GetUserInfo)2