Search in sources :

Example 26 with IdentityRef

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

the class GTACourseNode method validateInternalConfiguration.

private List<StatusDescription> validateInternalConfiguration(CourseEditorEnv cev) {
    List<StatusDescription> sdList = new ArrayList<>(5);
    ModuleConfiguration config = getModuleConfiguration();
    boolean hasScoring = config.getBooleanSafe(GTASK_GRADING);
    if (hasScoring) {
        if (!config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_PASSED_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_COMMENT_FIELD)) {
            addStatusErrorDescription("error.missing.score.config", GTAEditController.PANE_TAB_GRADING, sdList);
        }
    }
    if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
        List<Long> groupKeys = config.getList(GTACourseNode.GTASK_GROUPS, Long.class);
        List<Long> areaKeys = config.getList(GTACourseNode.GTASK_AREAS, Long.class);
        if (groupKeys.isEmpty() && areaKeys.isEmpty()) {
            addStatusErrorDescription("error.missing.group", GTAEditController.PANE_TAB_GRADING, sdList);
        }
    }
    // at least one step
    if (!config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT) && !config.getBooleanSafe(GTACourseNode.GTASK_SUBMIT) && !config.getBooleanSafe(GTACourseNode.GTASK_REVIEW_AND_CORRECTION) && !config.getBooleanSafe(GTACourseNode.GTASK_REVISION_PERIOD) && !config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION) && !config.getBooleanSafe(GTACourseNode.GTASK_GRADING)) {
        addStatusErrorDescription("error.select.atleastonestep", GTAEditController.PANE_TAB_WORKLOW, sdList);
    }
    if (cev != null) {
        // check assignment
        GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
        RepositoryEntry courseRe = cev.getCourseGroupManager().getCourseEntry();
        ICourse course = CourseFactory.loadCourse(courseRe);
        if (config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT)) {
            File taskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
            if (!TaskHelper.hasDocuments(taskDirectory)) {
                if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                    addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                } else {
                    addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                }
            } else {
                List<TaskDefinition> taskList = gtaManager.getTaskDefinitions(course.getCourseEnvironment(), this);
                if (taskList == null || taskList.isEmpty()) {
                    if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                        addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                    } else {
                        addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                    }
                } else {
                    String[] filenames = taskDirectory.list();
                    for (TaskDefinition taskDef : taskList) {
                        boolean found = false;
                        for (String filename : filenames) {
                            if (filename.equals(taskDef.getFilename())) {
                                found = true;
                                break;
                            }
                        }
                        if (!found) {
                            addStatusWarningDescription("error.missing.file", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                        }
                    }
                }
            }
        }
        // check solutions
        if (config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION)) {
            File solutionDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), this);
            if (!TaskHelper.hasDocuments(solutionDirectory)) {
                if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                    addStatusWarningDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
                } else {
                    addStatusErrorDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
                }
            }
        }
        List<IdentityRef> participants = gtaManager.getDuplicatedMemberships(this);
        if (participants.size() > 0) {
            UserManager um = CoreSpringFactory.getImpl(UserManager.class);
            StringBuilder sb = new StringBuilder();
            for (IdentityRef participant : participants) {
                String fullname = um.getUserDisplayName(participant.getKey());
                if (sb.length() > 0)
                    sb.append(", ");
                sb.append(fullname);
            }
            String[] params = new String[] { getShortTitle(), sb.toString() };
            StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.duplicate.memberships", "error.duplicate.memberships", params, PACKAGE_GTA);
            sd.setDescriptionForUnit(getIdent());
            sd.setActivateableViewIdentifier(GTAEditController.PANE_TAB_WORKLOW);
            sdList.add(sd);
        }
    }
    return sdList;
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition) StatusDescription(org.olat.course.editor.StatusDescription) UserManager(org.olat.user.UserManager) IdentityRef(org.olat.basesecurity.IdentityRef) GTAManager(org.olat.course.nodes.gta.GTAManager) File(java.io.File)

