Search in sources :

Example 11 with IdentityShort

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

the class SearchControllerFactory method getBusinessPathLabel.

@Override
public String getBusinessPathLabel(String token, List<String> allTokens, Locale locale) {
    try {
        String[] splitted = token.split("[:]");
        if (splitted != null && splitted.length == 2) {
            String tokenType = splitted[0];
            String tokenKey = splitted[1];
            if ("RepositoryEntry".equals(tokenType)) {
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(Long.parseLong(tokenKey));
                return re.getDisplayname();
            }
            if ("CourseNode".equals(tokenType)) {
                String repoKey = allTokens.get(0).split("[:]")[1];
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(Long.parseLong(repoKey));
                if (re != null) {
                    ICourse course = CourseFactory.loadCourse(re);
                    CourseNode courseNode = course.getRunStructure().getNode(tokenKey);
                    return courseNode.getShortTitle();
                }
            }
            if ("Identity".equals(tokenType)) {
                IdentityShort identity = BaseSecurityManager.getInstance().loadIdentityShortByKey(Long.parseLong(tokenKey));
                return UserManager.getInstance().getUserDisplayName(identity);
            }
            if ("BusinessGroup".equals(tokenType)) {
                BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(Long.parseLong(tokenKey));
                return bg == null ? "" : bg.getName();
            }
            if ("Taxonomy".equals(tokenType)) {
                Taxonomy taxonomy = CoreSpringFactory.getImpl(TaxonomyService.class).getTaxonomy(new TaxonomyRefImpl(Long.parseLong(tokenKey)));
                return taxonomy == null ? "" : taxonomy.getDisplayName();
            }
            if ("TaxonomyLevel".equals(tokenType)) {
                TaxonomyLevel level = CoreSpringFactory.getImpl(TaxonomyService.class).getTaxonomyLevel(new TaxonomyLevelRefImpl(Long.parseLong(tokenKey)));
                return level == null ? "" : level.getDisplayName();
            }
            Translator translator = Util.createPackageTranslator(this.getClass(), locale);
            if ("DocumentPool".equals(tokenType)) {
                return translator.translate("DocumentPool");
            }
            if ("Templates".equals(tokenType)) {
                return translator.translate("Templates");
            }
            if ("userfolder".equals(tokenType)) {
                return translator.translate("type.identity.publicfolder");
            }
            String translated = translator.translate(tokenType);
            if (translated == null || translated.length() > 64) {
                // no translation, translator return an error
                return token;
            }
            return translated;
        }
    } catch (Exception ex) {
        log.warn("Problem to decipher business path token: " + token, ex);
    }
    return token;
}
Also used : TaxonomyService(org.olat.modules.taxonomy.TaxonomyService) TaxonomyRefImpl(org.olat.modules.taxonomy.model.TaxonomyRefImpl) BusinessGroup(org.olat.group.BusinessGroup) Taxonomy(org.olat.modules.taxonomy.Taxonomy) IdentityShort(org.olat.basesecurity.IdentityShort) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) BusinessGroupService(org.olat.group.BusinessGroupService) Translator(org.olat.core.gui.translator.Translator) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) CourseNode(org.olat.course.nodes.CourseNode)

Example 12 with IdentityShort

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

the class AssessedIdentityListProvider method getResult.

@Override
public void getResult(String searchValue, ListReceiver receiver) {
    SearchAssessedIdentityParams params = new SearchAssessedIdentityParams(courseEntry, subIdent, referenceEntry, assessmentCallback);
    params.setSearchString(searchValue);
    int maxEntries = MAX_ENTRIES;
    List<IdentityShort> res = assessmentToolManager.getShortAssessedIdentities(coach, params, 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, CSSHelper.CSS_CLASS_USER);
    }
    if (hasMore) {
        receiver.addEntry(".....", ".....");
    }
}
Also used : IdentityShort(org.olat.basesecurity.IdentityShort) SearchAssessedIdentityParams(org.olat.course.assessment.model.SearchAssessedIdentityParams)

Example 13 with IdentityShort

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

the class AssessmentToolManagerTest method assessmentTool_coach.

