Search in sources :

Example 1 with IdentityShort

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

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)

Example 2 with IdentityShort

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

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 3 with IdentityShort

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

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 4 with IdentityShort

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

the class UserSearchListProvider method getResult.

@Override
public void getResult(String searchValue, ListReceiver receiver) {
    Map<String, String> userProperties = new HashMap<>();
    // We can only search in mandatory User-Properties due to problems
    // with hibernate query with join and not existing rows
    userProperties.put(UserConstants.FIRSTNAME, searchValue);
    userProperties.put(UserConstants.LASTNAME, searchValue);
    userProperties.put(UserConstants.EMAIL, searchValue);
    // Search in all fileds -> non intersection search
    int maxEntries = MAX_ENTRIES;
    List<IdentityShort> res = securityManager.searchIdentityShort(searchValue, maxEntries);
    boolean hasMore = false;
    for (Iterator<IdentityShort> it_res = res.iterator(); (hasMore = it_res.hasNext()) && maxEntries > 0; ) {
        maxEntries--;
        IdentityShort ident = it_res.next();
        String key = ident.getKey().toString();
        String displayKey = ident.getName();
        String displayText = userManager.getUserDisplayName(ident);
        receiver.addEntry(key, displayKey, displayText, null);
    }
    if (hasMore) {
        receiver.addEntry(".....", ".....");
    }
}
Also used : HashMap(java.util.HashMap) IdentityShort(org.olat.basesecurity.IdentityShort)

Example 5 with IdentityShort

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

the class RevisionListController method loadModel.

private void loadModel(VFSLeaf versionedLeaf) {
    Versions versions = versionedFile.getVersions();
    List<VFSRevision> revisions = new ArrayList<VFSRevision>(versions.getRevisions());
    revisions.add(new CurrentRevision(versionedLeaf, versions));
    Collection<String> names = new HashSet<String>();
    for (VFSRevision revision : revisions) {
        if (revision.getAuthor() != null) {
            names.add(revision.getAuthor());
        }
    }
    Map<String, IdentityShort> mappedIdentities = new HashMap<String, IdentityShort>();
    for (IdentityShort identity : BaseSecurityManager.getInstance().findShortIdentitiesByName(names)) {
        mappedIdentities.put(identity.getName(), identity);
    }
    revisionListTableCtr.setTableDataModel(new RevisionListDataModel(revisions, mappedIdentities, getLocale()));
}
Also used : Versions(org.olat.core.util.vfs.version.Versions) HashMap(java.util.HashMap) VFSRevision(org.olat.core.util.vfs.version.VFSRevision) IdentityShort(org.olat.basesecurity.IdentityShort) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

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