Search in sources :

Example 91 with LectureBlock

use of org.olat.modules.lecture.LectureBlock in project openolat by klemens.

the class LecturesBlocksTest method addTeacherToLectureBlock.

@Test
public void addTeacherToLectureBlock() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    Identity teacher = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence config", "Course with absence configuration", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    LectureBlock block = createLectureBlock(entry);
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(entry.getKey().toString()).path("lectureblocks").path(block.getKey().toString()).path("teachers").path(teacher.getKey().toString()).build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    // check the response
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check the database
    List<Identity> teachers = lectureService.getTeachers(block);
    Assert.assertTrue(teachers.contains(teacher));
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 92 with LectureBlock

use of org.olat.modules.lecture.LectureBlock in project openolat by klemens.

the class LectureBlockRollCallDAO method getParticipantLectureBlockAndRollCalls.

public List<LectureBlockAndRollCall> getParticipantLectureBlockAndRollCalls(RepositoryEntryRef entry, IdentityRef identity, String teacherSeaparator) {
    StringBuilder sb = new StringBuilder();
    sb.append("select block, call, re.displayname").append(" from lectureblock block").append(" inner join block.entry re").append(" inner join block.groups blockToGroup").append(" inner join blockToGroup.group bGroup").append(" inner join bGroup.members membership").append(" inner join lectureparticipantsummary as summary on (summary.identity.key=membership.identity.key and summary.entry.key=block.entry.key)").append(" left join lectureblockrollcall as call on (call.identity.key=membership.identity.key and call.lectureBlock.key=block.key)").append(" where membership.identity.key=:identityKey and membership.role='").append(GroupRoles.participant.name()).append("'").append(" and block.entry.key=:repoEntryKey and block.endDate>=summary.firstAdmissionDate");
    List<Object[]> rawObjects = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", identity.getKey()).setParameter("repoEntryKey", entry.getKey()).getResultList();
    Map<Long, LectureBlockAndRollCall> blockToRollCallMap = new HashMap<>();
    for (Object[] objects : rawObjects) {
        int pos = 0;
        LectureBlock block = (LectureBlock) objects[pos++];
        LectureBlockRollCall rollCall = (LectureBlockRollCall) objects[pos++];
        String displayname = (String) objects[pos++];
        blockToRollCallMap.put(block.getKey(), new LectureBlockAndRollCall(displayname, block, rollCall));
    }
    appendCoaches(entry, blockToRollCallMap, teacherSeaparator);
    return new ArrayList<>(blockToRollCallMap.values());
}
Also used : LectureBlockAndRollCall(org.olat.modules.lecture.model.LectureBlockAndRollCall) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall)

Example 93 with LectureBlock

use of org.olat.modules.lecture.LectureBlock in project openolat by klemens.

the class LectureServiceImpl method adaptAll.

@Override
public void adaptAll(Identity author) {
    List<LectureBlock> lectureBlocks = lectureBlockDao.getLectureBlocks();
    for (LectureBlock lectureBlock : lectureBlocks) {
        List<LectureBlockRollCall> rollCallList = lectureBlockRollCallDao.getRollCalls(lectureBlock);
        for (LectureBlockRollCall rollCall : rollCallList) {
            int numOfLectures = lectureBlock.getEffectiveLecturesNumber();
            if (numOfLectures <= 0 && lectureBlock.getStatus() != LectureBlockStatus.cancelled) {
                numOfLectures = lectureBlock.getPlannedLecturesNumber();
            }
            lectureBlockRollCallDao.adaptLecture(lectureBlock, rollCall, numOfLectures, author);
        }
        dbInstance.commitAndCloseSession();
    }
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall)

Example 94 with LectureBlock

use of org.olat.modules.lecture.LectureBlock in project openolat by klemens.

the class LectureServiceImpl method fullSyncCourseCalendar.

