summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx
diff options
context:
space:
mode:
authorSimon Rettberg2016-01-19 15:40:15 +0100
committerSimon Rettberg2016-01-19 15:40:15 +0100
commitffba802b538b82cc202939cebf26e3925ced9686 (patch)
treeda5bb21cc205e49ca31dae5a9bec6093364f82b2 /dozentenmodulserver/src/main/java/org/openslx
parent[client] Fix NPE related to location editor (diff)
downloadtutor-module-ffba802b538b82cc202939cebf26e3925ced9686.tar.gz
tutor-module-ffba802b538b82cc202939cebf26e3925ced9686.tar.xz
tutor-module-ffba802b538b82cc202939cebf26e3925ced9686.zip
[server] Fill location info in LectureRead, set maxLocationsPerLecture to 4
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/RuntimeConfig.java9
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java6
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLocation.java19
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java6
4 files changed, 33 insertions, 7 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/RuntimeConfig.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/RuntimeConfig.java
index 8f050777..0a4c0165 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/RuntimeConfig.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/RuntimeConfig.java
@@ -15,11 +15,12 @@ public class RuntimeConfig {
satConfig = new SatelliteConfig();
satConfig.setDefaultImagePermissions(new ImagePermissions(true, true, false, false));
satConfig.setDefaultLecturePermissions(new LecturePermissions(false, false));
- satConfig.setMaxImageValidityDays(200);
- satConfig.setMaxLectureValidityDays(200);
+ satConfig.setMaxImageValidityDays(220);
+ satConfig.setMaxLectureValidityDays(220);
satConfig.setPageSize(Paginator.PER_PAGE);
satConfig.setMaxConnectionsPerTransfer(Constants.MAX_CONNECTIONS_PER_TRANSFER);
satConfig.setMaxTransfers(Constants.MAX_UPLOADS / 2);
+ satConfig.setMaxLocationsPerLecture(4);
}
public static SatelliteConfig get() {
@@ -34,6 +35,10 @@ public class RuntimeConfig {
return satConfig.getMaxLectureValidityDays() * 86400l;
}
+ public static int getMaxLocationsPerLecture() {
+ return satConfig.getMaxLocationsPerLecture();
+ }
+
/**
* How long a version that is not the latest version of an image will be kept.
*
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 1f0daf66..ace13b05 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
@@ -283,8 +283,8 @@ public class DbLecture {
lecture.setImageBaseId(rs.getString("imagebaseid"));
lecture.setAutoUpdate(rs.getBoolean("autoupdate"));
lecture.setIsEnabled(rs.getBoolean("isenabled"));
- //lecture.setLimitToAllowedUsers(rs.getBoolean("isprivate"));
- //lecture.setLimitToLocations(rs.getBoolean("islocationprivate")); TODO
+ lecture.setLimitToAllowedUsers(rs.getBoolean("isprivate"));
+ lecture.setLimitToLocations(rs.getBoolean("islocationprivate"));
lecture.setStartTime(rs.getLong("starttime"));
lecture.setEndTime(rs.getLong("endtime"));
lecture.setLastUsed(rs.getLong("lastused"));
@@ -312,7 +312,7 @@ public class DbLecture {
lecture.setDefaultPermissions(DbLecturePermissions.fromResultSetDefault(rs));
lecture.setUserPermissions(DbLecturePermissions.fromResultSetUser(rs));
User.setCombinedUserPermissions(lecture, user);
- // TODO: Query locations
+ lecture.setLocationIds(DbLocation.getLectureLocations(connection, lectureId));
return lecture;
} catch (SQLException e) {
LOGGER.error("Query failed in DbLecture.getLectureDetails()", e);
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLocation.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLocation.java
index e14bcf0d..b079d3b4 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLocation.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLocation.java
@@ -23,11 +23,11 @@ public class DbLocation {
if (Util.isEmptyString(locationsTable))
return list;
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement("SELECT locationid, locationname FROM "
+ MysqlStatement stmt = connection.prepareStatement("SELECT locationid, parentlocationid, locationname FROM "
+ locationsTable);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
- list.add(new Location(rs.getInt("locationid"), rs.getString("locationname")));
+ list.add(new Location(rs.getInt("locationid"), rs.getString("locationname"), rs.getInt("parentlocationid")));
}
} catch (SQLException e) {
LOGGER.error("Query failed in DbLocation.getLocations()", e);
@@ -36,4 +36,19 @@ public class DbLocation {
return list;
}
+ public static List<Integer> getLectureLocations(MysqlConnection connection, String lectureId) throws SQLException {
+ List<Integer> list = new ArrayList<>();
+ String locationsTable = Configuration.getDbLocationTable();
+ if (Util.isEmptyString(locationsTable))
+ return list;
+ MysqlStatement stmt = connection.prepareStatement("SELECT locationid FROM lecture_x_location"
+ + " WHERE lectureid = :lectureid");
+ stmt.setString("lectureid", lectureId);
+ ResultSet rs = stmt.executeQuery();
+ while (rs.next()) {
+ list.add(rs.getInt("locationid"));
+ }
+ return list;
+ }
+
}
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 d24bb912..3244ac95 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
@@ -514,6 +514,8 @@ public class ServerHandler implements SatelliteServer.Iface {
TInvocationException, TInvalidDateParam, TNotFoundException {
if (lecture == null || lecture.defaultPermissions == null)
throw new TInvocationException(InvocationError.MISSING_DATA, "Lecture data missing or incomplete");
+ if (lecture.locationIds != null && lecture.locationIds.size() > RuntimeConfig.getMaxLocationsPerLecture())
+ throw new TInvocationException(InvocationError.INVALID_DATA, "Too many locations for lecture");
UserInfo user = SessionManager.getOrFail(userToken);
User.canCreateLectureOrFail(user);
User.canLinkToImageOrFail(user, lecture.imageVersionId);
@@ -528,6 +530,10 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public void updateLecture(String userToken, String lectureId, LectureWrite newLectureData)
throws TAuthorizationException, TNotFoundException, TInvocationException, TInvalidDateParam {
+ if (newLectureData == null)
+ throw new TInvocationException(InvocationError.MISSING_DATA, "Lecture data missing or incomplete");
+ if (newLectureData.locationIds != null && newLectureData.locationIds.size() > RuntimeConfig.getMaxLocationsPerLecture())
+ throw new TInvocationException(InvocationError.INVALID_DATA, "Too many locations for lecture");
UserInfo user = SessionManager.getOrFail(userToken);
LectureSummary oldLecture;
try {