summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver
diff options
context:
space:
mode:
authorSimon Rettberg2018-12-11 10:41:49 +0100
committerSimon Rettberg2018-12-11 10:41:49 +0100
commit645f99079478eb3a5e7e041a6f5a836e61832ad2 (patch)
tree8135ff251045cf3ea7aa4763e88f0e992f42b63f /dozentenmodulserver
parent[server] Add sharename index (diff)
downloadtutor-module-645f99079478eb3a5e7e041a6f5a836e61832ad2.tar.gz
tutor-module-645f99079478eb3a5e7e041a6f5a836e61832ad2.tar.xz
tutor-module-645f99079478eb3a5e7e041a6f5a836e61832ad2.zip
[*] Follow changes in m-s-s to load/save predef netshare/filters
Diffstat (limited to 'dozentenmodulserver')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java21
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java23
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureNetshare.java31
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java4
4 files changed, 48 insertions, 31 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 fd2b8c19..faa708ba 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
@@ -20,6 +20,7 @@ import org.openslx.bwlp.sat.thrift.cache.OperatingSystemList;
import org.openslx.bwlp.sat.web.VmChooserEntryXml;
import org.openslx.bwlp.sat.web.VmChooserListXml;
import org.openslx.bwlp.sat.web.XmlFilterEntry;
+import org.openslx.bwlp.thrift.iface.LdapFilter;
import org.openslx.bwlp.thrift.iface.LectureRead;
import org.openslx.bwlp.thrift.iface.LectureSummary;
import org.openslx.bwlp.thrift.iface.LectureWrite;
@@ -120,10 +121,10 @@ public class DbLecture {
stmt.executeUpdate();
writeLocations(connection, lectureId, lecture.locationIds);
if (lecture.isSetNetworkShares()) {
- DbLectureNetshare.writeNetworkShares(connection, lectureId, lecture.networkShares);
+ DbLectureNetshare.writeForLecture(connection, lectureId, lecture.networkShares);
}
if (lecture.isSetLdapFilters()) {
- DbLectureFilter.writeLdapFilters(connection, lectureId, lecture.ldapFilters);
+ DbLectureFilter.writeForLectureLdap(connection, lectureId, lecture.ldapFilters);
}
connection.commit();
return lectureId;
@@ -147,10 +148,10 @@ public class DbLecture {
setWriteFields(stmt, lectureId, lecture, user);
writeLocations(connection, lectureId, lecture.locationIds);
if (lecture.isSetNetworkShares()) {
- DbLectureNetshare.writeNetworkShares(connection, lectureId, lecture.networkShares);
+ DbLectureNetshare.writeForLecture(connection, lectureId, lecture.networkShares);
}
if (lecture.isSetLdapFilters()) {
- DbLectureFilter.writeLdapFilters(connection, lectureId, lecture.ldapFilters);
+ DbLectureFilter.writeForLectureLdap(connection, lectureId, lecture.ldapFilters);
}
if (lecture.isSetPresetScriptIds()) {
DbRunScript.writeLectureRunScripts(connection, lectureId, lecture.presetScriptIds);
@@ -344,8 +345,14 @@ public class DbLecture {
lecture.setUserPermissions(DbLecturePermissions.fromResultSetUser(rs));
User.setCombinedUserPermissions(lecture, user);
lecture.setLocationIds(DbLocation.getLectureLocations(connection, lectureId));
- lecture.setNetworkShares(DbLectureNetshare.getLectureNetshares(connection, lectureId));
- lecture.setLdapFilters(DbLectureFilter.getLectureLdapFilters(connection, lectureId));
+ lecture.setNetworkShares(new ArrayList<NetShare>());
+ lecture.setPresetNetworkShares(new ArrayList<Integer>());
+ DbLectureNetshare.getSplitForLecture(connection, lectureId,
+ lecture.networkShares, lecture.presetNetworkShares);
+ lecture.setLdapFilters(new ArrayList<LdapFilter>());
+ lecture.setPresetLdapFilters(new ArrayList<Integer>());
+ DbLectureFilter.getSplitForLectureLdap(connection, lectureId,
+ lecture.ldapFilters, lecture.presetLdapFilters);
return lecture;
} catch (SQLException e) {
LOGGER.error("Query failed in DbLecture.getLectureDetails()", e);
@@ -577,7 +584,7 @@ public class DbLecture {
usbAccess = rs.getBoolean("hasusbaccess");
retval.vmx = meta;
retval.legacyRunScript = rs.getString("runscript");
- retval.netShares = DbLectureNetshare.getLectureNetshares(connection, lectureId);
+ retval.netShares = DbLectureNetshare.getCombinedForLecture(connection, lectureId);
retval.runScript = DbRunScript.getRunScriptsForLaunch(connection, lectureId, rs.getInt("osid"));
// Everything worked so far, update statistics counters
MysqlStatement upStmt = connection.prepareStatement("UPDATE"
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java
index 8afe7988..2f21af99 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java
@@ -28,21 +28,24 @@ public class DbLectureFilter {
return stmt;
}
- public static List<LdapFilter> getLectureLdapFilters(MysqlConnection connection, String lectureId)
- throws SQLException {
- List<LdapFilter> list = new ArrayList<>();
+ public static void getSplitForLectureLdap(MysqlConnection connection, String lectureId,
+ List<LdapFilter> custom, List<Integer> predef) throws SQLException {
MysqlStatement stmt = getLdapFilterStatement(connection, lectureId);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
- LdapFilter filter = new LdapFilter(rs.getString("filterkey"), rs.getString("filtervalue"));
- filter.setFilterId(rs.getInt("filterid"));
- filter.setTitle(rs.getString("filtername"));
- list.add(filter);
+ int id = rs.getInt("filterid");
+ if (id != 0) {
+ predef.add(id);
+ } else {
+ LdapFilter filter = new LdapFilter(rs.getString("filterkey"), rs.getString("filtervalue"));
+ filter.setFilterId(id);
+ filter.setTitle(rs.getString("filtername"));
+ custom.add(filter);
+ }
}
- return list;
}
- public static List<LdapFilter> getPredefinedLdapFilters()
+ public static List<LdapFilter> getPredefinedLdap()
throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
List<LdapFilter> list = new ArrayList<>();
@@ -78,7 +81,7 @@ public class DbLectureFilter {
return list;
}
- public static void writeLdapFilters(MysqlConnection connection, String lectureId, List<LdapFilter> list)
+ public static void writeForLectureLdap(MysqlConnection connection, String lectureId, List<LdapFilter> list)
throws SQLException {
if (lectureId == null || lectureId.isEmpty()) {
return;
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureNetshare.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureNetshare.java
index c60de376..30843d31 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureNetshare.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureNetshare.java
@@ -17,7 +17,7 @@ public class DbLectureNetshare {
private static final Logger LOGGER = Logger.getLogger(DbLectureNetshare.class);
- public static void writeNetworkShares(MysqlConnection connection, String lectureId, List<NetShare> shares)
+ public static void writeForLecture(MysqlConnection connection, String lectureId, List<NetShare> shares)
throws SQLException {
if (lectureId == null || lectureId.isEmpty()) {
return;
@@ -53,16 +53,7 @@ public class DbLectureNetshare {
}
}
- public static List<NetShare> getLectureNetshares(String lectureId) throws SQLException {
- try (MysqlConnection connection = Database.getConnection()) {
- return getLectureNetshares(connection, lectureId);
- } catch (SQLException e) {
- LOGGER.error("Query failed in DbNetshare.getLectureNetshares()", e);
- throw e;
- }
- }
-
- public static List<NetShare> getLectureNetshares(MysqlConnection connection, String lectureId)
+ public static List<NetShare> getCombinedForLecture(MysqlConnection connection, String lectureId)
throws SQLException {
List<NetShare> list = new ArrayList<>();
MysqlStatement netsharestmt = connection.prepareStatement(
@@ -78,7 +69,23 @@ public class DbLectureNetshare {
return list;
}
- public static List<NetShare> getPredefinedNetshares() throws SQLException {
+ public static void getSplitForLecture(MysqlConnection connection, String lectureId,
+ List<NetShare> custom, List<Integer> predef) throws SQLException {
+ MysqlStatement netsharestmt = connection
+ .prepareStatement("SELECT sharepresetid, sharedata FROM networkshare WHERE lectureid = :lectureid");
+ netsharestmt.setString("lectureid", lectureId);
+ ResultSet rs = netsharestmt.executeQuery();
+ while (rs.next()) {
+ int id = rs.getInt("sharepresetid");
+ if (id == 0) {
+ custom.add(Json.deserialize(rs.getString("sharedata"), NetShare.class).setShareId(0));
+ } else {
+ predef.add(id);
+ }
+ }
+ }
+
+ public static List<NetShare> getPredefined() throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
List<NetShare> list = new ArrayList<>();
MysqlStatement stmt = connection
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java
index f97766ed..a818a9ae 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java
@@ -794,13 +794,13 @@ public class ServerHandler implements SatelliteServer.Iface {
SessionManager.ensureAuthenticated(userToken); // Only logged in users
PredefinedData data = new PredefinedData();
try {
- data.ldapFilter = DbLectureFilter.getPredefinedLdapFilters();
+ data.ldapFilter = DbLectureFilter.getPredefinedLdap();
} catch (SQLException e) {
throw new TInvocationException(InvocationError.INTERNAL_SERVER_ERROR,
"Database failure when querying predefined LDAP filters.");
}
try {
- data.netShares = DbLectureNetshare.getPredefinedNetshares();
+ data.netShares = DbLectureNetshare.getPredefined();
} catch (SQLException e) {
throw new TInvocationException(InvocationError.INTERNAL_SERVER_ERROR,
"Database failure when querying predefined network shares.");