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));
}
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());
}
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();
}
}
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);
}
}
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);
}
Aggregations