Skip to content
Snippets Groups Projects
Commit c5e2919b authored by srosse's avatar srosse
Browse files

OO-2636: implement deletion of courses and users

parent ce77a8de
No related branches found
No related tags found
No related merge requests found
Showing
with 99 additions and 13 deletions
......@@ -102,6 +102,13 @@ public interface LectureService {
*/
public void deleteLectureBlock(LectureBlock block);
/**
* Delete all the lecture blocks and configuration of the specified course.
*
* @param entry
*/
public int delete(RepositoryEntry entry);
/**
* Returns all configured reasons.
*
......
......@@ -142,6 +142,13 @@ public class LectureBlockDAO {
return rows;
}
public List<LectureBlock> getLectureBlocks(RepositoryEntryRef entry) {
return dbInstance.getCurrentEntityManager()
.createNamedQuery("lectureBlocksByRepositoryEntry", LectureBlock.class)
.setParameter("repoEntryKey", entry.getKey())
.getResultList();
}
/**
*
* @param entry The course (mandatory)
......
......@@ -78,4 +78,12 @@ public class LectureBlockReminderDAO {
}
return blockToTeachers;
}
public int deleteReminders(Identity identity) {
String del = "delete from lecturereminder reminder where reminder.identity.key=:identityKey";
return dbInstance.getCurrentEntityManager()
.createQuery(del)
.setParameter("identityKey", identity.getKey())
.executeUpdate();
}
}
......@@ -151,6 +151,14 @@ public class LectureBlockRollCallDAO {
return dbInstance.getCurrentEntityManager().merge(rollCall);
}
public int deleteRollCalls(Identity identity) {
String del = "delete from lectureblockrollcall rollcall where rollcall.identity.key=:identityKey";
return dbInstance.getCurrentEntityManager()
.createQuery(del)
.setParameter("identityKey", identity.getKey())
.executeUpdate();
}
public List<LectureBlockRollCall> getRollCalls(LectureBlockRef block) {
StringBuilder sb = new StringBuilder();
sb.append("select rollcall from lectureblockrollcall rollcall")
......
......@@ -152,4 +152,22 @@ public class LectureParticipantSummaryDAO {
public LectureParticipantSummary update(LectureParticipantSummary summary) {
return dbInstance.getCurrentEntityManager().merge(summary);
}
public int deleteSummaries(RepositoryEntryRef entry) {
//delete summaries
String deleteSummaries = "delete from lectureparticipantsummary summary where summary.entry.key=:repoEntryKey";
return dbInstance.getCurrentEntityManager()
.createQuery(deleteSummaries)
.setParameter("repoEntryKey", entry.getKey())
.executeUpdate();
}
public int deleteSummaries(Identity identity) {
//delete summaries
String deleteSummaries = "delete from lectureparticipantsummary summary where summary.identity.key=:identityKey";
return dbInstance.getCurrentEntityManager()
.createQuery(deleteSummaries)
.setParameter("identityKey", identity.getKey())
.executeUpdate();
}
}
......@@ -19,6 +19,7 @@
*/
package org.olat.modules.lecture.manager;
import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
......@@ -75,6 +76,7 @@ import org.olat.modules.lecture.ui.LectureAdminController;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryEntryRef;
import org.olat.repository.manager.RepositoryEntryDAO;
import org.olat.user.UserDataDeletable;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -86,7 +88,7 @@ import org.springframework.stereotype.Service;
*
*/
@Service
public class LectureServiceImpl implements LectureService {
public class LectureServiceImpl implements LectureService, UserDataDeletable {
private static final CalendarManagedFlag[] CAL_MANAGED_FLAGS = new CalendarManagedFlag[] { CalendarManagedFlag.all };
......@@ -208,6 +210,25 @@ public class LectureServiceImpl implements LectureService {
lectureBlockDao.delete(block);
}
@Override
public int delete(RepositoryEntry entry) {
int rows = 0;
List<LectureBlock> blocksToDelete = lectureBlockDao.getLectureBlocks(entry);
for(LectureBlock blockToDelete:blocksToDelete) {
rows += lectureBlockDao.delete(blockToDelete);
}
rows += lectureConfigurationDao.deleteConfiguration(entry);
rows += lectureParticipantSummaryDao.deleteSummaries(entry);
return rows;
}
@Override
public void deleteUserData(Identity identity, String newDeletedUserName, File archivePath) {
lectureParticipantSummaryDao.deleteSummaries(identity);
lectureBlockRollCallDao.deleteRollCalls(identity);
lectureBlockReminderDao.deleteReminders(identity);
}
@Override
public LectureBlock getLectureBlock(LectureBlockRef block) {
return lectureBlockDao.loadByKey(block.getKey());
......
......@@ -70,12 +70,8 @@ public class RepositoryEntryLectureConfigurationDAO {
}
public RepositoryEntryLectureConfiguration getConfiguration(RepositoryEntryRef entry) {
StringBuilder sb = new StringBuilder();
sb.append("select config from lectureentryconfig config")
.append(" where config.entry.key=:entryKey");
List<RepositoryEntryLectureConfiguration> configs = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), RepositoryEntryLectureConfiguration.class)
.createNamedQuery("lectureconfigByRepositoryEntry", RepositoryEntryLectureConfiguration.class)
.setParameter("entryKey", entry.getKey())
.getResultList();
return configs == null || configs.isEmpty() ? null : configs.get(0);
......@@ -98,4 +94,11 @@ public class RepositoryEntryLectureConfigurationDAO {
public RepositoryEntryLectureConfiguration update(RepositoryEntryLectureConfiguration config) {
return dbInstance.getCurrentEntityManager().merge(config);
}
public int deleteConfiguration(RepositoryEntryRef entry) {
String sb = "delete from lectureentryconfig config where config.entry.key=:repoEntryKey";
return dbInstance.getCurrentEntityManager().createQuery(sb)
.setParameter("repoEntryKey", entry.getKey())
.executeUpdate();
}
}
......@@ -31,6 +31,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
......@@ -55,6 +57,9 @@ import org.olat.repository.RepositoryEntry;
*/
@Entity(name="lectureblock")
@Table(name="o_lecture_block")
@NamedQueries(
@NamedQuery(name="lectureBlocksByRepositoryEntry", query="select block from lectureblock block where block.entry.key=:repoEntryKey")
)
public class LectureBlockImpl implements Persistable, LectureBlock {
private static final long serialVersionUID = -1010006683915268916L;
......
......@@ -29,6 +29,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
......@@ -45,6 +47,9 @@ import org.olat.repository.RepositoryEntry;
*/
@Entity(name="lectureentryconfig")
@Table(name="o_lecture_entry_config")
@NamedQueries(
@NamedQuery(name="lectureconfigByRepositoryEntry", query="select config from lectureentryconfig config where config.entry.key=:entryKey")
)
public class RepositoryEntryLectureConfigurationImpl implements Persistable, RepositoryEntryLectureConfiguration {
private static final long serialVersionUID = -728141275261361935L;
......
......@@ -32,22 +32,22 @@ import org.olat.modules.lecture.RepositoryEntryLectureConfiguration;
public class ConfigurationHelper {
public static boolean isRollCallEnabled(RepositoryEntryLectureConfiguration lectureConfig, LectureModule lectureModule) {
return (lectureConfig.isOverrideModuleDefault() && lectureConfig.getRollCallEnabled() != null && lectureConfig.getRollCallEnabled().booleanValue())
|| (!lectureConfig.isOverrideModuleDefault() && lectureModule.isRollCallDefaultEnabled());
return (lectureConfig != null && lectureConfig.isOverrideModuleDefault() && lectureConfig.getRollCallEnabled() != null && lectureConfig.getRollCallEnabled().booleanValue())
|| ((lectureConfig == null || !lectureConfig.isOverrideModuleDefault()) && lectureModule.isRollCallDefaultEnabled());
}
public static boolean isSyncTeacherCalendarEnabled(RepositoryEntryLectureConfiguration lectureConfig, LectureModule lectureModule) {
return (lectureConfig.isOverrideModuleDefault() && lectureConfig.getTeacherCalendarSyncEnabled() != null && lectureConfig.getTeacherCalendarSyncEnabled().booleanValue())
|| (!lectureConfig.isOverrideModuleDefault() && lectureModule.isTeacherCalendarSyncEnabledDefault());
return (lectureConfig != null && lectureConfig.isOverrideModuleDefault() && lectureConfig.getTeacherCalendarSyncEnabled() != null && lectureConfig.getTeacherCalendarSyncEnabled().booleanValue())
|| ((lectureConfig == null || !lectureConfig.isOverrideModuleDefault()) && lectureModule.isTeacherCalendarSyncEnabledDefault());
}
public static boolean isSyncParticipantCalendarEnabled(RepositoryEntryLectureConfiguration lectureConfig, LectureModule lectureModule) {
return (lectureConfig.isOverrideModuleDefault() && lectureConfig.getParticipantCalendarSyncEnabled() != null && lectureConfig.getParticipantCalendarSyncEnabled().booleanValue())
|| (!lectureConfig.isOverrideModuleDefault() && lectureModule.isParticipantCalendarSyncEnabledDefault());
return (lectureConfig != null && lectureConfig.isOverrideModuleDefault() && lectureConfig.getParticipantCalendarSyncEnabled() != null && lectureConfig.getParticipantCalendarSyncEnabled().booleanValue())
|| ((lectureConfig == null || !lectureConfig.isOverrideModuleDefault()) && lectureModule.isParticipantCalendarSyncEnabledDefault());
}
public static boolean isRateEnabled(RepositoryEntryLectureConfiguration lectureConfig, LectureModule lectureModule) {
if(lectureConfig.isOverrideModuleDefault()) {
if(lectureConfig != null && lectureConfig.isOverrideModuleDefault()) {
return lectureConfig.getCalculateAttendanceRate() == null ?
lectureModule.isRollCallCalculateAttendanceRateDefaultEnabled() : lectureConfig.getCalculateAttendanceRate().booleanValue();
}
......
......@@ -62,6 +62,7 @@ import org.olat.course.assessment.manager.UserCourseInformationsManager;
import org.olat.course.certificate.CertificatesManager;
import org.olat.ims.qti21.manager.AssessmentTestSessionDAO;
import org.olat.modules.assessment.manager.AssessmentEntryDAO;
import org.olat.modules.lecture.LectureService;
import org.olat.modules.reminder.manager.ReminderDAO;
import org.olat.repository.ErrorList;
import org.olat.repository.RepositoryEntry;
......@@ -403,6 +404,9 @@ public class RepositoryServiceImpl implements RepositoryService {
//delete all pending tasks
persistentTaskDao.delete(resource);
dbInstance.commit();
//delete lectures
CoreSpringFactory.getImpl(LectureService.class).delete(entry);
dbInstance.commit();
// inform handler to do any cleanup work... handler must delete the
// referenced resourceable a swell.
......
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