Search in sources :

Example 36 with ErrorCode

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

the class ViteroManager method updateVmsUser.

protected boolean updateVmsUser(Identity identity, int vmsUserId) throws VmsNotAvailableException {
    try {
        UpdateUserRequest updateRequest = new UpdateUserRequest();
        Completeusertype user = new Completeusertype();
        user.setId(vmsUserId);
        // mandatory
        User olatUser = identity.getUser();
        user.setUsername("olat." + WebappHelper.getInstanceId() + "." + identity.getName());
        user.setSurname(olatUser.getProperty(UserConstants.LASTNAME, null));
        user.setFirstname(olatUser.getProperty(UserConstants.FIRSTNAME, null));
        user.setEmail(olatUser.getProperty(UserConstants.EMAIL, null));
        // optional
        String language = identity.getUser().getPreferences().getLanguage();
        if (StringHelper.containsNonWhitespace(language) && language.startsWith("de")) {
            user.setLocale("de_DE");
        } else if (StringHelper.containsNonWhitespace(language) && language.startsWith("fr")) {
            user.setLocale("fr_FR");
        } else if (StringHelper.containsNonWhitespace(language) && language.startsWith("zh_CN")) {
            user.setLocale("zh_CN");
        } else {
            user.setLocale("en_GB");
        }
        user.setPcstate("NOT_TESTED");
        user.setTimezone(viteroModule.getTimeZoneId());
        String street = olatUser.getProperty(UserConstants.STREET, null);
        if (StringHelper.containsNonWhitespace(street)) {
            user.setStreet(street);
        }
        String zip = olatUser.getProperty(UserConstants.ZIPCODE, null);
        if (StringHelper.containsNonWhitespace(zip)) {
            user.setZip(zip);
        }
        String city = olatUser.getProperty(UserConstants.CITY, null);
        if (StringHelper.containsNonWhitespace(city)) {
            user.setCity(city);
        }
        String country = olatUser.getProperty(UserConstants.COUNTRY, null);
        if (StringHelper.containsNonWhitespace(country)) {
            user.setCountry(country);
        }
        String mobile = olatUser.getProperty(UserConstants.TELMOBILE, null);
        if (StringHelper.containsNonWhitespace(mobile)) {
            user.setMobile(mobile);
        }
        String phonePrivate = olatUser.getProperty(UserConstants.TELPRIVATE, null);
        if (StringHelper.containsNonWhitespace(phonePrivate)) {
            user.setPhone(phonePrivate);
        }
        String phoneOffice = olatUser.getProperty(UserConstants.TELOFFICE, null);
        if (StringHelper.containsNonWhitespace(phoneOffice)) {
            user.setPhone(phoneOffice);
        }
        String institution = olatUser.getProperty(UserConstants.INSTITUTIONALNAME, null);
        if (StringHelper.containsNonWhitespace(institution)) {
            user.setCompany(institution);
        }
        updateRequest.setUser(user);
        getUserWebService().updateUser(updateRequest);
        return true;
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            default:
                logAxisError("Cannot create vms user.", f);
        }
        return true;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot create vms user.", e);
        return true;
    }
}
Also used : User(org.olat.core.id.User) ViteroUser(org.olat.modules.vitero.model.ViteroUser) WebServiceException(javax.xml.ws.WebServiceException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ErrorCode(org.olat.modules.vitero.model.ErrorCode) UpdateUserRequest(de.vitero.schema.user.UpdateUserRequest) Completeusertype(de.vitero.schema.user.Completeusertype) ConnectException(java.net.ConnectException)

Example 37 with ErrorCode

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

the class ViteroManager method getVmsBookingById.

private Bookingtype getVmsBookingById(int id) throws VmsNotAvailableException {
    if (id < 0)
        return null;
    try {
        Bookingid bookingId = new Bookingid();
        bookingId.setBookingid(id);
        Bookingtype booking = getBookingWebService().getBookingById(bookingId);
        return booking;
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            case invalidAttribut:
                log.error("ids <= 0", f);
                break;
            case bookingDoesntExist:
                log.error("The booking does not exist", f);
                break;
            default:
                logAxisError("Cannot get booking by id: " + id, f);
        }
        return null;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot get booking by id: " + id, e);
        return null;
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Bookingid(de.vitero.schema.booking.Bookingid) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ErrorCode(org.olat.modules.vitero.model.ErrorCode) Bookingtype(de.vitero.schema.booking.Bookingtype) ConnectException(java.net.ConnectException)

Example 38 with ErrorCode

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

the class ViteroManager method getCustomersUsers.

public List<Usertype> getCustomersUsers() throws VmsNotAvailableException {
    try {
        GetUserListByCustomerRequest listRequest = new GetUserListByCustomerRequest();
        listRequest.setCustomerid(viteroModule.getCustomerId());
        Userlist userList = getUserWebService().getUserListByCustomer(listRequest);
        List<Usertype> userTypes = userList.getUser();
        return userTypes;
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            default:
                logAxisError("Cannot get the list of users of customer: " + viteroModule.getCustomerId(), f);
        }
        return null;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot get the list of users of customer: " + viteroModule.getCustomerId(), e);
        return null;
    }
}
Also used : Usertype(de.vitero.schema.user.Usertype) WebServiceException(javax.xml.ws.WebServiceException) Userlist(de.vitero.schema.user.Userlist) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ErrorCode(org.olat.modules.vitero.model.ErrorCode) GetUserListByCustomerRequest(de.vitero.schema.user.GetUserListByCustomerRequest) ConnectException(java.net.ConnectException)

Example 39 with ErrorCode

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

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 40 with ErrorCode

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

the class ViteroManager method getGroupRoles.

/**
 * @param id The group id
 * @return
 * @throws VmsNotAvailableException
 */
public ViteroGroupRoles getGroupRoles(int id) throws VmsNotAvailableException {
    try {
        Group groupWs = getGroupWebService();
        Groupid groupId = new Groupid();
        groupId.setGroupid(id);
        Group_Type group = groupWs.getGroup(groupId);
        Completegrouptype groupType = group.getGroup();
        List<Completegrouptype.Participant> participants = groupType.getParticipant();
        int numOfParticipants = participants == null ? 0 : participants.size();
        ViteroGroupRoles groupRoles = new ViteroGroupRoles();
        if (numOfParticipants > 0) {
            Map<Integer, String> idToEmails = new HashMap<Integer, String>();
            List<Usertype> vmsUsers = getVmsUsersByGroup(id);
            if (vmsUsers != null) {
                for (Usertype vmsUser : vmsUsers) {
                    Integer userId = new Integer(vmsUser.getId());
                    String email = vmsUser.getEmail();
                    groupRoles.getEmailsOfParticipants().add(email);
                    idToEmails.put(userId, email);
                }
            }
            for (int i = 0; i < numOfParticipants; i++) {
                Completegrouptype.Participant participant = participants.get(i);
                Integer userId = new Integer(participant.getUserid());
                String email = idToEmails.get(userId);
                if (email != null) {
                    GroupRole role = GroupRole.valueOf(participant.getRole());
                    groupRoles.getEmailsToRole().put(email, role);
                    groupRoles.getEmailsToVmsUserId().put(email, userId);
                }
            }
        }
        return groupRoles;
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            default:
                logAxisError("Cannot get group roles", f);
        }
        return null;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        return null;
    }
}
Also used : Group(de.vitero.schema.group.Group) ViteroGroup(org.olat.modules.vitero.model.ViteroGroup) BusinessGroup(org.olat.group.BusinessGroup) ViteroGroupRoles(org.olat.modules.vitero.model.ViteroGroupRoles) Usertype(de.vitero.schema.user.Usertype) WebServiceException(javax.xml.ws.WebServiceException) HashMap(java.util.HashMap) Completegrouptype(de.vitero.schema.group.Completegrouptype) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Group_Type(de.vitero.schema.group.Group_Type) Groupid(de.vitero.schema.group.Groupid) BigInteger(java.math.BigInteger) GroupRole(org.olat.modules.vitero.model.GroupRole) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ConnectException(java.net.ConnectException)

Aggregations

ConnectException (java.net.ConnectException)48 WebServiceException (javax.xml.ws.WebServiceException)48 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)48 ErrorCode (org.olat.modules.vitero.model.ErrorCode)48 BigInteger (java.math.BigInteger)10 ViteroStatus (org.olat.modules.vitero.model.ViteroStatus)10 Groupid (de.vitero.schema.group.Groupid)8 Group (de.vitero.schema.group.Group)6 Usertype (de.vitero.schema.user.Usertype)6 ParseException (java.text.ParseException)6 ArrayList (java.util.ArrayList)6 ConnectTimeoutException (org.apache.commons.httpclient.ConnectTimeoutException)6 BusinessGroup (org.olat.group.BusinessGroup)6 GetUserInfo (org.olat.modules.vitero.model.GetUserInfo)6 ViteroGroup (org.olat.modules.vitero.model.ViteroGroup)6 Booking (de.vitero.schema.booking.Booking)4 Bookinglist (de.vitero.schema.booking.Bookinglist)4 Bookingtype (de.vitero.schema.booking.Bookingtype)4 ChangeGroupRoleRequest (de.vitero.schema.group.ChangeGroupRoleRequest)4 Completegrouptype (de.vitero.schema.group.Completegrouptype)4