@Test
public void assessmentTool_coach() {
    // course
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-author-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "course-assessment-tool", "course long name", null);
    // members as participant and coach
    Identity assessedIdentity1 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-1");
    Identity assessedIdentity2 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-2");
    Identity assessedIdentity3 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-3");
    Identity assessedIdentity4 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-4");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-coach-1");
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    RepositoryEntry refEntry = JunitTestHelper.createAndPersistRepositoryEntry();
    String subIdent = UUID.randomUUID().toString();
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "assessment-tool-bg-1", "assessment-tool-bg-1-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group1, entry);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "assessment-tool-bg-2", "assessment-tool-bg-2-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group2, entry);
    businessGroupRelationDao.addRole(assessedIdentity1, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity2, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity3, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(coach, group1, GroupRoles.coach.name());
    dbInstance.commitAndCloseSession();
    // some datas
    assessmentEntryDao.createAssessmentEntry(assessedIdentity1, null, entry, subIdent, refEntry, 3.0f, Boolean.FALSE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity2, null, entry, subIdent, refEntry, 5.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity3, null, entry, subIdent, refEntry, 8.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity4, null, entry, subIdent, refEntry, 9.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(null, UUID.randomUUID().toString(), entry, subIdent, refEntry);
    dbInstance.commitAndCloseSession();
    // coach of group 1 with id 1 and id2
    List<BusinessGroup> coachedGroups = Collections.singletonList(group1);
    AssessmentToolSecurityCallback assessmentCallback = new AssessmentToolSecurityCallback(false, false, false, true, coachedGroups);
    SearchAssessedIdentityParams params = new SearchAssessedIdentityParams(entry, subIdent, refEntry, assessmentCallback);
    // statistics
    AssessmentStatistics statistics = assessmentToolManager.getStatistics(coach, params);
    Assert.assertEquals(4.0d, statistics.getAverageScore().doubleValue(), 0.0001);
    Assert.assertEquals(1, statistics.getCountFailed());
    Assert.assertEquals(1, statistics.getCountPassed());
    // check assessed identities list
    List<Identity> assessedIdentities = assessmentToolManager.getAssessedIdentities(coach, params);
    Assert.assertNotNull(assessedIdentities);
    Assert.assertEquals(2, assessedIdentities.size());
    // number of assessed identities
    int numOfAssessedIdentities = assessmentToolManager.getNumberOfAssessedIdentities(coach, params);
    Assert.assertEquals(2, numOfAssessedIdentities);
    // check only the queries
    AssessmentMembersStatistics participantStatistics = assessmentToolManager.getNumberOfParticipants(coach, params);
    Assert.assertNotNull(participantStatistics);
    int numOfInitialLanches = assessmentToolManager.getNumberOfInitialLaunches(coach, params);
    // not launched, only simulated
    Assert.assertEquals(0, numOfInitialLanches);
    List<IdentityShort> assessedShortIdentities = assessmentToolManager.getShortAssessedIdentities(coach, params, 120);
    Assert.assertNotNull(assessedShortIdentities);
    Assert.assertEquals(2, assessedShortIdentities.size());
    List<AssessmentEntry> assessmentEntries = assessmentToolManager.getAssessmentEntries(coach, params, AssessmentEntryStatus.notStarted);
    Assert.assertNotNull(assessmentEntries);
    Assert.assertEquals(0, assessmentEntries.size());
    // separate check with more options in the search parameters
    // add by group key
    params.setBusinessGroupKeys(Collections.singletonList(group1.getKey()));
    // assessed groups
    List<AssessedBusinessGroup> assessedGroups = assessmentToolManager.getBusinessGroupStatistics(coach, params);
    Assert.assertNotNull(assessedGroups);
    Assert.assertEquals(1, assessedGroups.size());
    // check assessed identities list
    List<Identity> assessedIdentitiesAlt = assessmentToolManager.getAssessedIdentities(coach, params);
    Assert.assertNotNull(assessedIdentitiesAlt);
    Assert.assertEquals(2, assessedIdentitiesAlt.size());
    // number of assessed identities
    int numOfAssessedIdentitiesAlt = assessmentToolManager.getNumberOfAssessedIdentities(coach, params);
    Assert.assertEquals(2, numOfAssessedIdentitiesAlt);
    List<IdentityShort> assessedShortIdentitiesAlt = assessmentToolManager.getShortAssessedIdentities(coach, params, 120);
    Assert.assertNotNull(assessedShortIdentitiesAlt);
    Assert.assertEquals(2, assessedShortIdentitiesAlt.size());
    List<AssessmentEntry> assessmentEntriesAlt = assessmentToolManager.getAssessmentEntries(coach, params, AssessmentEntryStatus.notStarted);
    Assert.assertNotNull(assessmentEntriesAlt);
    Assert.assertEquals(0, assessmentEntriesAlt.size());
}
Also used : AssessmentMembersStatistics(org.olat.modules.assessment.model.AssessmentMembersStatistics) BusinessGroup(org.olat.group.BusinessGroup) AssessedBusinessGroup(org.olat.course.assessment.model.AssessedBusinessGroup) IdentityShort(org.olat.basesecurity.IdentityShort) AssessmentToolSecurityCallback(org.olat.modules.assessment.ui.AssessmentToolSecurityCallback) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) AssessmentStatistics(org.olat.course.assessment.model.AssessmentStatistics) SearchAssessedIdentityParams(org.olat.course.assessment.model.SearchAssessedIdentityParams) AssessedBusinessGroup(org.olat.course.assessment.model.AssessedBusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 14 with IdentityShort

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

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 15 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)

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