use of org.olat.basesecurity.IdentityShort in project openolat by klemens.
the class UserManagerImpl method getUserDisplayName.
@Override
public String getUserDisplayName(Long identityKey) {
if (identityKey == null || identityKey.longValue() <= 0) {
return "";
}
String fullName = userToFullnameCache.get(identityKey);
if (fullName == null) {
IdentityShort identity = securityManager.loadIdentityShortByKey(identityKey);
fullName = getUserDisplayName(identity);
}
return fullName;
}
use of org.olat.basesecurity.IdentityShort in project openolat by klemens.
the class UserManagerImpl method getUserDisplayNamesByUserName.
@Override
public Map<String, String> getUserDisplayNamesByUserName(Collection<String> usernames) {
if (usernames == null || usernames.isEmpty()) {
return Collections.emptyMap();
}
Map<String, String> fullNames = new HashMap<>();
List<String> newUsernames = new ArrayList<>();
for (String username : usernames) {
String fullName = userToFullnameCache.get(username);
if (fullName != null) {
fullNames.put(username, fullName);
} else {
newUsernames.add(username);
}
}
List<IdentityShort> identities = securityManager.findShortIdentitiesByName(newUsernames);
for (IdentityShort identity : identities) {
String fullName = getUserDisplayName(identity);
fullNames.put(identity.getName(), fullName);
newUsernames.remove(identity.getName());
}
// not found
for (String notFound : newUsernames) {
userToFullnameCache.put(notFound, notFound);
}
return fullNames;
}
use of org.olat.basesecurity.IdentityShort in project openolat by klemens.
the class UserWebService method getPortraitHead.
/**
* Retrieves the portrait of an user
* @response.representation.200.mediaType application/octet-stream
* @response.representation.200.doc The portrait as image
* @response.representation.404.doc The identity or the portrait not found
* @param identityKey The identity key of the user being searched
* @return The image
*/
@HEAD
@Path("{identityKey}/portrait")
@Produces({ "image/jpeg", "image/jpg", MediaType.APPLICATION_OCTET_STREAM })
public Response getPortraitHead(@PathParam("identityKey") Long identityKey) {
try {
IdentityShort identity = BaseSecurityManager.getInstance().loadIdentityShortByKey(identityKey);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
File portrait = DisplayPortraitManager.getInstance().getBigPortrait(identity.getName());
if (portrait == null || !portrait.exists()) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Date lastModified = new Date(portrait.lastModified());
return Response.ok().lastModified(lastModified).build();
} catch (Throwable e) {
throw new WebApplicationException(e);
}
}
use of org.olat.basesecurity.IdentityShort in project openolat by klemens.
the class UserWebService method postPortrait.
/**
* Upload the portrait of an user
* @response.representation.200.mediaType application/octet-stream
* @response.representation.200.doc The portrait as image
* @response.representation.401.doc Not authorized
* @response.representation.404.doc The identity or the portrait not found
* @param identityKey The user key identifier of the user being searched
* @param file The image
* @param request The REST request
* @return The image
*/
@POST
@Path("{identityKey}/portrait")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response postPortrait(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
MultipartReader partsReader = null;
try {
IdentityShort identity = BaseSecurityManager.getInstance().loadIdentityShortByKey(identityKey);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Identity authIdentity = getUserRequest(request).getIdentity();
if (!isUserManager(request) && !identity.getKey().equals(authIdentity.getKey())) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
partsReader = new MultipartReader(request);
File tmpFile = partsReader.getFile();
String filename = partsReader.getFilename();
DisplayPortraitManager.getInstance().setPortrait(tmpFile, filename, identity.getName());
return Response.ok().build();
} catch (Throwable e) {
throw new WebApplicationException(e);
} finally {
MultipartReader.closeQuietly(partsReader);
}
}
use of org.olat.basesecurity.IdentityShort in project openolat by klemens.
the class UserWebService method getPortrait.
/**
* Retrieves the portrait of an user
* @response.representation.200.mediaType application/octet-stream
* @response.representation.200.doc The portrait as image
* @response.representation.404.doc The identity or the portrait not found
* @param identityKey The identity key of the user being searched
* @param request The REST request
* @return The image
*/
@GET
@Path("{identityKey}/portrait")
@Produces({ "image/jpeg", "image/jpg", MediaType.APPLICATION_OCTET_STREAM })
public Response getPortrait(@PathParam("identityKey") Long identityKey, @Context Request request) {
try {
IdentityShort identity = BaseSecurityManager.getInstance().loadIdentityShortByKey(identityKey);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
File portrait = DisplayPortraitManager.getInstance().getBigPortrait(identity.getName());
if (portrait == null || !portrait.exists()) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Date lastModified = new Date(portrait.lastModified());
Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
if (response == null) {
response = Response.ok(portrait).lastModified(lastModified).cacheControl(cc);
}
return response.build();
} catch (Throwable e) {
throw new WebApplicationException(e);
}
}
Aggregations