use of org.olat.basesecurity.SearchIdentityParams 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();
}
}
use of org.olat.basesecurity.SearchIdentityParams in project openolat by klemens.
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;
}
use of org.olat.basesecurity.SearchIdentityParams in project openolat by klemens.
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();
}
use of org.olat.basesecurity.SearchIdentityParams 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();
}
}
use of org.olat.basesecurity.SearchIdentityParams in project openolat by klemens.
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;
}
Aggregations