Search in sources :

Example 26 with IdentityShort

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

the class InstantMessagingServiceImpl method getBuddyById.

@Override
public Buddy getBuddyById(Long identityKey) {
    IdentityShort identity = securityManager.loadIdentityShortByKey(identityKey);
    String fullname = userManager.getUserDisplayName(identity);
    String status;
    boolean online = isOnline(identityKey);
    if (online) {
        String prefStatus = prefsDao.getStatus(identityKey);
        if (prefStatus == null) {
            status = Presence.available.name();
        } else {
            status = prefStatus;
        }
    } else {
        status = Presence.unavailable.name();
    }
    return new Buddy(identity.getKey(), identity.getName(), fullname, false, status);
}
Also used : IdentityShort(org.olat.basesecurity.IdentityShort) Buddy(org.olat.instantMessaging.model.Buddy)

Example 27 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project openolat by klemens.

the class UserWebService method getOriginalPortraitHead.

/**
 * 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/{size}")
@Produces({ "image/jpeg", "image/jpg", MediaType.APPLICATION_OCTET_STREAM })
public Response getOriginalPortraitHead(@PathParam("identityKey") Long identityKey, @PathParam("size") String size) {
    try {
        IdentityShort identity = BaseSecurityManager.getInstance().loadIdentityShortByKey(identityKey);
        if (identity == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        DisplayPortraitManager portraitManager = DisplayPortraitManager.getInstance();
        File portrait = null;
        if ("master".equals(size)) {
            portrait = portraitManager.getMasterPortrait(identity.getName());
        } else if ("big".equals(size)) {
            portrait = portraitManager.getBigPortrait(identity.getName());
        } else if ("small".equals(size)) {
            portrait = portraitManager.getSmallPortrait(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) DisplayPortraitManager(org.olat.user.DisplayPortraitManager) 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 28 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project openolat by klemens.

the class UserManagerImpl method getUserDisplayNamesByKey.

@Override
public Map<Long, String> getUserDisplayNamesByKey(Collection<Long> identityKeys) {
    if (identityKeys == null || identityKeys.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<Long, String> fullNames = new HashMap<>();
    List<Long> newIdentityKeys = new ArrayList<>();
    for (Long identityKey : identityKeys) {
        String fullName = userToFullnameCache.get(identityKey);
        if (fullName != null) {
            fullNames.put(identityKey, fullName);
        } else {
            newIdentityKeys.add(identityKey);
        }
    }
    List<IdentityShort> identities = securityManager.loadIdentityShortByKeys(newIdentityKeys);
    for (IdentityShort identity : identities) {
        String fullName = getUserDisplayName(identity);
        updateUsernameCache(identity.getKey(), identity.getName(), fullName);
        fullNames.put(identity.getKey(), fullName);
    }
    return fullNames;
}
Also used : HashMap(java.util.HashMap) IdentityShort(org.olat.basesecurity.IdentityShort) ArrayList(java.util.ArrayList)

Example 29 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project openolat by klemens.

the class UserManagerImpl method warmUp.

@Override
public int warmUp() {
    EntityManager em = dbInstance.getCurrentEntityManager();
    int batchSize = 5000;
    TypedQuery<IdentityShort> query = em.createNamedQuery("selectAllIdentitiesShortUnordered", IdentityShort.class).setMaxResults(batchSize);
    int count = 0;
    List<IdentityShort> identities;
    do {
        identities = query.setFirstResult(count).getResultList();
        em.clear();
        for (IdentityShort identity : identities) {
            if (identity.getStatus() < Identity.STATUS_DELETED) {
                getUserDisplayName(identity);
            }
        }
        count += identities.size();
    } while (identities.size() >= batchSize);
    return count;
}
Also used : EntityManager(javax.persistence.EntityManager) IdentityShort(org.olat.basesecurity.IdentityShort)

Example 30 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project openolat by klemens.

the class UserManagerImpl method getUsername.

@Override
public String getUsername(Long identityKey) {
    if (identityKey == null || identityKey.longValue() <= 0) {
        return null;
    }
    String username = userToNameCache.get(identityKey);
    if (username == null) {
        IdentityShort identity = securityManager.loadIdentityShortByKey(identityKey);
        // fill the cache
        getUserDisplayName(identity);
        username = identity.getName();
    }
    return username;
}
Also used : IdentityShort(org.olat.basesecurity.IdentityShort)

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