Search in sources :

Example 1 with ViteroGroupRoles

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

the class ViteroBookingWebService method addMembers.

/**
 * Update the list of members of the booking, it add and mutates the
 * members and delete the missing members.
 *
 * @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
 * @param members The array of members
 * @return Nothing
 */
@POST
@Path("{bookingId}/members")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addMembers(@PathParam("bookingId") int bookingId, ViteroGroupMemberVO[] members) {
    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<ViteroErrorVO> errors = new ArrayList<>();
        List<String> currentEmails = new ArrayList<>(roles.getEmailsOfParticipants());
        for (ViteroGroupMemberVO member : members) {
            GroupRole role = GroupRole.valueOf(member.getGroupRole());
            Identity identity = securityManager.loadIdentityByKey(member.getIdentityKey());
            String currentEmail = identity.getUser().getProperty(UserConstants.EMAIL, null);
            GroupRole currentRole = roles.getEmailsToRole().get(currentEmail);
            if (currentRole == null) {
                ViteroStatus status = viteroManager.addToRoom(booking, identity, role);
                if (!status.isOk()) {
                    errors.add(viteroErrorVO(status));
                }
            } else if (!currentRole.equals(role)) {
                Integer vmsUserId = roles.getEmailsToVmsUserId().get(currentEmail);
                ViteroStatus status = viteroManager.changeGroupRole(booking.getGroupId(), vmsUserId.intValue(), role.getVmsValue());
                if (!status.isOk()) {
                    errors.add(viteroErrorVO(status));
                }
            }
            currentEmails.remove(currentEmail);
        }
        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) {
                ViteroStatus status = viteroManager.removeFromRoom(booking, identity);
                if (!status.isOk()) {
                    errors.add(viteroErrorVO(status));
                }
            }
        }
        return Response.ok().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) ViteroStatus(org.olat.modules.vitero.model.ViteroStatus) SearchIdentityParams(org.olat.basesecurity.SearchIdentityParams) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 2 with ViteroGroupRoles

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

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 3 with ViteroGroupRoles

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

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 4 with ViteroGroupRoles

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

the class ViteroBookingWebService method addMembers.

/**
 * Update the list of members of the booking, it add and mutates the
 * members and delete the missing members.
 *
 * @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
 * @param members The array of members
 * @return Nothing
 */
@POST
@Path("{bookingId}/members")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addMembers(@PathParam("bookingId") int bookingId, ViteroGroupMemberVO[] members) {
    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<ViteroErrorVO> errors = new ArrayList<>();
        List<String> currentEmails = new ArrayList<>(roles.getEmailsOfParticipants());
        for (ViteroGroupMemberVO member : members) {
            GroupRole role = GroupRole.valueOf(member.getGroupRole());
            Identity identity = securityManager.loadIdentityByKey(member.getIdentityKey());
            String currentEmail = identity.getUser().getProperty(UserConstants.EMAIL, null);
            GroupRole currentRole = roles.getEmailsToRole().get(currentEmail);
            if (currentRole == null) {
                ViteroStatus status = viteroManager.addToRoom(booking, identity, role);
                if (!status.isOk()) {
                    errors.add(viteroErrorVO(status));
                }
            } else if (!currentRole.equals(role)) {
                Integer vmsUserId = roles.getEmailsToVmsUserId().get(currentEmail);
                ViteroStatus status = viteroManager.changeGroupRole(booking.getGroupId(), vmsUserId.intValue(), role.getVmsValue());
                if (!status.isOk()) {
                    errors.add(viteroErrorVO(status));
                }
            }
            currentEmails.remove(currentEmail);
        }
        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) {
                ViteroStatus status = viteroManager.removeFromRoom(booking, identity);
                if (!status.isOk()) {
                    errors.add(viteroErrorVO(status));
                }
            }
        }
        return Response.ok().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) ViteroStatus(org.olat.modules.vitero.model.ViteroStatus) SearchIdentityParams(org.olat.basesecurity.SearchIdentityParams) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with ViteroGroupRoles

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

the class ViteroUserToGroupController method loadModel.

private void loadModel() {
    try {
        ViteroGroupRoles groupRoles = viteroManager.getGroupRoles(booking.getGroupId());
        ResourceMembers members = getIdentitiesInResource(groupRoles);
        tableCtr.setTableDataModel(new UserToGroupDataModel(members, groupRoles));
        int numOfFreePlaces = booking.getRoomSize() - groupRoles.size();
        mainVC.contextPut("freePlaces", new String[] { Integer.toString(numOfFreePlaces) });
    } catch (VmsNotAvailableException e) {
        showError(VmsNotAvailableException.I18N_KEY);
    }
}
Also used : ViteroGroupRoles(org.olat.modules.vitero.model.ViteroGroupRoles) VmsNotAvailableException(org.olat.modules.vitero.manager.VmsNotAvailableException)

Aggregations

ViteroGroupRoles (org.olat.modules.vitero.model.ViteroGroupRoles)8 VmsNotAvailableException (org.olat.modules.vitero.manager.VmsNotAvailableException)6 GroupRole (org.olat.modules.vitero.model.GroupRole)6 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 SearchIdentityParams (org.olat.basesecurity.SearchIdentityParams)4 Identity (org.olat.core.id.Identity)4 ViteroBooking (org.olat.modules.vitero.model.ViteroBooking)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 POST (javax.ws.rs.POST)2