diff options
Diffstat (limited to 'dozentenmodulserver/src')
-rw-r--r-- | dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java | 73 | ||||
-rw-r--r-- | dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java | 23 |
2 files changed, 80 insertions, 16 deletions
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 dddd47b0..8afe7988 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 @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; +import org.openslx.bwlp.sat.database.Database; import org.openslx.bwlp.sat.database.MysqlConnection; import org.openslx.bwlp.sat.database.MysqlStatement; import org.openslx.bwlp.sat.web.XmlFilterEntry; @@ -15,28 +16,56 @@ import org.openslx.util.Util; public class DbLectureFilter { private static final Logger LOGGER = Logger.getLogger(DbLectureFilter.class); + + private static MysqlStatement getLdapFilterStatement(MysqlConnection connection, String lectureId) throws SQLException { + MysqlStatement stmt = connection.prepareStatement( + "SELECT p.filterid, p.filtername," + + " IFNULL(p.filterkey, f.filterkey) AS filterkey, IFNULL(p.filtervalue, f.filtervalue) AS filtervalue" + + " FROM lecturefilter f" + + " LEFT JOIN presetlecturefilter p ON (f.filterpresetid = p.filterid)" + + " WHERE f.lectureid = :lectureid AND (f.filtertype = 'LDAP' OR p.filtertype = 'LDAP')"); + stmt.setString("lectureid", lectureId); + return stmt; + } public static List<LdapFilter> getLectureLdapFilters(MysqlConnection connection, String lectureId) throws SQLException { List<LdapFilter> list = new ArrayList<>(); - MysqlStatement stmt = connection.prepareStatement("SELECT filterkey, filtervalue FROM lecturefilter" - + " WHERE lectureid = :lectureid AND filtertype = 'LDAP'"); - stmt.setString("lectureid", lectureId); + MysqlStatement stmt = getLdapFilterStatement(connection, lectureId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { - String key = rs.getString("filterkey"); - String value = rs.getString("filtervalue"); - list.add(new LdapFilter(key, value)); + LdapFilter filter = new LdapFilter(rs.getString("filterkey"), rs.getString("filtervalue")); + filter.setFilterId(rs.getInt("filterid")); + filter.setTitle(rs.getString("filtername")); + list.add(filter); } return list; } + + public static List<LdapFilter> getPredefinedLdapFilters() + throws SQLException { + try (MysqlConnection connection = Database.getConnection()) { + List<LdapFilter> list = new ArrayList<>(); + MysqlStatement stmt = connection.prepareStatement("SELECT filterid, filtername, filterkey, filtervalue" + + " FROM presetlecturefilter WHERE filtertype = 'LDAP'"); + 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); + } + return list; + } catch (SQLException e) { + LOGGER.error("Query failed in getPredefinedLdapFilters()", e); + throw e; + } + } public static final List<XmlFilterEntry> getFiltersXml(MysqlConnection connection, String lectureId) throws SQLException { List<XmlFilterEntry> list = null; - MysqlStatement stmt = connection.prepareStatement("SELECT filterkey, filtervalue FROM lecturefilter" - + " WHERE lectureid = :lectureid AND filtertype = 'LDAP'"); - stmt.setString("lectureid", lectureId); + MysqlStatement stmt = getLdapFilterStatement(connection, lectureId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String key = rs.getString("filterkey"); @@ -60,15 +89,27 @@ public class DbLectureFilter { if (list == null || list.isEmpty()) { return; } - MysqlStatement addStmt = connection.prepareStatement("INSERT INTO lecturefilter (lectureid, filtertype, filterkey, filtervalue)" + MysqlStatement addCustomStmt = connection.prepareStatement( + "INSERT INTO lecturefilter (lectureid, filtertype, filterkey, filtervalue)" + " VALUES (:lectureid, 'LDAP', :key, :value)"); - addStmt.setString("lectureid", lectureId); + MysqlStatement addPredefStmt = connection.prepareStatement( + "INSERT INTO lecturefilter (lectureid, filterpresetid)" + + " VALUES (:lectureid, :filterid)"); + addCustomStmt.setString("lectureid", lectureId); + addPredefStmt.setString("lectureid", lectureId); for (LdapFilter filter : list) { - if (Util.isEmptyString(filter.attribute) || filter.value == null) - continue; - addStmt.setString("key", filter.attribute); - addStmt.setString("value", filter.value); - addStmt.executeUpdate(); + if (filter.filterId == 0) { + // Custom + if (Util.isEmptyString(filter.attribute) || filter.value == null) + continue; + addCustomStmt.setString("key", filter.attribute); + addCustomStmt.setString("value", filter.value); + addCustomStmt.executeUpdate(); + } else { + // Predef reference + addPredefStmt.setInt("filterid", filter.filterId); + addPredefStmt.executeUpdate(); + } } } 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 30c38288..52ec6b21 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 @@ -3,6 +3,7 @@ package org.openslx.bwlp.sat.thrift; import java.io.File; import java.nio.ByteBuffer; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -14,6 +15,7 @@ import org.openslx.bwlp.sat.database.mappers.DbImage; import org.openslx.bwlp.sat.database.mappers.DbImage.DeleteState; import org.openslx.bwlp.sat.database.mappers.DbImagePermissions; import org.openslx.bwlp.sat.database.mappers.DbLecture; +import org.openslx.bwlp.sat.database.mappers.DbLectureFilter; import org.openslx.bwlp.sat.database.mappers.DbLecturePermissions; import org.openslx.bwlp.sat.database.mappers.DbLocation; import org.openslx.bwlp.sat.database.mappers.DbLog; @@ -43,13 +45,17 @@ import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.ImageVersionDetails; import org.openslx.bwlp.thrift.iface.ImageVersionWrite; import org.openslx.bwlp.thrift.iface.InvocationError; +import org.openslx.bwlp.thrift.iface.LdapFilter; import org.openslx.bwlp.thrift.iface.LecturePermissions; import org.openslx.bwlp.thrift.iface.LectureRead; import org.openslx.bwlp.thrift.iface.LectureSummary; import org.openslx.bwlp.thrift.iface.LectureWrite; import org.openslx.bwlp.thrift.iface.Location; +import org.openslx.bwlp.thrift.iface.NetShare; +import org.openslx.bwlp.thrift.iface.NetShareAuth; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.Organization; +import org.openslx.bwlp.thrift.iface.PredefinedData; import org.openslx.bwlp.thrift.iface.SatelliteConfig; import org.openslx.bwlp.thrift.iface.SatelliteServer; import org.openslx.bwlp.thrift.iface.SatelliteStatus; @@ -780,4 +786,21 @@ public class ServerHandler implements SatelliteServer.Iface { } } + @Override + public PredefinedData getPredefinedData(String userToken) throws TAuthorizationException, + TInvocationException, TException { + PredefinedData data = new PredefinedData(new ArrayList<NetShare>(), new ArrayList<LdapFilter>()); + try { + data.ldapFilter = DbLectureFilter.getPredefinedLdapFilters(); + } catch (SQLException e) { + throw new TInvocationException(InvocationError.INTERNAL_SERVER_ERROR, + "Database failure when querying predefined LDAP filters."); + } + // Dummy 2 + NetShare ns = new NetShare(NetShareAuth.OTHER_USER, "\\\\server.example.org\\data"); + ns.setShareId(1); + data.netShares.add(ns); + return data; + } + } |