Search in sources :

Example 1 with SearchIdentityParams

use of org.olat.basesecurity.SearchIdentityParams 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 SearchIdentityParams

use of org.olat.basesecurity.SearchIdentityParams 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 SearchIdentityParams

use of org.olat.basesecurity.SearchIdentityParams in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_8_4_0 method checkMailOfDeletedUsers.

private boolean checkMailOfDeletedUsers(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    if (!uhd.getBooleanDataValue(TASK_CHECK_MAIL_DELETED_USERS)) {
        int counter = 0;
        List<Identity> deletedIdentities;
        do {
            SearchIdentityParams params = new SearchIdentityParams();
            params.setStatus(new Integer(Identity.STATUS_DELETED));
            deletedIdentities = securityManager.getIdentitiesByPowerSearch(params, counter, BATCH_SIZE);
            for (Identity deletedIdentity : deletedIdentities) {
                User deletedUser = deletedIdentity.getUser();
                boolean changed = processDeletedIdentityEmail(deletedUser, UserConstants.EMAIL);
                changed |= processDeletedIdentityEmail(deletedUser, UserConstants.INSTITUTIONALEMAIL);
                if (changed) {
                    UserManager.getInstance().updateUser(deletedUser);
                    log.audit("Update emails of deleted identity: " + deletedIdentity.getName() + " with key: " + deletedIdentity.getKey());
                }
            }
            counter += deletedIdentities.size();
            log.audit("Processed deleted identities: " + deletedIdentities.size());
            dbInstance.intermediateCommit();
        } while (deletedIdentities.size() == BATCH_SIZE);
        uhd.setBooleanDataValue(TASK_CHECK_MAIL_DELETED_USERS, true);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
    return true;
}
Also used : User(org.olat.core.id.User) Identity(org.olat.core.id.Identity) SearchIdentityParams(org.olat.basesecurity.SearchIdentityParams)

Example 4 with SearchIdentityParams

use of org.olat.basesecurity.SearchIdentityParams in project OpenOLAT by OpenOLAT.

the class AbstractMemberListController method filterIdentities.

private List<Identity> filterIdentities(SearchMembersParams params, Collection<Long> identityKeys) {
    SearchIdentityParams idParams = new SearchIdentityParams();
    if (StringHelper.containsNonWhitespace(params.getSearchString())) {
        String searchString = params.getSearchString();
        Map<String, String> propertiesSearch = new HashMap<>();
        for (UserPropertyHandler handler : userPropertyHandlers) {
            propertiesSearch.put(handler.getName(), searchString);
        }
        idParams.setLogin(searchString);
        idParams.setUserProperties(propertiesSearch);
    } else {
        if (params.getUserPropertiesSearch() != null && !params.getUserPropertiesSearch().isEmpty()) {
            idParams.setUserProperties(params.getUserPropertiesSearch());
        }
        if (StringHelper.containsNonWhitespace(params.getLogin())) {
            idParams.setLogin(params.getLogin());
        }
    }
    List<Long> identityKeyList = new ArrayList<>(identityKeys);
    List<Identity> identities = new ArrayList<>(identityKeyList.size());
    int count = 0;
    int batch = 500;
    do {
        int toIndex = Math.min(count + batch, identityKeyList.size());
        List<Long> toLoad = identityKeyList.subList(count, toIndex);
        idParams.setIdentityKeys(toLoad);
        List<Identity> batchOfIdentities = securityManager.getIdentitiesByPowerSearch(idParams, 0, -1);
        identities.addAll(batchOfIdentities);
        count += batch;
    } while (count < identityKeyList.size());
    return identities;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) SearchIdentityParams(org.olat.basesecurity.SearchIdentityParams)

Example 5 with SearchIdentityParams

use of org.olat.basesecurity.SearchIdentityParams in project OpenOLAT by OpenOLAT.

the class UserWebService method getManagedUsers.

@GET
@Path("managed")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getManagedUsers(@Context HttpServletRequest httpRequest) {
    if (!isUserManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    SearchIdentityParams params = new SearchIdentityParams();
    params.setManaged(Boolean.TRUE);
    List<Identity> identities = BaseSecurityManager.getInstance().getIdentitiesByPowerSearch(params, 0, -1);
    int count = 0;
    ManagedUserVO[] userVOs = new ManagedUserVO[identities.size()];
    for (Identity identity : identities) {
        userVOs[count++] = getManaged(identity);
    }
    return Response.ok(userVOs).build();
}
Also used : Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) SearchIdentityParams(org.olat.basesecurity.SearchIdentityParams) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

SearchIdentityParams (org.olat.basesecurity.SearchIdentityParams)10 Identity (org.olat.core.id.Identity)10 ArrayList (java.util.ArrayList)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 GET (javax.ws.rs.GET)4 VmsNotAvailableException (org.olat.modules.vitero.manager.VmsNotAvailableException)4 GroupRole (org.olat.modules.vitero.model.GroupRole)4 ViteroBooking (org.olat.modules.vitero.model.ViteroBooking)4 ViteroGroupRoles (org.olat.modules.vitero.model.ViteroGroupRoles)4 HashMap (java.util.HashMap)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 User (org.olat.core.id.User)2 ViteroStatus (org.olat.modules.vitero.model.ViteroStatus)2 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)2 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)2