private void fullSyncCourseCalendar(RepositoryEntry entry) {
    List<LectureBlock> blocks = getLectureBlocks(entry);
    Map<String, LectureBlock> externalIds = blocks.stream().collect(Collectors.toMap(b -> generateExternalId(b, entry), b -> b));
    Kalendar cal = calendarMgr.getCalendar(CalendarManager.TYPE_COURSE, entry.getOlatResource().getResourceableId().toString());
    String prefix = generateExternalIdPrefix(entry);
    List<KalendarEvent> events = new ArrayList<>(cal.getEvents());
    for (KalendarEvent event : events) {
        String externalId = event.getExternalId();
        if (StringHelper.containsNonWhitespace(externalId) && externalId.startsWith(prefix)) {
            if (externalIds.containsKey(externalId)) {
                if (updateEvent(externalIds.get(externalId), event)) {
                    calendarMgr.updateEventFrom(cal, event);
                }
                externalIds.remove(externalId);
            } else {
                calendarMgr.removeEventFrom(cal, event);
            }
        }
    }
    // add new calendar events
    List<KalendarEvent> eventsToAdd = new ArrayList<>();
    for (Map.Entry<String, LectureBlock> entryToAdd : externalIds.entrySet()) {
        eventsToAdd.add(createEvent(entryToAdd.getValue(), entry));
    }
    if (eventsToAdd.size() > 0) {
        calendarMgr.addEventTo(cal, eventsToAdd);
    }
}
Also used : Util(org.olat.core.util.Util) LectureParticipantSummary(org.olat.modules.lecture.LectureParticipantSummary) LectureBlockRollCallSearchParameters(org.olat.modules.lecture.LectureBlockRollCallSearchParameters) Date(java.util.Date) I18nManager(org.olat.core.util.i18n.I18nManager) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef) LectureBlockAuditLog(org.olat.modules.lecture.LectureBlockAuditLog) Autowired(org.springframework.beans.factory.annotation.Autowired) IdentityRef(org.olat.basesecurity.IdentityRef) MailContextImpl(org.olat.core.util.mail.MailContextImpl) RepositoryEntryLectureConfiguration(org.olat.modules.lecture.RepositoryEntryLectureConfiguration) Locale(java.util.Locale) GroupDAO(org.olat.basesecurity.manager.GroupDAO) Map(java.util.Map) Group(org.olat.basesecurity.Group) LectureBlockToGroup(org.olat.modules.lecture.LectureBlockToGroup) LectureBlockStatistics(org.olat.modules.lecture.model.LectureBlockStatistics) MailTemplate(org.olat.core.util.mail.MailTemplate) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) OLog(org.olat.core.logging.OLog) Translator(org.olat.core.gui.translator.Translator) LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockWithTeachers(org.olat.modules.lecture.model.LectureBlockWithTeachers) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) Set(java.util.Set) LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl) UUID(java.util.UUID) AggregatedLectureBlocksStatistics(org.olat.modules.lecture.model.AggregatedLectureBlocksStatistics) Collectors(java.util.stream.Collectors) VelocityContext(org.apache.velocity.VelocityContext) MailManager(org.olat.core.util.mail.MailManager) LectureService(org.olat.modules.lecture.LectureService) List(java.util.List) Identity(org.olat.core.id.Identity) ParticipantAndLectureSummary(org.olat.modules.lecture.model.ParticipantAndLectureSummary) IdentityImpl(org.olat.basesecurity.IdentityImpl) MailContext(org.olat.core.util.mail.MailContext) LectureBlockIdentityStatistics(org.olat.modules.lecture.model.LectureBlockIdentityStatistics) Settings(org.olat.core.helpers.Settings) MailBundle(org.olat.core.util.mail.MailBundle) LectureBlockAndRollCall(org.olat.modules.lecture.model.LectureBlockAndRollCall) Action(org.olat.modules.lecture.LectureBlockAuditLog.Action) HashMap(java.util.HashMap) CalendarManagedFlag(org.olat.commons.calendar.CalendarManagedFlag) Reason(org.olat.modules.lecture.Reason) RepositoryEntry(org.olat.repository.RepositoryEntry) LecturesBlockSearchParameters(org.olat.modules.lecture.model.LecturesBlockSearchParameters) ArrayList(java.util.ArrayList) Kalendar(org.olat.commons.calendar.model.Kalendar) HashSet(java.util.HashSet) Calendar(java.util.Calendar) Service(org.springframework.stereotype.Service) StringHelper(org.olat.core.util.StringHelper) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) RepositoryEntryDAO(org.olat.repository.manager.RepositoryEntryDAO) LectureBlockToTeacher(org.olat.modules.lecture.model.LectureBlockToTeacher) CalendarManager(org.olat.commons.calendar.CalendarManager) LectureBlockRef(org.olat.modules.lecture.LectureBlockRef) LectureBlockStatus(org.olat.modules.lecture.LectureBlockStatus) LectureStatisticsSearchParameters(org.olat.modules.lecture.model.LectureStatisticsSearchParameters) Formatter(org.olat.core.util.Formatter) MailerResult(org.olat.core.util.mail.MailerResult) LectureAdminController(org.olat.modules.lecture.ui.LectureAdminController) LectureModule(org.olat.modules.lecture.LectureModule) Iterator(java.util.Iterator) LectureBlockRollCallRef(org.olat.modules.lecture.LectureBlockRollCallRef) File(java.io.File) UserManager(org.olat.user.UserManager) DB(org.olat.core.commons.persistence.DB) BusinessGroup(org.olat.group.BusinessGroup) DeletableGroupData(org.olat.group.DeletableGroupData) LectureRollCallStatus(org.olat.modules.lecture.LectureRollCallStatus) Tracing(org.olat.core.logging.Tracing) ConfigurationHelper(org.olat.modules.lecture.ui.ConfigurationHelper) UserDataDeletable(org.olat.user.UserDataDeletable) LectureBlock(org.olat.modules.lecture.LectureBlock) Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Map(java.util.Map) HashMap(java.util.HashMap)