Example 27 with IdentityRef

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

the class RepositoryEntryAuthorQueries method createViewQuery.

protected <T> TypedQuery<T> createViewQuery(SearchAuthorRepositoryEntryViewParams params, Class<T> type) {
    IdentityRef identity = params.getIdentity();
    Roles roles = params.getRoles();
    List<String> resourceTypes = params.getResourceTypes();
    boolean oracle = "oracle".equals(dbInstance.getDbVendor());
    boolean admin = (roles != null && (roles.isInstitutionalResourceManager() || roles.isOLATAdmin()));
    boolean count = Number.class.equals(type);
    boolean needIdentity = false;
    StringBuilder sb = new StringBuilder();
    if (count) {
        sb.append("select count(v.key) ").append(" from repositoryentry as v").append(" inner join v.olatResource as res").append(" left join v.lifecycle as lifecycle");
    } else {
        sb.append("select v, ");
        if (params.getMarked() != null && params.getMarked().booleanValue()) {
            sb.append(" 1 as marks,");
        } else {
            sb.append(" (select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark ").append("   where mark.creator.key=:identityKey and mark.resId=v.key and mark.resName='RepositoryEntry'").append(" ) as marks,");
            needIdentity = true;
        }
        sb.append(" (select count(offer.key) from acoffer as offer ").append("   where offer.resource.key=res.key and offer.valid=true").append(" ) as offers,").append(" (select count(ref.key) from references as ref ").append("   where ref.target.key=res.key").append(" ) as references").append(" from repositoryentry as v").append(" inner join ").append(oracle ? "" : "fetch").append(" v.olatResource as res").append(" inner join fetch v.statistics as stats").append(" left join fetch v.lifecycle as lifecycle ");
        if (params.isDeleted()) {
            sb.append(" left join fetch v.deletedBy as deletedBy").append(" left join fetch deletedBy.user as deletedByUser");
        }
    }
    sb.append(" where");
    if (params.isOwnedResourcesOnly()) {
        needIdentity = true;
        sb.append(" v.key in (select rel.entry.key from repoentrytogroup as rel, bgroupmember as membership").append("    where rel.group.key=membership.group.key and membership.identity.key=:identityKey").append("      and membership.role='").append(GroupRoles.owner.name()).append("'").append(" )");
        if (params.isDeleted()) {
            sb.append(" and v.access=").append(RepositoryEntry.DELETED);
        } else {
            sb.append(" and v.access>=").append(RepositoryEntry.ACC_OWNERS);
        }
    } else if (admin) {
        if (params.isDeleted()) {
            sb.append(" v.access=").append(RepositoryEntry.DELETED);
        } else {
            sb.append(" v.access>=").append(RepositoryEntry.ACC_OWNERS);
        }
    } else {
        needIdentity = true;
        sb.append(" (v.access>=").append(RepositoryEntry.ACC_OWNERS_AUTHORS).append(" or (v.access=").append(RepositoryEntry.ACC_OWNERS).append("   and v.key in (select rel.entry.key from repoentrytogroup as rel, bgroupmember as membership").append("     where rel.group.key=membership.group.key and membership.identity.key=:identityKey").append("       and membership.role='").append(GroupRoles.owner.name()).append("'").append("   )").append(" ))");
    }
    if (params.getClosed() != null) {
        if (params.getClosed().booleanValue()) {
            sb.append(" and v.statusCode>0");
        } else {
            sb.append(" and v.statusCode=0");
        }
    }
    if (params.getResourceUsage() != null && params.getResourceUsage() != ResourceUsage.all) {
        sb.append(" and res.resName!='CourseModule' and");
        if (params.getResourceUsage() == ResourceUsage.notUsed) {
            sb.append(" not");
        }
        sb.append(" exists (select ref.key from references as ref where ref.target.key=res.key)");
    }
    if (params.getRepoEntryKeys() != null && params.getRepoEntryKeys().size() > 0) {
        sb.append(" and v.key in (:repoEntryKeys)");
    }
    if (params.isResourceTypesDefined()) {
        sb.append(" and res.resName in (:resourcetypes)");
    }
    if (params.getMarked() != null && params.getMarked().booleanValue()) {
        needIdentity = true;
        sb.append(" and exists (select mark2.key from ").append(MarkImpl.class.getName()).append(" as mark2 ").append("   where mark2.creator.key=:identityKey and mark2.resId=v.key and mark2.resName='RepositoryEntry'").append(" )");
    }
    if (params.isLicenseTypeDefined()) {
        sb.append(" and exists (");
        sb.append(" select license.key from license as license");
        sb.append("  where license.resId=res.resId and license.resName=res.resName");
        sb.append("    and license.licenseType.key in (:licenseTypeKeys))");
    }
    String author = params.getAuthor();
    if (StringHelper.containsNonWhitespace(author)) {
        // fuzzy author search
        author = PersistenceHelper.makeFuzzyQueryString(author);
        sb.append(" and v.key in (select rel.entry.key from repoentrytogroup as rel, bgroupmember as membership, ").append(IdentityImpl.class.getName()).append(" as identity, ").append(UserImpl.class.getName()).append(" as user").append("    where rel.group.key=membership.group.key and membership.identity.key=identity.key and user.identity.key=identity.key").append("      and membership.role='").append(GroupRoles.owner.name()).append("'").append("      and (");
        PersistenceHelper.appendFuzzyLike(sb, "user.firstName", "author", dbInstance.getDbVendor());
        sb.append(" or ");
        PersistenceHelper.appendFuzzyLike(sb, "user.lastName", "author", dbInstance.getDbVendor());
        sb.append(" or ");
        PersistenceHelper.appendFuzzyLike(sb, "identity.name", "author", dbInstance.getDbVendor());
        sb.append(" ))");
    }
    String displayname = params.getDisplayname();
    if (StringHelper.containsNonWhitespace(displayname)) {
        // displayName = '%' + displayName.replace('*', '%') + '%';
        // query.append(" and v.displayname like :displayname");
        displayname = PersistenceHelper.makeFuzzyQueryString(displayname);
        sb.append(" and ");
        PersistenceHelper.appendFuzzyLike(sb, "v.displayname", "displayname", dbInstance.getDbVendor());
    }
    String desc = params.getDescription();
    if (StringHelper.containsNonWhitespace(desc)) {
        // desc = '%' + desc.replace('*', '%') + '%';
        // query.append(" and v.description like :desc");
        desc = PersistenceHelper.makeFuzzyQueryString(desc);
        sb.append(" and ");
        PersistenceHelper.appendFuzzyLike(sb, "v.description", "desc", dbInstance.getDbVendor());
    }
    Long id = null;
    String refs = null;
    String fuzzyRefs = null;
    if (StringHelper.containsNonWhitespace(params.getIdAndRefs())) {
        refs = params.getIdAndRefs();
        fuzzyRefs = PersistenceHelper.makeFuzzyQueryString(refs);
        sb.append(" and (v.externalId=:ref or ");
        PersistenceHelper.appendFuzzyLike(sb, "v.externalRef", "fuzzyRefs", dbInstance.getDbVendor());
        sb.append(" or v.softkey=:ref");
        if (StringHelper.isLong(refs)) {
            try {
                id = Long.parseLong(refs);
                sb.append(" or v.key=:vKey or res.resId=:vKey");
            } catch (NumberFormatException e) {
            // 
            }
        }
        sb.append(")");
    }
    // quick search
    Long quickId = null;
    String quickRefs = null;
    String quickText = null;
    if (StringHelper.containsNonWhitespace(params.getIdRefsAndTitle())) {
        quickRefs = params.getIdRefsAndTitle();
        sb.append(" and (v.externalId=:quickRef or ");
        PersistenceHelper.appendFuzzyLike(sb, "v.externalRef", "quickText", dbInstance.getDbVendor());
        sb.append(" or v.softkey=:quickRef or ");
        quickText = PersistenceHelper.makeFuzzyQueryString(quickRefs);
        PersistenceHelper.appendFuzzyLike(sb, "v.displayname", "quickText", dbInstance.getDbVendor());
        if (StringHelper.isLong(quickRefs)) {
            try {
                quickId = Long.parseLong(quickRefs);
                sb.append(" or v.key=:quickVKey or res.resId=:quickVKey");
            } catch (NumberFormatException e) {
            // 
            }
        }
        sb.append(")");
    }
    if (!count) {
        appendAuthorViewOrderBy(params, sb);
    }
    TypedQuery<T> dbQuery = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), type);
    if (params.getRepoEntryKeys() != null && params.getRepoEntryKeys().size() > 0) {
        dbQuery.setParameter("repoEntryKeys", params.getRepoEntryKeys());
    }
    if (params.isResourceTypesDefined()) {
        dbQuery.setParameter("resourcetypes", resourceTypes);
    }
    if (id != null) {
        dbQuery.setParameter("vKey", id);
    }
    if (refs != null) {
        dbQuery.setParameter("ref", refs);
    }
    if (fuzzyRefs != null) {
        dbQuery.setParameter("fuzzyRefs", fuzzyRefs);
    }
    if (quickId != null) {
        dbQuery.setParameter("quickVKey", quickId);
    }
    if (quickRefs != null) {
        dbQuery.setParameter("quickRef", quickRefs);
    }
    if (quickText != null) {
        dbQuery.setParameter("quickText", quickText);
    }
    if (StringHelper.containsNonWhitespace(author)) {
        // fuzzy author search
        dbQuery.setParameter("author", author);
    }
    if (StringHelper.containsNonWhitespace(displayname)) {
        dbQuery.setParameter("displayname", displayname);
    }
    if (StringHelper.containsNonWhitespace(desc)) {
        dbQuery.setParameter("desc", desc);
    }
    if (needIdentity) {
        dbQuery.setParameter("identityKey", identity.getKey());
    }
    if (params.isLicenseTypeDefined()) {
        dbQuery.setParameter("licenseTypeKeys", params.getLicenseTypeKeys());
    }
    return dbQuery;
}
Also used : IdentityRef(org.olat.basesecurity.IdentityRef) UserImpl(org.olat.user.UserImpl) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) IdentityImpl(org.olat.basesecurity.IdentityImpl)

