Search in sources :

Example 6 with GroupRole

use of org.olat.modules.vitero.model.GroupRole 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)

Example 7 with GroupRole

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

the class ViteroBookingWebService method getMembers.

/**
 * Returns the list of members of the booking.
 *
 * @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
 * @return The list of members in the specified booking
 */
@GET
@Path("{bookingId}/members")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getMembers(@PathParam("bookingId") int bookingId) {
    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<String> currentEmails = new ArrayList<>(roles.getEmailsOfParticipants());
        List<ViteroGroupMemberVO> memberList = new ArrayList<>(currentEmails.size());
        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) {
                GroupRole role = roles.getEmailsToRole().get(email);
                memberList.add(new ViteroGroupMemberVO(identity.getKey(), role.name()));
            }
        }
        ViteroGroupMemberVO[] members = memberList.toArray(new ViteroGroupMemberVO[memberList.size()]);
        return Response.ok(members).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) SearchIdentityParams(org.olat.basesecurity.SearchIdentityParams) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with GroupRole

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

the class ViteroUserToGroupController method signIn.

private void signIn(List<Identity> identities) {
    try {
        ResourceMembers members = ((UserToGroupDataModel) tableCtr.getTableDataModel()).getMembers();
        for (Identity identity : identities) {
            boolean upgrade = members.getCoaches().contains(identity) || members.getOwners().contains(identity);
            GroupRole role = upgrade ? GroupRole.teamleader : null;
            ViteroStatus status = viteroManager.addToRoom(booking, identity, role);
            if (status.isOk()) {
                showInfo("signin.ok");
            } else {
                showInfo("signin.nok");
                break;
            }
        }
        loadModel();
    } catch (VmsNotAvailableException e) {
        showError(VmsNotAvailableException.I18N_KEY);
    }
}
Also used : VmsNotAvailableException(org.olat.modules.vitero.manager.VmsNotAvailableException) GroupRole(org.olat.modules.vitero.model.GroupRole) Identity(org.olat.core.id.Identity) ViteroStatus(org.olat.modules.vitero.model.ViteroStatus)

Aggregations

GroupRole (org.olat.modules.vitero.model.GroupRole)8 Identity (org.olat.core.id.Identity)6 VmsNotAvailableException (org.olat.modules.vitero.manager.VmsNotAvailableException)6 ViteroGroupRoles (org.olat.modules.vitero.model.ViteroGroupRoles)6 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 SearchIdentityParams (org.olat.basesecurity.SearchIdentityParams)4 ViteroBooking (org.olat.modules.vitero.model.ViteroBooking)4 ViteroStatus (org.olat.modules.vitero.model.ViteroStatus)4 Completegrouptype (de.vitero.schema.group.Completegrouptype)2 Group (de.vitero.schema.group.Group)2 Group_Type (de.vitero.schema.group.Group_Type)2 Groupid (de.vitero.schema.group.Groupid)2 Usertype (de.vitero.schema.user.Usertype)2 BigInteger (java.math.BigInteger)2 ConnectException (java.net.ConnectException)2 HashMap (java.util.HashMap)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2