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);
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations