summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-09-02 12:09:23 +0200
committerSimon Rettberg2015-09-02 12:09:23 +0200
commit8e444863bdb91f7b8109ff7c15c29673fe67d4d6 (patch)
tree41b8a00754f6b67b5e6392edcf5762ca5b9477b1 /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java
parent.....aaaaand it's gone (diff)
downloadtutor-module-8e444863bdb91f7b8109ff7c15c29673fe67d4d6.tar.gz
tutor-module-8e444863bdb91f7b8109ff7c15c29673fe67d4d6.tar.xz
tutor-module-8e444863bdb91f7b8109ff7c15c29673fe67d4d6.zip
[server] Serve vmchooser-compatible lecture list via http
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java31
1 files changed, 30 insertions, 1 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java
index 8492dd58..1afcdb93 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java
@@ -17,6 +17,8 @@ import org.openslx.bwlp.sat.mail.MailGenerator;
import org.openslx.bwlp.sat.permissions.User;
import org.openslx.bwlp.sat.util.Json;
import org.openslx.bwlp.sat.util.Util;
+import org.openslx.bwlp.sat.web.VmChooserEntryXml;
+import org.openslx.bwlp.sat.web.VmChooserListXml;
import org.openslx.bwlp.thrift.iface.LectureRead;
import org.openslx.bwlp.thrift.iface.LectureSummary;
import org.openslx.bwlp.thrift.iface.LectureWrite;
@@ -360,7 +362,6 @@ public class DbLecture {
List<LectureSummary> lectures = getAllUsingImageVersion(connection, oldVersion.imageVersionId);
if (lectures.isEmpty())
return;
- // TODO: If there is no new candidate to switch to, send a warning via mail, otherwise, inform about switch
MysqlStatement stmt;
if (newVersion == null) {
stmt = connection.prepareStatement("UPDATE lecture SET isenabled = 0 WHERE imageversionid = :oldversionid");
@@ -401,4 +402,32 @@ public class DbLecture {
}
}
+ public static VmChooserListXml getUsableListXml(boolean exams) throws SQLException {
+ try (MysqlConnection connection = Database.getConnection()) {
+ MysqlStatement stmt = connection.prepareStatement("SELECT"
+ + " l.lectureid, l.displayname AS lecturename, l.description,"
+ + " l.endtime, l.usecount, o.displayname AS osname, v.virtname, b.istemplate, i.filepath"
+ + " FROM lecture l "
+ + " INNER JOIN imageversion i USING (imageversionid)"
+ + " INNER JOIN imagebase b USING (imagebaseid)"
+ + " INNER JOIN operatingsystem o USING (osid)"
+ + " INNER JOIN virtualizer v USING (virtid)"
+ + " WHERE l.isenabled = 1 AND l.isprivate = 0 AND l.isexam = :isexam"
+ + " AND l.starttime < UNIX_TIMESTAMP() AND l.endtime > UNIX_TIMESTAMP() AND i.isvalid = 1");
+ stmt.setBoolean("isexam", exams);
+ ResultSet rs = stmt.executeQuery();
+ VmChooserListXml list = new VmChooserListXml(true);
+ while (rs.next()) {
+ String prio = rs.getBoolean("istemplate") ? "10" : "100";
+ list.add(new VmChooserEntryXml(prio, rs.getString("filepath"), "-",
+ rs.getString("lecturename"), rs.getString("description"), rs.getString("lectureid"),
+ rs.getString("virtname"), rs.getString("osname"), ""));
+ }
+ return list;
+ } catch (SQLException e) {
+ LOGGER.error("Query failed in DbLecture.getUsableList()", e);
+ throw e;
+ }
+ }
+
}