summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLectureFilter.java73
1 files changed, 57 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();
+ }
}
}