diff options
author | Simon Rettberg | 2018-12-11 10:41:49 +0100 |
---|---|---|
committer | Simon Rettberg | 2018-12-11 10:41:49 +0100 |
commit | 645f99079478eb3a5e7e041a6f5a836e61832ad2 (patch) | |
tree | 8135ff251045cf3ea7aa4763e88f0e992f42b63f | |
parent | [server] Add sharename index (diff) | |
download | tutor-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
7 files changed, 59 insertions, 77 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/LdapFilterConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/LdapFilterConfigurator.java index 1f359305..6ebd180f 100755 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/LdapFilterConfigurator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/LdapFilterConfigurator.java @@ -157,36 +157,17 @@ public class LdapFilterConfigurator extends LdapFilterConfiguratorLayout { return ret; } - public boolean setState(List<LdapFilter> data) { + public boolean setState(List<LdapFilter> data, List<Integer> predefSelected) { if (data == null) return false; ArrayList<LdapFilter> filterList = new ArrayList<>(data); + Set<LdapFilter> checked = new HashSet<LdapFilter>(); List<LdapFilter> predef = MetaDataCache.getPredefinedLdapFilters(); - Set<LdapFilter> checked = new HashSet<>(); - for (LdapFilter item : data) { - if (item.filterId == 0) - continue; - // Item has a filterId (is predefined), so validate it's in there - // before marking it checked, or just uncheck it by removing the id - // so it becomes a custom entry. - boolean ok = false; - for (LdapFilter pd : predef) { - if (pd.filterId == item.filterId) { - checked.add(pd); - ok = true; - break; - } - } - // If it wasn't preselected, add to list now... - if (!ok) { - item.filterId = 0; - } - } // Now add remaining filters for (LdapFilter pd : predef) { - if (!checked.contains(pd)) { - filterList.add(pd); - LOGGER.info("Adding " + pd.filterId); + filterList.add(pd); + if (predefSelected != null && predefSelected.contains(pd.filterId)) { + checked.add(pd); } } tblFilters.setData(filterList, checked, false); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/NetshareConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/NetshareConfigurator.java index 0fe7052b..ec0c9009 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/NetshareConfigurator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/NetshareConfigurator.java @@ -292,32 +292,16 @@ public class NetshareConfigurator extends NetshareConfiguratorLayout { return ret; } - public boolean setState(List<NetShare> data) { + public boolean setState(List<NetShare> data, List<Integer> predefSelected) { if (data == null) return false; List<NetShare> shareList = new ArrayList<>(data); List<NetShare> predef = MetaDataCache.getPredefinedNetshares(); Set<NetShare> checked = new HashSet<>(); - for (NetShare item : data) { - if (item.shareId == 0) - continue; - boolean ok = false; - for (NetShare share : predef) { - if (share.shareId == item.shareId) { - checked.add(share); - ok = true; - break; - } - } - if (!ok) { - item.shareId = 0; - } - } - // Now add remaining filters for (NetShare share : predef) { - if (!checked.contains(share)) { - shareList.add(share); - LOGGER.info("Adding " + share.shareId); + shareList.add(share); + if (predefSelected != null && predefSelected.contains(share.shareId)) { + checked.add(share); } } tblNetshare.setData(shareList, checked, false); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java index 9fc5dd34..4820ccc6 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java @@ -343,8 +343,8 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements // init advanced info ctlRunscriptConfigurator.setState(lecture.runscript); - ctlNetshareConfigurator.setState(lecture.networkShares); - ctlLdapFilterConfigurator.setState(lecture.ldapFilters); + ctlNetshareConfigurator.setState(lecture.networkShares, lecture.presetNetworkShares); + ctlLdapFilterConfigurator.setState(lecture.ldapFilters, lecture.presetLdapFilters); ctlNetrulesConfigurator.setState(lecture.networkExceptions); txtTitle.setText(lecture.getLectureName()); 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."); |