Example 95 with LectureBlock

use of org.olat.modules.lecture.LectureBlock in project openolat by klemens.

the class LectureServiceImpl method deleteLectureBlock.

@Override
public void deleteLectureBlock(LectureBlock lectureBlock) {
    // first remove events
    LectureBlock reloadedBlock = lectureBlockDao.loadByKey(lectureBlock.getKey());
    RepositoryEntry entry = reloadedBlock.getEntry();
    RepositoryEntryLectureConfiguration config = getRepositoryEntryLectureConfiguration(entry);
    if (ConfigurationHelper.isSyncCourseCalendarEnabled(config, lectureModule)) {
        unsyncCourseCalendar(lectureBlock, entry);
    }
    if (ConfigurationHelper.isSyncTeacherCalendarEnabled(config, lectureModule)) {
        List<Identity> teachers = getTeachers(reloadedBlock);
        unsyncInternalCalendar(reloadedBlock, teachers);
    }
    lectureBlockDao.delete(reloadedBlock);
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryLectureConfiguration(org.olat.modules.lecture.RepositoryEntryLectureConfiguration) Identity(org.olat.core.id.Identity)

Aggregations

LectureBlock (org.olat.modules.lecture.LectureBlock)232 Identity (org.olat.core.id.Identity)132 Test (org.junit.Test)116 RepositoryEntry (org.olat.repository.RepositoryEntry)98 Date (java.util.Date)64 LectureBlockRollCall (org.olat.modules.lecture.LectureBlockRollCall)42 URI (java.net.URI)30 ArrayList (java.util.ArrayList)30 HttpResponse (org.apache.http.HttpResponse)30 Group (org.olat.basesecurity.Group)30 Calendar (java.util.Calendar)26 ICourse (org.olat.course.ICourse)24 BusinessGroup (org.olat.group.BusinessGroup)24 CourseConfigVO (org.olat.restapi.support.vo.CourseConfigVO)24 LectureBlockToGroup (org.olat.modules.lecture.LectureBlockToGroup)22 RepositoryEntryLectureConfiguration (org.olat.modules.lecture.RepositoryEntryLectureConfiguration)20 LecturesBlockSearchParameters (org.olat.modules.lecture.model.LecturesBlockSearchParameters)16 List (java.util.List)14 HttpGet (org.apache.http.client.methods.HttpGet)14 LectureBlockToTeacher (org.olat.modules.lecture.model.LectureBlockToTeacher)14