From d0ee9ddd442c5a6e380bdbc3c8e8866122ea853d Mon Sep 17 00:00:00 2001 From: uhensler <urs.hensler@frentix.com> Date: Wed, 10 Oct 2018 11:31:30 +0200 Subject: [PATCH] OO-3304: Quality generator for curriculum elements should generate data collection right before its start date. Refactorings. --- .../model/CurriculumElementRefImpl.java | 9 ++ .../provider/course/CourseProvider.java | 2 +- .../course/manager/SearchParameters.java | 3 +- .../CurriculumElementProvider.java | 97 ++++++++------ .../manager/CurriculumElementProviderDAO.java | 120 +++++++++--------- .../manager/SearchParameters.java | 47 ++++--- .../CurriculumElementProviderDAOTest.java | 107 +++++----------- 7 files changed, 186 insertions(+), 199 deletions(-) diff --git a/src/main/java/org/olat/modules/curriculum/model/CurriculumElementRefImpl.java b/src/main/java/org/olat/modules/curriculum/model/CurriculumElementRefImpl.java index dd417f235c9..1e645b2257e 100644 --- a/src/main/java/org/olat/modules/curriculum/model/CurriculumElementRefImpl.java +++ b/src/main/java/org/olat/modules/curriculum/model/CurriculumElementRefImpl.java @@ -39,4 +39,13 @@ public class CurriculumElementRefImpl implements CurriculumElementRef { public Long getKey() { return key; } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CurriculumElementRefImpl [key="); + builder.append(key); + builder.append("]"); + return builder.toString(); + } } diff --git a/src/main/java/org/olat/modules/quality/generator/provider/course/CourseProvider.java b/src/main/java/org/olat/modules/quality/generator/provider/course/CourseProvider.java index 691483ddee2..928cce36a98 100644 --- a/src/main/java/org/olat/modules/quality/generator/provider/course/CourseProvider.java +++ b/src/main/java/org/olat/modules/quality/generator/provider/course/CourseProvider.java @@ -150,7 +150,7 @@ public class CourseProvider implements QualityGeneratorProvider { } if (!courses.isEmpty()) { - log.debug(courses + " data collections created by generator " + generator.toString()); + log.info(courses + " data collections created by generator " + generator.toString()); } } diff --git a/src/main/java/org/olat/modules/quality/generator/provider/course/manager/SearchParameters.java b/src/main/java/org/olat/modules/quality/generator/provider/course/manager/SearchParameters.java index 90b2836631f..fa58f775023 100644 --- a/src/main/java/org/olat/modules/quality/generator/provider/course/manager/SearchParameters.java +++ b/src/main/java/org/olat/modules/quality/generator/provider/course/manager/SearchParameters.java @@ -103,11 +103,12 @@ public class SearchParameters { StringBuilder builder = new StringBuilder(); builder.append("SearchParameters [generatorRef="); builder.append(generatorRef); - builder.append(", organisationRefs (keys)="); + builder.append(", organisationRefs (keys)=["); builder.append(organisationRefs.stream() .map(OrganisationRef::getKey) .map(k -> k.toString()) .collect(Collectors.joining(", "))); + builder.append("]"); builder.append(", beginFrom="); builder.append(beginFrom); builder.append(", beginTo="); diff --git a/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/CurriculumElementProvider.java b/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/CurriculumElementProvider.java index cf4ab19400e..ba5eec3631d 100644 --- a/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/CurriculumElementProvider.java +++ b/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/CurriculumElementProvider.java @@ -122,23 +122,9 @@ public class CurriculumElementProvider implements QualityGeneratorProvider { Translator translator = Util.createPackageTranslator(CurriculumElementProviderConfigController.class, locale); List<Organisation> organisations = generatorService.loadGeneratorOrganisations(generator); - String ceTypeKeyString = configs.getValue(CONFIG_KEY_CURRICULUM_ELEMENT_TYPE); - Long ceTypeKey = Long.valueOf(ceTypeKeyString); - SearchParameters searchParams = new SearchParameters(generator, organisations, ceTypeKey, fromDate, toDate); - List<CurriculumElementRef> curriculumElementRefs = CurriculumElementWhiteListController.getCurriculumElementRefs(configs); - searchParams.setCurriculumElementRefs(curriculumElementRefs); - - Long count = 0l; - String dueDateType = configs.getValue(CONFIG_KEY_DUE_DATE_TYPE); - if (CONFIG_KEY_DUE_DATE_BEGIN.equals(dueDateType)) { - searchParams.setStartDate(true); - count = providerDao.loadPendingCount(searchParams); - } else if (CONFIG_KEY_DUE_DATE_END.equals(dueDateType)) { - searchParams.setStartDate(false); - count = providerDao.loadPendingCount(searchParams); - } + List<CurriculumElement> elements = loadCurriculumElements(generator, configs, fromDate, toDate, organisations); - return translator.translate("generate.info", new String[] { String.valueOf(count)}); + return translator.translate("generate.info", new String[] { String.valueOf( elements.size() )}); } @Override @@ -155,44 +141,31 @@ public class CurriculumElementProvider implements QualityGeneratorProvider { @Override public void generate(QualityGenerator generator, QualityGeneratorConfigs configs, Date fromDate, Date toDate) { - int numCreated = 0; List<Organisation> organisations = generatorService.loadGeneratorOrganisations(generator); - String ceTypeKeyString = configs.getValue(CONFIG_KEY_CURRICULUM_ELEMENT_TYPE); - Long ceTypeKey = Long.valueOf(ceTypeKeyString); - SearchParameters searchParams = new SearchParameters(generator, organisations, ceTypeKey, fromDate, toDate); - List<CurriculumElementRef> curriculumElementRefs = CurriculumElementWhiteListController.getCurriculumElementRefs(configs); - searchParams.setCurriculumElementRefs(curriculumElementRefs); + List<CurriculumElement> elements = loadCurriculumElements(generator, configs, fromDate, toDate, organisations); - String dueDateType = configs.getValue(CONFIG_KEY_DUE_DATE_TYPE); - String dueDateDays = configs.getValue(CONFIG_KEY_DUE_DATE_DAYS); - if (CONFIG_KEY_DUE_DATE_BEGIN.equals(dueDateType)) { - searchParams.setStartDate(true); - List<CurriculumElement> curriculumElementsFormStart = providerDao.loadPending(searchParams); - for (CurriculumElement curriculumElement: curriculumElementsFormStart) { - Date dcStart = addDays(curriculumElement.getBeginDate(), dueDateDays); - generateDataCollection(generator, configs, organisations, curriculumElement, dcStart); - } - numCreated += curriculumElementsFormStart.size(); - } else if (CONFIG_KEY_DUE_DATE_END.equals(dueDateType)) { - searchParams.setStartDate(false); - List<CurriculumElement> curriculumElementsFormEnd = providerDao.loadPending(searchParams); - for (CurriculumElement curriculumElement: curriculumElementsFormEnd) { - Date dcStart = addDays(curriculumElement.getEndDate(), dueDateDays); - generateDataCollection(generator, configs, organisations, curriculumElement, dcStart); - } - numCreated += curriculumElementsFormEnd.size(); + for (CurriculumElement element : elements) { + generateDataCollection(generator, configs, organisations, element); } - log.debug(numCreated + " data collections created by generator " + generator.toString()); + if (!elements.isEmpty()) { + log.info(elements + " data collections created by generator " + generator.toString()); + } } private void generateDataCollection(QualityGenerator generator, QualityGeneratorConfigs configs, - List<Organisation> organisations, CurriculumElement curriculumElement, Date dcStart) { + List<Organisation> organisations, CurriculumElement curriculumElement) { // create data collection RepositoryEntry formEntry = generator.getFormEntry(); Long generatorProviderKey = curriculumElement.getKey(); QualityDataCollection dataCollection = qualityService.createDataCollection(organisations, formEntry, generator, generatorProviderKey); + String dueDateType = configs.getValue(CONFIG_KEY_DUE_DATE_TYPE); + String dueDateDays = configs.getValue(CONFIG_KEY_DUE_DATE_DAYS); + Date dcStart = CONFIG_KEY_DUE_DATE_BEGIN.equals(dueDateType) + ? curriculumElement.getBeginDate() + : curriculumElement.getEndDate(); + dcStart = addDays(dcStart, dueDateDays); dataCollection.setStart(dcStart); String duration = configs.getValue(CONFIG_KEY_DURATION_DAYS); @@ -240,4 +213,44 @@ public class CurriculumElementProvider implements QualityGeneratorProvider { } } + private List<CurriculumElement> loadCurriculumElements(QualityGenerator generator, QualityGeneratorConfigs configs, + Date fromDate, Date toDate, List<Organisation> organisations) { + SearchParameters searchParams = createSearchParams(generator, configs, fromDate, toDate, organisations); + if(log.isDebug()) log.debug("Generator " + generator + " searches with " + searchParams); + + List<CurriculumElement> elements = providerDao.loadPending(searchParams); + + if(log.isDebug()) log.debug("Generator " + generator + " found " + elements.size() + " curriculum elements"); + return elements; + } + + private SearchParameters createSearchParams(QualityGenerator generator, QualityGeneratorConfigs configs, + Date fromDate, Date toDate, List<Organisation> organisations) { + SearchParameters searchParams = new SearchParameters(); + searchParams.setGeneratorRef(generator); + searchParams.setOrganisationRefs(organisations); + + String ceTypeKeyString = configs.getValue(CONFIG_KEY_CURRICULUM_ELEMENT_TYPE); + Long ceTypeKey = Long.valueOf(ceTypeKeyString); + searchParams.setCeTypeKey(ceTypeKey); + + String dueDateDays = configs.getValue(CONFIG_KEY_DUE_DATE_DAYS); + Date dueDateFrom = addDays(fromDate, dueDateDays); + searchParams.setFrom(dueDateFrom); + Date dueDateTo = addDays(toDate, dueDateDays); + searchParams.setTo(dueDateTo); + + String dueDateType = configs.getValue(CONFIG_KEY_DUE_DATE_TYPE); + if (CONFIG_KEY_DUE_DATE_BEGIN.equals(dueDateType)) { + searchParams.setStartDate(true); + } else if (CONFIG_KEY_DUE_DATE_END.equals(dueDateType)) { + searchParams.setStartDate(false); + } + + List<CurriculumElementRef> curriculumElementRefs = CurriculumElementWhiteListController.getCurriculumElementRefs(configs); + searchParams.setCurriculumElementRefs(curriculumElementRefs); + + return searchParams; + } + } diff --git a/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/CurriculumElementProviderDAO.java b/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/CurriculumElementProviderDAO.java index d1294ddec66..95a572bcf28 100644 --- a/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/CurriculumElementProviderDAO.java +++ b/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/CurriculumElementProviderDAO.java @@ -19,13 +19,14 @@ */ package org.olat.modules.quality.generator.provider.curriculumelement.manager; -import java.util.ArrayList; +import static java.util.stream.Collectors.toList; + import java.util.List; -import java.util.stream.Collectors; 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.CurriculumElement; import org.olat.modules.curriculum.CurriculumElementRef; @@ -46,13 +47,10 @@ public class CurriculumElementProviderDAO { private DB dbInstance; public List<CurriculumElement> loadPending(SearchParameters searchParams) { - if (validateSearchParams(searchParams)) { - return new ArrayList<>(0); - } - - StringBuilder sb = new StringBuilder(256); + QueryBuilder sb = new QueryBuilder(512); sb.append("select curEle"); - appendFrom(sb); + sb.append(" from curriculumelement as curEle"); + sb.append(" inner join curEle.curriculum cur");; appendWhere(sb, searchParams); TypedQuery<CurriculumElement> query = dbInstance.getCurrentEntityManager() @@ -61,66 +59,64 @@ public class CurriculumElementProviderDAO { return query.getResultList(); } - public Long loadPendingCount(SearchParameters searchParams) { - if (validateSearchParams(searchParams)) { - return 0l; + private void appendWhere(QueryBuilder sb, SearchParameters searchParams) { + sb.and().append("curEle.status = '").append(CurriculumElementStatus.active.name()).append("'"); + if (searchParams.isStartDate() && searchParams.getFrom() != null) { + sb.and().append("curEle.beginDate >= :beginFrom"); } - - StringBuilder sb = new StringBuilder(256); - sb.append("select count(curEle)"); - appendFrom(sb); - appendWhere(sb, searchParams); - - TypedQuery<Long> query = dbInstance.getCurrentEntityManager() - .createQuery(sb.toString(), Long.class); - appendParameter(query, searchParams); - - List<Long> counts = query.getResultList(); - return !counts.isEmpty()? counts.get(0): 0l; - } - - private boolean validateSearchParams(SearchParameters searchParams) { - return searchParams.getGeneratorRef() == null || searchParams.getGeneratorRef().getKey() == null - || searchParams.getOrganisationRefs().isEmpty() || searchParams.getCeTypeKey() == null - || searchParams.getFrom() == null || searchParams.getTo() == null; - } - - private void appendFrom(StringBuilder sb) { - sb.append(" from curriculumelement as curEle"); - sb.append(" inner join curEle.curriculum cur"); - } - - private void appendWhere(StringBuilder sb, SearchParameters searchParams) { - sb.append(" where curEle.type.key = :ceTypeKey"); - sb.append(" and curEle.status = '").append(CurriculumElementStatus.active.name()).append("'"); - sb.append(" and cur.organisation.key in :organisationKeys"); - sb.append(" and curEle.key not in ("); - sb.append(" select datacollection.generatorProviderKey"); - sb.append(" from qualitydatacollection as datacollection"); - sb.append(" where datacollection.generator.key = :generatorKey"); - sb.append(" )"); - - if (searchParams.isStartDate()) { - sb.append(" and curEle.beginDate > :from and curEle.beginDate <= :to"); - } else { - sb.append(" and curEle.endDate > :from and curEle.endDate <= :to"); + if (searchParams.isStartDate() && searchParams.getTo() != null) { + sb.and().append("curEle.beginDate <= :beginTo"); } - - if (!searchParams.getCurriculumElementRefs().isEmpty()) { - sb.append(" and curEle.key in :curEleKeys"); + if (!searchParams.isStartDate() && searchParams.getFrom() != null) { + sb.and().append("curEle.endDate >= :endFrom"); + } + if (!searchParams.isStartDate() && searchParams.getTo() != null) { + sb.and().append("curEle.endDate <= :endTo"); + } + if (searchParams.getCeTypeKey() != null) { + sb.and().append("curEle.type.key = :ceTypeKey"); + } + if (searchParams.getGeneratorRef() != null) { + sb.and(); + sb.append("curEle.key not in ("); + sb.append("select datacollection.generatorProviderKey"); + sb.append(" from qualitydatacollection as datacollection"); + sb.append(" where datacollection.generator.key = :generatorKey"); + sb.append(")"); + } + if (searchParams.getOrganisationRefs() != null && !searchParams.getOrganisationRefs().isEmpty()) { + sb.and().append("cur.organisation.key in :organisationKeys"); + } + if (searchParams.getCurriculumElementRefs() != null && !searchParams.getCurriculumElementRefs().isEmpty()) { + sb.and().append("curEle.key in :curEleKeys"); } } private void appendParameter(TypedQuery<?> query, SearchParameters searchParams) { - List<Long> organisationKeys = searchParams.getOrganisationRefs().stream().map(OrganisationRef::getKey).collect(Collectors.toList()); - query.setParameter("ceTypeKey", searchParams.getCeTypeKey()) - .setParameter("organisationKeys", organisationKeys) - .setParameter("generatorKey", searchParams.getGeneratorRef().getKey()) - .setParameter("from", searchParams.getFrom()) - .setParameter("to", searchParams.getTo()); - - if (!searchParams.getCurriculumElementRefs().isEmpty()) { - List<Long> curEleKeys = searchParams.getCurriculumElementRefs().stream().map(CurriculumElementRef::getKey).collect(Collectors.toList()); + if (searchParams.isStartDate() && searchParams.getFrom() != null) { + query.setParameter("beginFrom", searchParams.getFrom()); + } + if (searchParams.isStartDate() && searchParams.getTo() != null) { + query.setParameter("beginTo", searchParams.getTo()); + } + if (!searchParams.isStartDate() && searchParams.getFrom() != null) { + query.setParameter("endFrom", searchParams.getFrom()); + } + if (!searchParams.isStartDate() && searchParams.getTo() != null) { + query.setParameter("endTo", searchParams.getTo()); + } + if (searchParams.getCeTypeKey() != null) { + query.setParameter("ceTypeKey", searchParams.getCeTypeKey()); + } + if (searchParams.getGeneratorRef() != null) { + query.setParameter("generatorKey", searchParams.getGeneratorRef().getKey()); + } + if (searchParams.getOrganisationRefs() != null && !searchParams.getOrganisationRefs().isEmpty()) { + List<Long> organisationKeys = searchParams.getOrganisationRefs().stream().map(OrganisationRef::getKey).collect(toList()); + query.setParameter("organisationKeys", organisationKeys); + } + if (searchParams.getCurriculumElementRefs() != null && !searchParams.getCurriculumElementRefs().isEmpty()) { + List<Long> curEleKeys = searchParams.getCurriculumElementRefs().stream().map(CurriculumElementRef::getKey).collect(toList()); query.setParameter("curEleKeys", curEleKeys); } } diff --git a/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/SearchParameters.java b/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/SearchParameters.java index 1198175049e..bb2b0189447 100644 --- a/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/SearchParameters.java +++ b/src/main/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/SearchParameters.java @@ -19,9 +19,9 @@ */ package org.olat.modules.quality.generator.provider.curriculumelement.manager; -import java.util.ArrayList; import java.util.Collection; import java.util.Date; +import java.util.stream.Collectors; import org.olat.core.id.Organisation; import org.olat.core.id.OrganisationRef; @@ -30,10 +30,11 @@ import org.olat.modules.quality.generator.QualityGeneratorRef; /** * Initial date: 20.08.2018<br> - * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com + * + * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com */ public class SearchParameters { - + private QualityGeneratorRef generatorRef; private Collection<? extends OrganisationRef> organisationRefs; private Long ceTypeKey; @@ -42,15 +43,6 @@ public class SearchParameters { private Date to; private boolean startDate; - public SearchParameters(QualityGeneratorRef generatorRef, Collection<? extends OrganisationRef> organisationRefs, - Long ceTypeKey, Date from, Date to) { - this.generatorRef = generatorRef; - this.organisationRefs = organisationRefs; - this.ceTypeKey = ceTypeKey; - this.from = from; - this.to = to; - } - public QualityGeneratorRef getGeneratorRef() { return generatorRef; } @@ -60,20 +52,14 @@ public class SearchParameters { } public Collection<? extends OrganisationRef> getOrganisationRefs() { - if (organisationRefs == null) { - organisationRefs = new ArrayList<>(0); - } return organisationRefs; } - public void setOrganisations(Collection<Organisation> organisations) { + public void setOrganisationRefs(Collection<Organisation> organisations) { this.organisationRefs = organisations; } public Collection<? extends CurriculumElementRef> getCurriculumElementRefs() { - if (curriculumElementRefs == null) { - curriculumElementRefs = new ArrayList<>(0); - } return curriculumElementRefs; } @@ -112,4 +98,27 @@ public class SearchParameters { public void setStartDate(boolean startDate) { this.startDate = startDate; } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SearchParameters [generatorRef="); + builder.append(generatorRef); + builder.append(", organisationRefs (keys)=["); + builder.append(organisationRefs.stream().map(OrganisationRef::getKey).map(k -> k.toString()) + .collect(Collectors.joining(", "))); + builder.append("]"); + builder.append(", ceTypeKey="); + builder.append(ceTypeKey); + builder.append(", curriculumElementRefs="); + builder.append(curriculumElementRefs); + builder.append(", from="); + builder.append(from); + builder.append(", to="); + builder.append(to); + builder.append(", startDate="); + builder.append(startDate); + builder.append("]"); + return builder.toString(); + } } \ No newline at end of file diff --git a/src/test/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/CurriculumElementProviderDAOTest.java b/src/test/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/CurriculumElementProviderDAOTest.java index ee173569342..8e3830de9e1 100644 --- a/src/test/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/CurriculumElementProviderDAOTest.java +++ b/src/test/java/org/olat/modules/quality/generator/provider/curriculumelement/manager/CurriculumElementProviderDAOTest.java @@ -71,16 +71,13 @@ public class CurriculumElementProviderDAOTest extends OlatTestCase { @Test public void shouldLoadCurriculumElements() { Organisation organisation = organisationService.createOrganisation(random(), random(), null, null, null); - List<Organisation> organisations = Collections.singletonList(organisation); CurriculumElementType ceType = curriculumService.createCurriculumElementType(random(), random(), null, null); Curriculum curriculum = curriculumService.createCurriculum(random(), random(), null, organisation); CurriculumElement curriculumElement = curriculumService.createCurriculumElement(random(), random(), oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); - QualityGenerator generator = generatorService.createGenerator(random(), organisations); dbInstance.commitAndCloseSession(); - SearchParameters searchParams = new SearchParameters(generator, organisations, ceType.getKey(), oneMonthAgo(), today()); - searchParams.setStartDate(true); + SearchParameters searchParams = new SearchParameters(); List<CurriculumElement> pending = sut.loadPending(searchParams); assertThat(pending).contains(curriculumElement); @@ -90,21 +87,20 @@ public class CurriculumElementProviderDAOTest extends OlatTestCase { public void shouldFilterByAlreadyCreated() { Organisation organisation = organisationService.createOrganisation(random(), random(), null, null, null); List<Organisation> organisations = Collections.singletonList(organisation); - CurriculumElementType ceType = curriculumService.createCurriculumElementType(random(), random(), null, null); Curriculum curriculum = curriculumService.createCurriculum(random(), random(), null, organisation); CurriculumElement curriculumElement = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); + oneDayAgo(), inOneDay(), null, null, CurriculumCalendars.disabled, curriculum); QualityGenerator generator = generatorService.createGenerator(random(), organisations); dbInstance.commitAndCloseSession(); CurriculumElement curriculumElementCreated = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); + oneDayAgo(), inOneDay(), null, null, CurriculumCalendars.disabled, curriculum); RepositoryEntry formEntry = JunitTestHelper.createAndPersistRepositoryEntry(); qualityService.createDataCollection(organisations, formEntry, generator, curriculumElementCreated.getKey()); dbInstance.commitAndCloseSession(); - SearchParameters searchParams = new SearchParameters(generator, organisations, ceType.getKey(), oneMonthAgo(), today()); - searchParams.setStartDate(true); + SearchParameters searchParams = new SearchParameters(); + searchParams.setGeneratorRef(generator); List<CurriculumElement> pending = sut.loadPending(searchParams); assertThat(pending).contains(curriculumElement).doesNotContain(curriculumElementCreated); @@ -113,22 +109,19 @@ public class CurriculumElementProviderDAOTest extends OlatTestCase { @Test public void shouldFilterByOrganisation() { Organisation organisation = organisationService.createOrganisation(random(), random(), null, null, null); - List<Organisation> organisations = Collections.singletonList(organisation); - CurriculumElementType ceType = curriculumService.createCurriculumElementType(random(), random(), null, null); Curriculum curriculum = curriculumService.createCurriculum(random(), random(), null, organisation); CurriculumElement curriculumElement = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); - QualityGenerator generator = generatorService.createGenerator(random(), organisations); + oneDayAgo(), inOneDay(), null, null, CurriculumCalendars.disabled, curriculum); dbInstance.commitAndCloseSession(); Organisation otherOrganisation = organisationService.createOrganisation(random(), random(), null, null, null); Curriculum otherCurriculum = curriculumService.createCurriculum(random(), random(), null, otherOrganisation); CurriculumElement otherCurriculumElement = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, otherCurriculum); + oneDayAgo(), inOneDay(), null, null, CurriculumCalendars.disabled, otherCurriculum); dbInstance.commitAndCloseSession(); - SearchParameters searchParams = new SearchParameters(generator, organisations, ceType.getKey(), oneMonthAgo(), today()); - searchParams.setStartDate(true); + SearchParameters searchParams = new SearchParameters(); + searchParams.setOrganisationRefs(asList(organisation)); List<CurriculumElement> pending = sut.loadPending(searchParams); assertThat(pending).contains(curriculumElement).doesNotContain(otherCurriculumElement); @@ -137,12 +130,10 @@ public class CurriculumElementProviderDAOTest extends OlatTestCase { @Test public void shouldFilterByCurriculumElementType() { Organisation organisation = organisationService.createOrganisation(random(), random(), null, null, null); - List<Organisation> organisations = Collections.singletonList(organisation); CurriculumElementType ceType = curriculumService.createCurriculumElementType(random(), random(), null, null); Curriculum curriculum = curriculumService.createCurriculum(random(), random(), null, organisation); CurriculumElement curriculumElement = curriculumService.createCurriculumElement(random(), random(), oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); - QualityGenerator generator = generatorService.createGenerator(random(), organisations); dbInstance.commitAndCloseSession(); CurriculumElementType otherCeType = curriculumService.createCurriculumElementType(random(), random(), null, null); @@ -150,8 +141,8 @@ public class CurriculumElementProviderDAOTest extends OlatTestCase { oneDayAgo(), inOneDay(), null, otherCeType, CurriculumCalendars.disabled, curriculum); dbInstance.commitAndCloseSession(); - SearchParameters searchParams = new SearchParameters(generator, organisations, ceType.getKey(), oneMonthAgo(), today()); - searchParams.setStartDate(true); + SearchParameters searchParams = new SearchParameters(); + searchParams.setCeTypeKey(ceType.getKey()); List<CurriculumElement> pending = sut.loadPending(searchParams); assertThat(pending).contains(curriculumElement).doesNotContain(otherCurriculumElement); @@ -160,23 +151,19 @@ public class CurriculumElementProviderDAOTest extends OlatTestCase { @Test public void shouldFilterByCurriculumElement() { Organisation organisation = organisationService.createOrganisation(random(), random(), null, null, null); - List<Organisation> organisations = Collections.singletonList(organisation); - CurriculumElementType ceType = curriculumService.createCurriculumElementType(random(), random(), null, null); Curriculum curriculum = curriculumService.createCurriculum(random(), random(), null, organisation); - QualityGenerator generator = generatorService.createGenerator(random(), organisations); dbInstance.commitAndCloseSession(); CurriculumElement curriculumElement1 = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); + oneDayAgo(), inOneDay(), null, null, CurriculumCalendars.disabled, curriculum); CurriculumElement curriculumElement2 = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); + oneDayAgo(), inOneDay(), null, null, CurriculumCalendars.disabled, curriculum); CurriculumElement otherCurriculumElement = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); + oneDayAgo(), inOneDay(), null, null, CurriculumCalendars.disabled, curriculum); dbInstance.commitAndCloseSession(); - SearchParameters searchParams = new SearchParameters(generator, organisations, ceType.getKey(), oneMonthAgo(), today()); + SearchParameters searchParams = new SearchParameters(); searchParams.setCurriculumElementRefs(asList(curriculumElement1, curriculumElement2)); - searchParams.setStartDate(true); List<CurriculumElement> pending = sut.loadPending(searchParams); assertThat(pending) @@ -187,25 +174,23 @@ public class CurriculumElementProviderDAOTest extends OlatTestCase { @Test public void shouldFilterByBeginDate() { Organisation organisation = organisationService.createOrganisation(random(), random(), null, null, null); - List<Organisation> organisations = Collections.singletonList(organisation); - CurriculumElementType ceType = curriculumService.createCurriculumElementType(random(), random(), null, null); Curriculum curriculum = curriculumService.createCurriculum(random(), random(), null, organisation); - - QualityGenerator generator = generatorService.createGenerator(random(), organisations); dbInstance.commitAndCloseSession(); CurriculumElement beginBeforeFrom = curriculumService.createCurriculumElement(random(), random(), - oneYearAgo(), oneYearAgo(), null, ceType, CurriculumCalendars.disabled, curriculum); + oneYearAgo(), oneYearAgo(), null, null, CurriculumCalendars.disabled, curriculum); CurriculumElement beginBetweenFromAndTo = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), oneDayAgo(), null, ceType, CurriculumCalendars.disabled, curriculum); + oneDayAgo(), oneDayAgo(), null, null, CurriculumCalendars.disabled, curriculum); CurriculumElement beginAfterTo = curriculumService.createCurriculumElement(random(), random(), - inOneDay(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); + inOneDay(), inOneDay(), null, null, CurriculumCalendars.disabled, curriculum); CurriculumElement beginNull = curriculumService.createCurriculumElement(random(), random(), - null, null, null, ceType, CurriculumCalendars.disabled, curriculum); + null, null, null, null, CurriculumCalendars.disabled, curriculum); beginAfterTo.setBeginDate(inOneDay()); dbInstance.commitAndCloseSession(); - SearchParameters searchParams = new SearchParameters(generator, organisations, ceType.getKey(), oneMonthAgo(), today()); + SearchParameters searchParams = new SearchParameters(); + searchParams.setFrom(oneMonthAgo()); + searchParams.setTo(today()); searchParams.setStartDate(true); List<CurriculumElement> pending = sut.loadPending(searchParams); @@ -215,25 +200,23 @@ public class CurriculumElementProviderDAOTest extends OlatTestCase { @Test public void shouldFilterByEndDate() { Organisation organisation = organisationService.createOrganisation(random(), random(), null, null, null); - List<Organisation> organisations = Collections.singletonList(organisation); - CurriculumElementType ceType = curriculumService.createCurriculumElementType(random(), random(), null, null); Curriculum curriculum = curriculumService.createCurriculum(random(), random(), null, organisation); - - QualityGenerator generator = generatorService.createGenerator(random(), organisations); dbInstance.commitAndCloseSession(); CurriculumElement endBeforeFrom = curriculumService.createCurriculumElement(random(), random(), - oneYearAgo(), oneYearAgo(), null, ceType, CurriculumCalendars.disabled, curriculum); + oneYearAgo(), oneYearAgo(), null, null, CurriculumCalendars.disabled, curriculum); CurriculumElement endBetweenFromAndTo = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), oneDayAgo(), null, ceType, CurriculumCalendars.disabled, curriculum); + oneDayAgo(), oneDayAgo(), null, null, CurriculumCalendars.disabled, curriculum); CurriculumElement endAfterTo = curriculumService.createCurriculumElement(random(), random(), - inOneDay(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); + inOneDay(), inOneDay(), null, null, CurriculumCalendars.disabled, curriculum); CurriculumElement endNull = curriculumService.createCurriculumElement(random(), random(), - null, null, null, ceType, CurriculumCalendars.disabled, curriculum); + null, null, null, null, CurriculumCalendars.disabled, curriculum); endAfterTo.setBeginDate(inOneDay()); dbInstance.commitAndCloseSession(); - SearchParameters searchParams = new SearchParameters(generator, organisations, ceType.getKey(), oneMonthAgo(), today()); + SearchParameters searchParams = new SearchParameters(); + searchParams.setFrom(oneMonthAgo()); + searchParams.setTo(today()); searchParams.setStartDate(false); List<CurriculumElement> pending = sut.loadPending(searchParams); @@ -243,51 +226,27 @@ public class CurriculumElementProviderDAOTest extends OlatTestCase { @Test public void shouldFilterActiveOnly() { Organisation organisation = organisationService.createOrganisation(random(), random(), null, null, null); - List<Organisation> organisations = Collections.singletonList(organisation); - CurriculumElementType ceType = curriculumService.createCurriculumElementType(random(), random(), null, null); Curriculum curriculum = curriculumService.createCurriculum(random(), random(), null, organisation); CurriculumElement active = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); - QualityGenerator generator = generatorService.createGenerator(random(), organisations); + oneDayAgo(), inOneDay(), null, null, CurriculumCalendars.disabled, curriculum); dbInstance.commitAndCloseSession(); CurriculumElement inactive = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); + oneDayAgo(), inOneDay(), null, null, CurriculumCalendars.disabled, curriculum); inactive.setElementStatus(CurriculumElementStatus.inactive); inactive = curriculumService.updateCurriculumElement(inactive); CurriculumElement deleted = curriculumService.createCurriculumElement(random(), random(), - oneDayAgo(), inOneDay(), null, ceType, CurriculumCalendars.disabled, curriculum); + oneDayAgo(), inOneDay(), null, null, CurriculumCalendars.disabled, curriculum); deleted.setElementStatus(CurriculumElementStatus.deleted); deleted = curriculumService.updateCurriculumElement(deleted); dbInstance.commitAndCloseSession(); - SearchParameters searchParams = new SearchParameters(generator, organisations, ceType.getKey(), oneMonthAgo(), today()); - searchParams.setStartDate(true); + SearchParameters searchParams = new SearchParameters(); List<CurriculumElement> pending = sut.loadPending(searchParams); assertThat(pending).contains(active).doesNotContain(inactive, deleted); } - @Test - public void shouldLoadCount() { - Organisation organisation = organisationService.createOrganisation(random(), random(), null, null, null); - List<Organisation> organisations = Collections.singletonList(organisation); - CurriculumElementType ceType = curriculumService.createCurriculumElementType(random(), random(), null, null); - Curriculum curriculum = curriculumService.createCurriculum(random(), random(), null, organisation); - curriculumService.createCurriculumElement(random(), random(), oneDayAgo(), inOneDay(), null, ceType, - CurriculumCalendars.disabled, curriculum); - curriculumService.createCurriculumElement(random(), random(), oneDayAgo(), inOneDay(), null, ceType, - CurriculumCalendars.disabled, curriculum); - QualityGenerator generator = generatorService.createGenerator(random(), organisations); - dbInstance.commitAndCloseSession(); - - SearchParameters searchParams = new SearchParameters(generator, organisations, ceType.getKey(), oneMonthAgo(), today()); - searchParams.setStartDate(true); - Long count = sut.loadPendingCount(searchParams); - - assertThat(count).isEqualTo(2); - } - private String random() { return UUID.randomUUID().toString(); } -- GitLab