Skip to content
Snippets Groups Projects
Commit 16185d9f authored by uhensler's avatar uhensler
Browse files

OO-3304: White list for course lecture generator provider

parent ea6c4667
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@ import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.StringHelper;
import org.olat.core.util.Util;
import org.olat.modules.curriculum.CurriculumElementRef;
import org.olat.modules.forms.EvaluationFormParticipation;
import org.olat.modules.quality.QualityDataCollection;
import org.olat.modules.quality.QualityDataCollectionStatus;
......@@ -57,6 +58,7 @@ import org.olat.modules.quality.generator.provider.courselectures.manager.Lectur
import org.olat.modules.quality.generator.provider.courselectures.manager.SearchParameters;
import org.olat.modules.quality.generator.provider.courselectures.ui.CourseLectureProviderConfigController;
import org.olat.modules.quality.generator.ui.AbstractGeneratorEditController;
import org.olat.modules.quality.generator.ui.CurriculumElementWhiteListController;
import org.olat.modules.quality.generator.ui.ProviderConfigController;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryEntryRelationType;
......@@ -123,23 +125,21 @@ public class CourseLecturesProvider implements QualityGeneratorProvider {
List<Organisation> organisations = generatorService.loadGeneratorOrganisations(generator);
SearchParameters searchParams = getSeachParameters(generator, configs, organisations, fromDate, toDate);
List<LectureBlockInfo> infos = providerDao.loadLectureBlockInfo(searchParams);
Long count = providerDao.loadLectureBlockCount(searchParams);
return translator.translate("generate.info", new String[] { String.valueOf(infos.size())});
return translator.translate("generate.info", new String[] { String.valueOf(count)});
}
@Override
public boolean hasWhiteListController() {
//TODO uh
return false;
return true;
}
@Override
public AbstractGeneratorEditController getWhiteListController(UserRequest ureq, WindowControl wControl,
QualitySecurityCallback secCallback, TooledStackedPanel stackPanel, QualityGenerator generator,
QualityGeneratorConfigs configs) {
//TODO uh
return null;
return new CurriculumElementWhiteListController(ureq, wControl, secCallback, stackPanel, generator, configs);
}
@Override
......@@ -227,6 +227,8 @@ public class CourseLecturesProvider implements QualityGeneratorProvider {
searchParams.setOrgansationRefs(organisations);
searchParams.setFrom(fromDate);
searchParams.setTo(toDate);
Collection<CurriculumElementRef> curriculumElementRefs = CurriculumElementWhiteListController.getCurriculumElementRefs(configs);
searchParams.setCurriculumElementRefs(curriculumElementRefs);
Integer minExceedingLectures = Integer.parseInt(configs.getValue(CONFIG_KEY_TOTAL_LECTURES));
searchParams.setMinTotalLectures(minExceedingLectures);
Integer selectingLecture = Integer.parseInt(configs.getValue(CONFIG_KEY_SURVEY_LECTURE));
......
......@@ -31,7 +31,9 @@ import javax.persistence.TypedQuery;
import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.persistence.QueryBuilder;
import org.olat.core.id.OrganisationRef;
import org.olat.modules.curriculum.CurriculumElementRef;
import org.olat.repository.RepositoryEntryRef;
import org.olat.repository.RepositoryEntryStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -68,7 +70,7 @@ public class CourseLecturesProviderDAO {
return count.longValueExact();
}
public Long loadLectureBlockCountHql(SearchParameters searchParams) {
private Long loadLectureBlockCountHql(SearchParameters searchParams) {
return new Long(loadLectureBlockInfoHql(searchParams).size());
}
......@@ -143,11 +145,23 @@ public class CourseLecturesProviderDAO {
sb.append(" where ro.fk_organisation in :organisationKeys");
sb.append(" and ro.fk_entry = lb.fk_entry");
sb.append(" )");
}
if (!searchParams.getCourseRefs().isEmpty()) {
sb.and().append("lb.fk_entry in :courseKeys");
}
if (!searchParams.getCurriculumElementRefs().isEmpty()) {
sb.and();
sb.append("lb.fk_entry in (");
sb.append(" select distinct v.repositoryentry_id");
sb.append(" from o_repositoryentry v");
sb.append(" inner join o_re_to_group rel");
sb.append(" on rel.fk_entry_id = v.repositoryentry_id");
sb.append(" inner join o_cur_curriculum_element el");
sb.append(" on el.fk_group = rel.fk_group_id");
sb.append(" where el.id in :curriculumElementKeys");
sb.append(" and v.status ").in(RepositoryEntryStatusEnum.preparationToPublished());
sb.append(" )");
}
if (searchParams.getExcludeGeneratorRef() != null) {
sb.and().append("(tm.fk_identity_id, lb.fk_entry) not in (");
sb.append(" select dc.q_topic_fk_identity, dc.q_generator_provider_key");
......@@ -280,6 +294,17 @@ public class CourseLecturesProviderDAO {
if (!searchParams.getCourseRefs().isEmpty()) {
sb.and().append("course.key in :courseKeys");
}
if (!searchParams.getCurriculumElementRefs().isEmpty()) {
sb.and();
sb.append("course.key in (");
sb.append(" select distinct v.key");
sb.append(" from repositoryentry as v");
sb.append(" inner join v.groups as rel");
sb.append(" inner join curriculumelement as el on (el.group.key=rel.group.key)");
sb.append(" where el.key in :curriculumElementKeys");
sb.append(" and v.status ").in(RepositoryEntryStatusEnum.preparationToPublished());
sb.append(" )");
}
if (!searchParams.getOrgansationRefs().isEmpty()) {
sb.and();
sb.append("course.key in (");
......@@ -307,6 +332,10 @@ public class CourseLecturesProviderDAO {
List<Long> courseKeys = searchParams.getCourseRefs().stream().map(RepositoryEntryRef::getKey).collect(Collectors.toList());
query.setParameter("courseKeys", courseKeys);
}
if (!searchParams.getCurriculumElementRefs().isEmpty()) {
List<Long> curriculumElementKeys = searchParams.getCurriculumElementRefs().stream().map(CurriculumElementRef::getKey).collect(Collectors.toList());
query.setParameter("curriculumElementKeys", curriculumElementKeys);
}
if (!searchParams.getOrgansationRefs().isEmpty()) {
List<Long> organisationKeys = searchParams.getOrgansationRefs().stream().map(OrganisationRef::getKey).collect(Collectors.toList());
query.setParameter("organisationKeys", organisationKeys);
......
......@@ -25,6 +25,7 @@ import java.util.Date;
import org.olat.basesecurity.IdentityRef;
import org.olat.core.id.OrganisationRef;
import org.olat.modules.curriculum.CurriculumElementRef;
import org.olat.modules.quality.generator.QualityGeneratorRef;
import org.olat.repository.RepositoryEntryRef;
......@@ -41,6 +42,7 @@ public class SearchParameters {
private QualityGeneratorRef excludeGeneratorRef;
private IdentityRef teacherRef;
private Collection<? extends RepositoryEntryRef> courseRefs;
private Collection<? extends CurriculumElementRef> curriculumElementRefs;
private Collection<? extends OrganisationRef> organsationRefs;
private Date from;
private Date to;
......@@ -88,6 +90,17 @@ public class SearchParameters {
this.courseRefs = courseRefs;
}
public Collection<? extends CurriculumElementRef> getCurriculumElementRefs() {
if (curriculumElementRefs == null) {
curriculumElementRefs = Collections.emptyList();
}
return curriculumElementRefs;
}
public void setCurriculumElementRefs(Collection<? extends CurriculumElementRef> curriculumElementRefs) {
this.curriculumElementRefs = curriculumElementRefs;
}
public Collection<? extends OrganisationRef> getOrgansationRefs() {
if (organsationRefs == null) {
organsationRefs = Collections.emptyList();
......
......@@ -148,9 +148,9 @@ public class CurriculumElementProvider implements QualityGeneratorProvider {
@Override
public AbstractGeneratorEditController getWhiteListController(UserRequest ureq, WindowControl wControl,
QualitySecurityCallback secCallback, TooledStackedPanel stackPanel, QualityGenerator gnerator,
QualitySecurityCallback secCallback, TooledStackedPanel stackPanel, QualityGenerator generator,
QualityGeneratorConfigs configs) {
return new CurriculumElementWhiteListController(ureq, wControl, secCallback, stackPanel, gnerator, configs);
return new CurriculumElementWhiteListController(ureq, wControl, secCallback, stackPanel, generator, configs);
}
@Override
......
......@@ -34,6 +34,9 @@ import org.olat.basesecurity.OrganisationService;
import org.olat.core.commons.persistence.DB;
import org.olat.core.id.Identity;
import org.olat.core.id.Organisation;
import org.olat.modules.curriculum.Curriculum;
import org.olat.modules.curriculum.CurriculumElement;
import org.olat.modules.curriculum.CurriculumService;
import org.olat.modules.lecture.LectureBlock;
import org.olat.modules.lecture.LectureBlockStatus;
import org.olat.modules.lecture.LectureRollCallStatus;
......@@ -71,6 +74,8 @@ public class CourseLecturesProviderDAOTest extends OlatTestCase {
private QualityGeneratorService generatorService;
@Autowired
private QualityService qualityService;
@Autowired
private CurriculumService curriculumService;
@Autowired
private CourseLecturesProviderDAO sut;
......@@ -192,6 +197,36 @@ public class CourseLecturesProviderDAOTest extends OlatTestCase {
.doesNotContain(otherCourse.getKey());
}
@Test
public void shouldFilterLectureBlockInfosByCurriculumElements() {
Identity teacher = JunitTestHelper.createAndPersistIdentityAsRndUser("");
Organisation organisation = organisationService.createOrganisation("", "", null, null, null);
Curriculum curriculum = curriculumService.createCurriculum("", "", null, organisation);
CurriculumElement element = curriculumService.createCurriculumElement("", "", null, null, null, null, curriculum);
CurriculumElement otherElement = curriculumService.createCurriculumElement("", "", null, null, null, null, curriculum);
RepositoryEntry course1 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry course2 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry otherCourse = JunitTestHelper.createAndPersistRepositoryEntry();
createLectureBlock(course1, teacher, 1);
createLectureBlock(course2, teacher, 1);
createLectureBlock(otherCourse, teacher, 1);
curriculumService.addRepositoryEntry(element, course1, false);
curriculumService.addRepositoryEntry(element, course2, false);
curriculumService.addRepositoryEntry(otherElement, otherCourse, false);
dbInstance.commitAndCloseSession();
SearchParameters searchParams = new SearchParameters();
searchParams.setTeacherRef(teacher);
searchParams.setCurriculumElementRefs(Arrays.asList(element));
List<LectureBlockInfo> infos = sut.loadLectureBlockInfo(searchParams);
List<Long> courseKeys = infos.stream().map(LectureBlockInfo::getCourseRepoKey).collect(Collectors.toList());
assertThat(courseKeys)
.containsExactlyInAnyOrder(course1.getKey(), course2.getKey())
.doesNotContain(otherCourse.getKey());
}
@Test
public void shouldFilterLectureBlockInfosByEndDate() {
Identity teacher = JunitTestHelper.createAndPersistIdentityAsRndUser("");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment