Search in sources :

Example 6 with IdentityShort

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;
}
Also used : IdentityShort(org.olat.basesecurity.IdentityShort)

Example 7 with IdentityShort

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;
}
Also used : HashMap(java.util.HashMap) IdentityShort(org.olat.basesecurity.IdentityShort) ArrayList(java.util.ArrayList)

Example 8 with IdentityShort

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) IdentityShort(org.olat.basesecurity.IdentityShort) File(java.io.File) Date(java.util.Date) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) Produces(javax.ws.rs.Produces)

Example 9 with IdentityShort

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) IdentityShort(org.olat.basesecurity.IdentityShort) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) File(java.io.File) MultipartReader(org.olat.restapi.support.MultipartReader) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 10 with IdentityShort

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) IdentityShort(org.olat.basesecurity.IdentityShort) File(java.io.File) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

IdentityShort (org.olat.basesecurity.IdentityShort)32 File (java.io.File)8 HashMap (java.util.HashMap)8 Path (javax.ws.rs.Path)8 WebApplicationException (javax.ws.rs.WebApplicationException)8 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 Produces (javax.ws.rs.Produces)6 HEAD (javax.ws.rs.HEAD)4 Identity (org.olat.core.id.Identity)4 ICourse (org.olat.course.ICourse)4 SearchAssessedIdentityParams (org.olat.course.assessment.model.SearchAssessedIdentityParams)4 BusinessGroup (org.olat.group.BusinessGroup)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 HashSet (java.util.HashSet)2 EntityManager (javax.persistence.EntityManager)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Response (javax.ws.rs.core.Response)2