Search in sources :

Example 1 with CreateVmsSessionCodeRequest

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

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

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)

Aggregations

Codetype (de.vitero.schema.sessioncode.Codetype)2 CreateVmsSessionCodeRequest (de.vitero.schema.sessioncode.CreateVmsSessionCodeRequest)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