summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-08-27 18:08:48 +0200
committerSimon Rettberg2015-08-27 18:08:48 +0200
commitac15c2a1cfe0fc0519b5577e7478c25500fe45c3 (patch)
treecdc93ee180fe17220c8a193fff73238e9ddcc651 /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java
parentMerge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff)
downloadtutor-module-ac15c2a1cfe0fc0519b5577e7478c25500fe45c3.tar.gz
tutor-module-ac15c2a1cfe0fc0519b5577e7478c25500fe45c3.tar.xz
tutor-module-ac15c2a1cfe0fc0519b5577e7478c25500fe45c3.zip
[*] Thrift API changes
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java140
1 files changed, 86 insertions, 54 deletions
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 4656519e..8fe48f9f 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
@@ -14,6 +14,7 @@ import org.openslx.bwlp.sat.database.mappers.DbImagePermissions;
import org.openslx.bwlp.sat.database.mappers.DbLecture;
import org.openslx.bwlp.sat.database.mappers.DbLecturePermissions;
import org.openslx.bwlp.sat.database.mappers.DbUser;
+import org.openslx.bwlp.sat.database.models.LocalUser;
import org.openslx.bwlp.sat.fileserv.ActiveDownload;
import org.openslx.bwlp.sat.fileserv.ActiveUpload;
import org.openslx.bwlp.sat.fileserv.FileServer;
@@ -21,16 +22,17 @@ import org.openslx.bwlp.sat.permissions.User;
import org.openslx.bwlp.sat.thrift.cache.OperatingSystemList;
import org.openslx.bwlp.sat.thrift.cache.OrganizationList;
import org.openslx.bwlp.sat.thrift.cache.VirtualizerList;
+import org.openslx.bwlp.sat.util.FileSystem;
import org.openslx.bwlp.sat.util.Sanitizer;
import org.openslx.bwlp.sat.util.Util;
import org.openslx.bwlp.thrift.iface.AuthorizationError;
import org.openslx.bwlp.thrift.iface.ImageBaseWrite;
-import org.openslx.bwlp.thrift.iface.ImageDataError;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
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.LecturePermissions;
import org.openslx.bwlp.thrift.iface.LectureRead;
import org.openslx.bwlp.thrift.iface.LectureSummary;
@@ -39,12 +41,13 @@ import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Organization;
import org.openslx.bwlp.thrift.iface.SatelliteConfig;
import org.openslx.bwlp.thrift.iface.SatelliteServer;
+import org.openslx.bwlp.thrift.iface.SatelliteStatus;
+import org.openslx.bwlp.thrift.iface.SatelliteUserConfig;
import org.openslx.bwlp.thrift.iface.ShareMode;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
-import org.openslx.bwlp.thrift.iface.TImageDataException;
-import org.openslx.bwlp.thrift.iface.TInternalServerError;
import org.openslx.bwlp.thrift.iface.TInvalidDateParam;
import org.openslx.bwlp.thrift.iface.TInvalidTokenException;
+import org.openslx.bwlp.thrift.iface.TInvocationException;
import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.bwlp.thrift.iface.TTransferRejectedException;
import org.openslx.bwlp.thrift.iface.TransferInformation;
@@ -89,14 +92,14 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public TransferInformation requestImageVersionUpload(String userToken, String imageBaseId, long fileSize,
List<ByteBuffer> blockHashes, ByteBuffer machineDescription) throws TTransferRejectedException,
- TAuthorizationException, TInternalServerError, TNotFoundException, TException {
+ TAuthorizationException, TInvocationException, TNotFoundException, TException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canEditBaseImageOrFail(user, imageBaseId);
ImageDetailsRead image;
try {
image = DbImage.getImageDetails(user, imageBaseId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
// Unwrap machine description
byte[] mDesc = null;
@@ -122,7 +125,7 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public ByteBuffer getMachineDescription(String userToken, String imageVersionId)
- throws TAuthorizationException, TInternalServerError, TNotFoundException, TException {
+ throws TAuthorizationException, TInvocationException, TNotFoundException, TException {
// TODO Auto-generated method stub
return null;
}
@@ -145,7 +148,7 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public TransferInformation requestDownload(String userToken, String imageVersionId)
- throws TAuthorizationException, TInternalServerError, TNotFoundException,
+ throws TAuthorizationException, TInvocationException, TNotFoundException,
TTransferRejectedException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canDownloadImageVersionOrFail(user, imageVersionId);
@@ -153,7 +156,7 @@ public class ServerHandler implements SatelliteServer.Iface {
try {
transfer = fileServer.createNewUserDownload(DbImage.getLocalImageData(imageVersionId));
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
return new TransferInformation(transfer.getId(), fileServer.getPlainPort(), fileServer.getSslPort());
}
@@ -170,12 +173,12 @@ public class ServerHandler implements SatelliteServer.Iface {
*/
@Override
- public void isAuthenticated(String userToken) throws TAuthorizationException, TInternalServerError {
+ public void isAuthenticated(String userToken) throws TAuthorizationException, TInvocationException {
SessionManager.ensureAuthenticated(userToken);
}
@Override
- public WhoamiInfo whoami(String userToken) throws TAuthorizationException, TInternalServerError {
+ public WhoamiInfo whoami(String userToken) throws TAuthorizationException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
return new WhoamiInfo(user, User.isSuperUser(user), User.canListImages(user));
}
@@ -204,62 +207,91 @@ public class ServerHandler implements SatelliteServer.Iface {
return OrganizationList.get();
}
+ @Override
+ public SatelliteStatus getStatus() {
+ return new SatelliteStatus(FileSystem.getAvailableStorageBytes(), Util.unixTime());
+ }
+
/*
* Everything below required at least a valid session
*/
@Override
+ public SatelliteUserConfig getUserConfig(String userToken) throws TAuthorizationException,
+ TInvocationException {
+ UserInfo user = SessionManager.getOrFail(userToken);
+ LocalUser localData;
+ try {
+ localData = DbUser.getLocalData(user);
+ } catch (SQLException e) {
+ throw new TInvocationException();
+ }
+ return new SatelliteUserConfig(localData != null && localData.emailNotifications);
+ }
+
+ @Override
+ public void setUserConfig(String userToken, SatelliteUserConfig config) throws TAuthorizationException,
+ TInvocationException {
+ UserInfo user = SessionManager.getOrFail(userToken);
+ try {
+ DbUser.writeUserConfig(user, config);
+ } catch (SQLException e) {
+ throw new TInvocationException();
+ }
+ }
+
+ @Override
public List<ImageSummaryRead> getImageList(String userToken, List<String> tagSearch, int page)
- throws TAuthorizationException, TInternalServerError {
+ throws TAuthorizationException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canListImagesOrFail(user);
try {
return DbImage.getAllVisible(user, tagSearch, page);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public ImageDetailsRead getImageDetails(String userToken, String imageBaseId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError {
+ throws TAuthorizationException, TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canSeeImageDetailsOrFail(user);
try {
return DbImage.getImageDetails(user, imageBaseId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public String createImage(String userToken, String imageName) throws TAuthorizationException,
- TImageDataException, TInternalServerError {
+ TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canCreateImageOrFail(user);
if (!Util.isPrintable(imageName) || Util.isEmptyString(imageName))
- throw new TImageDataException(ImageDataError.INVALID_DATA, "Invalid or empty name");
+ throw new TInvocationException(InvocationError.INVALID_DATA, "Invalid or empty name");
try {
return DbImage.createImage(user, imageName);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void updateImageBase(String userToken, String imageBaseId, ImageBaseWrite newData)
- throws TAuthorizationException, TInternalServerError, TNotFoundException, TImageDataException {
+ throws TAuthorizationException, TInvocationException, TNotFoundException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canEditBaseImageOrFail(user, imageBaseId);
// Check image name for invalid characters
if (!Util.isPrintable(newData.imageName) || Util.isEmptyString(newData.imageName))
- throw new TImageDataException(ImageDataError.INVALID_DATA, "Invalid or empty name");
+ throw new TInvocationException(InvocationError.INVALID_DATA, "Invalid or empty name");
// Check if image is marked for replication. If so, only allow changing the syncmode to FROZEN/DOWNLOAD
try {
ImageSummaryRead imageSummary = DbImage.getImageSummary(user, imageBaseId);
if (imageSummary.shareMode == ShareMode.DOWNLOAD || imageSummary.shareMode == ShareMode.FROZEN) {
if (newData.shareMode != ShareMode.DOWNLOAD && newData.shareMode != ShareMode.FROZEN) {
- throw new TImageDataException(ImageDataError.INVALID_SHARE_MODE,
+ throw new TInvocationException(InvocationError.INVALID_SHARE_MODE,
"Cannot change share mode from remote to local");
} else {
// Share mode is valid and changed, but ignore all other fields
@@ -269,7 +301,7 @@ public class ServerHandler implements SatelliteServer.Iface {
} else {
// Likewise, if share mode is local or publish, don't allow changing to FROZEN/DOWNLOAD
if (newData.shareMode != ShareMode.LOCAL && newData.shareMode != ShareMode.PUBLISH) {
- throw new TImageDataException(ImageDataError.INVALID_SHARE_MODE,
+ throw new TInvocationException(InvocationError.INVALID_SHARE_MODE,
"Cannot change share mode from local to remote");
}
}
@@ -278,13 +310,13 @@ public class ServerHandler implements SatelliteServer.Iface {
// The update routine will make sure only the super user can change the template flag
DbImage.updateImageMetadata(user, imageBaseId, newData);
} catch (SQLException e1) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void updateImageVersion(String userToken, String imageVersionId, ImageVersionWrite image)
- throws TAuthorizationException, TInternalServerError, TNotFoundException {
+ throws TAuthorizationException, TInvocationException, TNotFoundException {
UserInfo user = SessionManager.getOrFail(userToken);
// Special case: Version is still being uploaded, so there's no entry yet - remember for later
ActiveUpload upload = fileServer.getUploadByToken(imageVersionId);
@@ -303,31 +335,31 @@ public class ServerHandler implements SatelliteServer.Iface {
}
DbImage.updateImageVersion(user, imageVersionId, image);
} catch (SQLException e1) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void deleteImageVersion(String userToken, String imageVersionId) throws TAuthorizationException,
- TNotFoundException, TInternalServerError {
+ TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canDeleteImageVersionOrFail(user, imageVersionId);
try {
DbImage.markForDeletion(imageVersionId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void deleteImageBase(String userToken, String imageBaseId) throws TAuthorizationException,
- TNotFoundException, TInternalServerError {
+ TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
ImageDetailsRead imageDetails;
try {
imageDetails = DbImage.getImageDetails(user, imageBaseId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
User.canDeleteImageOrFail(imageDetails);
String[] ids = new String[imageDetails.versions.size()];
@@ -345,31 +377,31 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public void writeImagePermissions(String userToken, String imageBaseId,
Map<String, ImagePermissions> permissions) throws TAuthorizationException, TNotFoundException,
- TInternalServerError {
+ TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canEditImagePermissionsOrFail(user, imageBaseId);
try {
DbImagePermissions.writeForImageBase(imageBaseId, permissions);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public Map<String, ImagePermissions> getImagePermissions(String userToken, String imageBaseId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError {
+ throws TAuthorizationException, TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
boolean adminOnly = !User.canEditImagePermissions(user, imageBaseId);
try {
return DbImagePermissions.getForImageBase(imageBaseId, adminOnly);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void setImageOwner(String userToken, String imageBaseId, String newOwnerId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError, TException {
+ throws TAuthorizationException, TNotFoundException, TInvocationException, TException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canChangeImageOwnerOrFail(user, imageBaseId);
try {
@@ -380,13 +412,13 @@ public class ServerHandler implements SatelliteServer.Iface {
}
DbImage.setImageOwner(imageBaseId, newOwnerId, user);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void setImageVersionExpiry(String userToken, String imageBaseId, long expireTime)
- throws TAuthorizationException, TNotFoundException, TInternalServerError, TInvalidDateParam,
+ throws TAuthorizationException, TNotFoundException, TInvocationException, TInvalidDateParam,
TException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canChangeImageExpireDateOrFail(user);
@@ -394,113 +426,113 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public String createLecture(String userToken, LectureWrite lecture) throws TAuthorizationException,
- TInternalServerError, TInvalidDateParam {
+ TInvocationException, TInvalidDateParam {
if (lecture == null || lecture.defaultPermissions == null)
- throw new TInternalServerError(); // TODO Own exception for this
+ throw new TInvocationException(); // TODO Own exception for this
UserInfo user = SessionManager.getOrFail(userToken);
User.canCreateLectureOrFail(user);
Sanitizer.handleLectureDates(lecture);
try {
return DbLecture.create(user, lecture);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void updateLecture(String userToken, String lectureId, LectureWrite lecture)
- throws TAuthorizationException, TNotFoundException, TInternalServerError, TInvalidDateParam {
+ throws TAuthorizationException, TNotFoundException, TInvocationException, TInvalidDateParam {
UserInfo user = SessionManager.getOrFail(userToken);
User.canEditLectureOrFail(user, lectureId);
Sanitizer.handleLectureDates(lecture);
try {
DbLecture.update(user, lectureId, lecture);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public List<LectureSummary> getLectureList(String userToken, int page) throws TAuthorizationException,
- TInternalServerError {
+ TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
try {
// If user is student, getAll() will only return lectures where the current linked image is not restricted
return DbLecture.getAll(user, page);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public LectureRead getLectureDetails(String userToken, String lectureId) throws TAuthorizationException,
- TNotFoundException, TInternalServerError {
+ TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canSeeLectureDetailsOrFail(user);
try {
return DbLecture.getLectureDetails(user, lectureId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void deleteLecture(String userToken, String lectureId) throws TAuthorizationException,
- TNotFoundException, TInternalServerError {
+ TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canDeleteLectureOrFail(user, lectureId);
try {
if (!DbLecture.delete(lectureId))
throw new TNotFoundException();
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void writeLecturePermissions(String userToken, String lectureId,
Map<String, LecturePermissions> permissions) throws TAuthorizationException, TNotFoundException,
- TInternalServerError {
+ TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canEditLecturePermissionsOrFail(user, lectureId);
try {
DbLecturePermissions.writeForLecture(lectureId, permissions);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public Map<String, LecturePermissions> getLecturePermissions(String userToken, String lectureId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError {
+ throws TAuthorizationException, TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
boolean adminOnly = !User.canEditLecturePermissions(user, lectureId);
try {
return DbLecturePermissions.getForLecture(lectureId, adminOnly);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void setLectureOwner(String userToken, String lectureId, String newOwnerId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError, TException {
+ throws TAuthorizationException, TNotFoundException, TInvocationException, TException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canChangeLectureOwnerOrFail(user, lectureId);
try {
DbLecture.setOwner(user, lectureId, newOwnerId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public List<UserInfo> getUserList(String userToken, int page) throws TAuthorizationException,
- TInternalServerError {
+ TInvocationException {
try {
return DbUser.getAll(page);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}