Example 28 with IdentityRef

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

the class BusinessGroupRelationDAOTest method getDuplicateMemberships.

@Test
public void getDuplicateMemberships() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("wait-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("wait-1");
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "to-group-1", "to-group-1-desc", -1, -1, false, false, false, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "to-group-2", "to-group-2-desc", -1, -1, false, false, false, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(null, "to-group-2", "to-group-2-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(id1, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id1, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, group3, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // id1 is a duplicate
    List<BusinessGroup> groups = new ArrayList<>(2);
    groups.add(group1);
    groups.add(group2);
    groups.add(group3);
    List<IdentityRef> duplicates = businessGroupRelationDao.getDuplicateMemberships(groups);
    Assert.assertNotNull(duplicates);
    Assert.assertEquals(1, duplicates.size());
    Assert.assertEquals(id1.getKey(), duplicates.get(0).getKey());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) IdentityRef(org.olat.basesecurity.IdentityRef) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 29 with IdentityRef

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

the class IQIdentityListCourseNodeController method doConfirmExtraTime.

private void doConfirmExtraTime(UserRequest ureq) {
    List<IdentityRef> identities = getSelectedIdentities();
    if (identities == null || identities.isEmpty()) {
        showWarning("warning.users.extra.time");
        return;
    }
    List<AssessmentTestSession> testSessions = new ArrayList<>(identities.size());
    for (IdentityRef identity : identities) {
        List<AssessmentTestSessionStatistics> sessionsStatistics = qtiService.getAssessmentTestSessionsStatistics(getCourseRepositoryEntry(), courseNode.getIdent(), identity);
        if (!sessionsStatistics.isEmpty()) {
            if (sessionsStatistics.size() > 1) {
                Collections.sort(sessionsStatistics, new AssessmentTestSessionDetailsComparator());
            }
            AssessmentTestSession lastSession = sessionsStatistics.get(0).getTestSession();
            if (lastSession != null && lastSession.getFinishTime() == null) {
                testSessions.add(lastSession);
            }
        }
    }
    if (testSessions == null || testSessions.isEmpty()) {
        showWarning("warning.users.extra.time");
        return;
    }
    extraTimeCtrl = new ConfirmExtraTimeController(ureq, getWindowControl(), getCourseRepositoryEntry(), testSessions);
    listenTo(extraTimeCtrl);
    String title = translate("extra.time");
    cmc = new CloseableModalController(getWindowControl(), null, extraTimeCtrl.getInitialComponent(), true, title, true);
    listenTo(cmc);
    cmc.activate();
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) AssessmentTestSessionDetailsComparator(org.olat.course.nodes.iq.QTI21IdentityListCourseNodeToolsController.AssessmentTestSessionDetailsComparator) AssessmentTestSessionStatistics(org.olat.ims.qti21.model.jpa.AssessmentTestSessionStatistics) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) IdentityRef(org.olat.basesecurity.IdentityRef) ArrayList(java.util.ArrayList)

Example 30 with IdentityRef

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

the class DownloadCertificateCellRenderer method render.

@Override
public void render(Renderer renderer, StringOutput target, Object cellValue, int row, FlexiTableComponent source, URLBuilder ubu, Translator translator) {
    if (renderer == null) {
        if (cellValue instanceof CertificateLight) {
            renderExcel(target, (CertificateLight) cellValue);
        } else if (cellValue instanceof CertificateLightPack) {
            CertificateLightPack pack = (CertificateLightPack) cellValue;
            renderExcel(target, pack.getCertificate());
        }
    } else if (cellValue instanceof CertificateLight) {
        CertificateLight certificate = (CertificateLight) cellValue;
        if (assessedIdentity == null) {
            IdentityRef idRef = new IdentityRefImpl(certificate.getIdentityKey());
            render(target, certificate, idRef, translator.getLocale());
        } else {
            render(target, certificate, assessedIdentity, translator.getLocale());
        }
    } else if (cellValue instanceof CertificateLightPack) {
        CertificateLightPack pack = (CertificateLightPack) cellValue;
        render(target, pack.getCertificate(), pack.getIdentity(), translator.getLocale());
    }
}
Also used : IdentityRefImpl(org.olat.basesecurity.model.IdentityRefImpl) CertificateLightPack(org.olat.course.certificate.model.CertificateLightPack) IdentityRef(org.olat.basesecurity.IdentityRef) CertificateLight(org.olat.course.certificate.CertificateLight)

Aggregations

IdentityRef (org.olat.basesecurity.IdentityRef)36 ArrayList (java.util.ArrayList)18 IdentityRefImpl (org.olat.basesecurity.model.IdentityRefImpl)18 Identity (org.olat.core.id.Identity)8 BusinessGroupRef (org.olat.group.BusinessGroupRef)8 LDAPUser (org.olat.ldap.model.LDAPUser)8 RepositoryEntryRef (org.olat.repository.RepositoryEntryRef)6 RepositoryEntryRefImpl (org.olat.repository.model.RepositoryEntryRefImpl)6 OLATResource (org.olat.resource.OLATResource)6 HashMap (java.util.HashMap)4 AuthenticationException (javax.naming.AuthenticationException)4 NamingException (javax.naming.NamingException)4 Attributes (javax.naming.directory.Attributes)4 GroupRoles (org.olat.basesecurity.GroupRoles)4 Roles (org.olat.core.id.Roles)4 BusinessGroupRefImpl (org.olat.group.model.BusinessGroupRefImpl)4 ModuleConfiguration (org.olat.modules.ModuleConfiguration)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)3 File (java.io.File)2