summaryrefslogtreecommitdiffstats
path: root/dozentenmodul
diff options
context:
space:
mode:
authorStephan Schwaer2015-08-28 16:58:00 +0200
committerStephan Schwaer2015-08-28 16:58:00 +0200
commit8710c9336b11d966dc64c60660ac5bd3b02aacf8 (patch)
treeaf8540200eca6dd14c5ec1993a1349674b312184 /dozentenmodul
parent[client] info message in Image Upload Page. (diff)
parent[client] Clean up initDownload (diff)
downloadtutor-module-8710c9336b11d966dc64c60660ac5bd3b02aacf8.tar.gz
tutor-module-8710c9336b11d966dc64c60660ac5bd3b02aacf8.tar.xz
tutor-module-8710c9336b11d966dc64c60660ac5bd3b02aacf8.zip
Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1
Diffstat (limited to 'dozentenmodul')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java15
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java335
2 files changed, 213 insertions, 137 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
index a7fd9b27..93dff0ab 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
@@ -47,7 +47,7 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
* The image table held by the ImageListViewer
*/
public final ImageTable imageTable = imageListViewer.getImageTable();
-
+
/**
* Popup menu items
*/
@@ -209,7 +209,6 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
return true;
}
-
/**
* Updates the buttons/popup menu items according to the user's permissions
*
@@ -253,13 +252,14 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
private void openImageDetails(ImageSummaryRead image) {
if (image == null)
return;
- ImageDetailsWindow.open((JFrame) SwingUtilities.getWindowAncestor(me),
- image.getImageBaseId(), new ImageUpdatedCallback() {
+ ImageDetailsWindow.open((JFrame) SwingUtilities.getWindowAncestor(me), image.getImageBaseId(),
+ new ImageUpdatedCallback() {
public void updated() {
imageListViewer.refreshList(true, 100);
}
});
}
+
/**
* Triggers a download of the given image's latest version
*
@@ -281,7 +281,12 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
@Override
public void downloadInitialized(boolean success) {
if (!success) {
- imageListViewer.refreshList(true, 1000);
+ Gui.asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ imageListViewer.refreshList(true, 1000);
+ }
+ });
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
index dddb6de5..e4ebad31 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
@@ -38,12 +38,11 @@ import org.openslx.dozmod.filetransfer.DownloadTask;
import org.openslx.dozmod.filetransfer.UploadTask;
import org.openslx.dozmod.gui.GraphicalCertHandler;
import org.openslx.dozmod.gui.Gui;
-import org.openslx.dozmod.gui.Gui.GuiCallable;
import org.openslx.dozmod.gui.MainWindow;
import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.helper.QFileChooser;
-import org.openslx.sat.thrift.version.Version;
import org.openslx.dozmod.util.FormatHelper;
+import org.openslx.sat.thrift.version.Version;
import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
@@ -52,6 +51,8 @@ import org.openslx.util.Util;
public class ThriftActions {
private static final Logger LOGGER = Logger.getLogger(ThriftActions.class);
+ private static final long SIZE_CHECK_EXTRA_DL = 50l * 1024l * 1024l;
+ private static final long SIZE_CHECK_EXTRA_UL = 150l * 1024l * 1024l;
/* *******************************************************************************
*
@@ -62,7 +63,8 @@ public class ThriftActions {
********************************************************************************/
/**
* @param frame to show user feedback on
- * @param data AuthenticationData as received from a successfull login, or null if trying to resume a saved sessions
+ * @param data AuthenticationData as received from a successfull login, or
+ * null if trying to resume a saved sessions
* @return true if initiliazing the session worked, false otherwise
*/
public static boolean initSession(final Frame frame, AuthenticationData data) {
@@ -91,8 +93,8 @@ public class ThriftActions {
masterToken = data.masterToken;
}
// try to get a new client
- client = ThriftManager.getNewSatelliteClient(GraphicalCertHandler.getSslContext(address),
- address, App.THRIFT_SSL_PORT, App.THRIFT_TIMEOUT_MS);
+ client = ThriftManager.getNewSatelliteClient(GraphicalCertHandler.getSslContext(address), address,
+ App.THRIFT_SSL_PORT, App.THRIFT_TIMEOUT_MS);
if (client == null)
return false;
@@ -107,11 +109,10 @@ public class ThriftActions {
if (remoteVersion != Version.VERSION) {
Gui.showMessageBox(frame,
"Das von Ihnen verwendete Dozentenmodul ist nicht mit dem Satelliten-Server kompatibel.\n"
- + "Ihre Version: " + Version.VERSION + "\n"
- + "Satelliten-Version: " + remoteVersion,
- MessageType.ERROR, LOGGER, null);
+ + "Ihre Version: " + Version.VERSION + "\n" + "Satelliten-Version: "
+ + remoteVersion, MessageType.ERROR, LOGGER, null);
return false;
- }
+ }
// all good, try to get the whoami info
try {
whoami = client.whoami(satToken);
@@ -128,13 +129,12 @@ public class ThriftActions {
MessageType.ERROR, LOGGER, e);
return false;
} catch (Exception e) {
- Gui.showMessageBox(
- frame,
+ Gui.showMessageBox(frame,
"Authentifizierung erfolgreich, aber der Satellit akzeptiert das Sitzungstoken nicht.",
MessageType.ERROR, LOGGER, e);
return false;
}
-
+
if (whoami != null) {
Session.initialize(whoami, address, satToken, masterToken);
ThriftManager.setSatelliteAddress(
@@ -144,6 +144,7 @@ public class ThriftActions {
}
return false;
}
+
/* *******************************************************************************
*
* IMAGE CREATION
@@ -153,7 +154,8 @@ public class ThriftActions {
********************************************************************************/
/**
* GUI-BLOCKING
- * Creates the image with the given name. Returns the uuid returned by the server
+ * Creates the image with the given name. Returns the uuid returned by the
+ * server
*
* @param frame calling this action
* @return uuid as String, or null if the creation failed
@@ -165,23 +167,25 @@ public class ThriftActions {
} catch (TException e) {
ThriftError.showMessage(frame, LOGGER, e, "Erstellen des Images fehlgeschlagen");
} catch (Exception e) {
- Gui.showMessageBox(frame, "Unbekannter Fehler beim Erstellen der VM", MessageType.ERROR,
- LOGGER, e);
+ Gui.showMessageBox(frame, "Unbekannter Fehler beim Erstellen der VM", MessageType.ERROR, LOGGER,
+ e);
}
return uuid;
}
+
/**
* GUI-BLOCKING
- * Pushes a new image base to the server with the given imageBaseId and the meta information in meta
+ * Pushes a new image base to the server with the given imageBaseId and the
+ * meta information in meta
*
* @param frame to show user feedback on
* @param imageBaseId image's id we are writing meta information of
* @param meta actual meta information as ImageBaseWrite
*/
- public static boolean updateImageBase(final Frame frame, final String imageBaseId, final ImageBaseWrite meta) {
+ public static boolean updateImageBase(final Frame frame, final String imageBaseId,
+ final ImageBaseWrite meta) {
try {
- ThriftManager.getSatClient().updateImageBase(Session.getSatelliteToken(),
- imageBaseId, meta);
+ ThriftManager.getSatClient().updateImageBase(Session.getSatelliteToken(), imageBaseId, meta);
} catch (TException e) {
ThriftError.showMessage(frame, LOGGER, e, "Konnte Metadaten des Images nicht übertragen");
return false;
@@ -191,16 +195,18 @@ public class ThriftActions {
/**
* GUI-BLOCKING
- * Pushes the given permission map as custom permission for the given imageBaseId
+ * Pushes the given permission map as custom permission for the given
+ * imageBaseId
*
* @param frame to show user feedback on
* @param imageBaseId image's id we are writing permissions of
* @param permissions actual permissions map to write
*/
- public static void writeImagePermissions(final Frame frame, final String imageBaseId, final Map<String, ImagePermissions> permissions) {
+ public static void writeImagePermissions(final Frame frame, final String imageBaseId,
+ final Map<String, ImagePermissions> permissions) {
try {
- ThriftManager.getSatClient().writeImagePermissions(Session.getSatelliteToken(),
- imageBaseId, permissions);
+ ThriftManager.getSatClient().writeImagePermissions(Session.getSatelliteToken(), imageBaseId,
+ permissions);
} catch (TException e) {
ThriftError.showMessage(frame, LOGGER, e, "Konnte Berechtigungen nicht übertragen");
}
@@ -217,7 +223,8 @@ public class ThriftActions {
********************************************************************************/
/**
* GUI-BLOCKING
- * Request the upload of an image version. Returns the TransferInformation received by the server
+ * Request the upload of an image version. Returns the TransferInformation
+ * received by the server
* or null if the request failed. Will give user feedback about failures.
*
* @param frame caller of this method
@@ -226,27 +233,28 @@ public class ThriftActions {
* @param blockHashes
* @param machineDescription
* @param callback
- * @return TransferInformation received by the server, null if the request failed.
+ * @return TransferInformation received by the server, null if the request
+ * failed.
*/
public static TransferInformation requestVersionUpload(final Frame frame, final String imageBaseId,
- final long fileSize, final List<ByteBuffer> blockHashes,
- final ByteBuffer machineDescription) {
+ final long fileSize, final List<ByteBuffer> blockHashes, final ByteBuffer machineDescription) {
try {
- if (ThriftManager.getSatClient().getStatus().getAvailableStorageBytes() < fileSize){
- Gui.showMessageBox(frame, "Nicht genügend Speicherplatz Satelliten. Löschen Sie nicht verwendete Imageversionen oder kontaktieren sie den Administrator.", MessageType.ERROR, LOGGER, null);
+ if (ThriftManager.getSatClient().getStatus().getAvailableStorageBytes() < fileSize
+ + SIZE_CHECK_EXTRA_UL) {
+ Gui.showMessageBox(
+ frame,
+ "Nicht genügend Speicherplatz Satelliten. Löschen Sie nicht verwendete Imageversionen oder kontaktieren sie den Administrator.",
+ MessageType.ERROR, LOGGER, null);
return null;
}
} catch (TException e1) {
- ThriftError.showMessage(frame, LOGGER, e1, "Konnte Status des Satelliten nicht abfragen!");
+ ThriftError.showMessage(frame, LOGGER, e1, "Konnte Status des Satelliten nicht abfragen!");
return null;
}
TransferInformation ti = null;
try {
- ti = ThriftManager.getSatClient().requestImageVersionUpload(
- Session.getSatelliteToken(),
- imageBaseId,
- fileSize,
- null, // TODO remove deprecated parameter
+ ti = ThriftManager.getSatClient().requestImageVersionUpload(Session.getSatelliteToken(),
+ imageBaseId, fileSize, null, // TODO remove deprecated parameter
machineDescription);
LOGGER.info("Version upload granted, versionId: '" + ti.toString());
} catch (TAuthorizationException e) {
@@ -259,26 +267,28 @@ public class ThriftActions {
/**
* GUI-BLOCKING
- * Starts uploading the given diskFile using the transferInformation and hashGen
- *
+ * Starts uploading the given diskFile using the transferInformation and
+ * hashGen
+ *
* @param frame caller of this method
* @param transferInformation transfer information to use for the upload
* @param hashGen hash generator for this file
* @param diskFile the file to upload
- * @return UploadTask if the uploading initialized, or null if uploading failed
+ * @return UploadTask if the uploading initialized, or null if uploading
+ * failed
*/
- public static InitUploadStatus initUpload(final Frame frame, final TransferInformation transferInformation,
- final File diskFile) {
+ public static InitUploadStatus initUpload(final Frame frame,
+ final TransferInformation transferInformation, final File diskFile) {
UploadTask uploadTask = null;
// do actually start the upload now
LOGGER.debug("Starting upload for: " + diskFile.toPath());
try {
- uploadTask = new UploadTask(Session.getSatelliteAddress(),
- transferInformation.getPlainPort(), transferInformation.getToken(),
- diskFile);
+ uploadTask = new UploadTask(Session.getSatelliteAddress(), transferInformation.getPlainPort(),
+ transferInformation.getToken(), diskFile);
} catch (FileNotFoundException e) {
- Gui.asyncMessageBox("Kann VM nicht hochladen: Datei nicht gefunden\n\n"
- + diskFile.getAbsolutePath(), MessageType.ERROR, LOGGER, e);
+ Gui.asyncMessageBox(
+ "Kann VM nicht hochladen: Datei nicht gefunden\n\n" + diskFile.getAbsolutePath(),
+ MessageType.ERROR, LOGGER, e);
return null;
}
AsyncHashGenerator hashGen = null;
@@ -313,23 +323,23 @@ public class ThriftActions {
* GUI-BLOCKING
* Gives user feedback
* TODO
+ *
* @param frame
* @param transferInformation
* @param versionInfo
*/
- public static boolean updateImageVersion(final Frame frame,
- final String versionId, final ImageVersionWrite versionInfo){
- try {
- ThriftManager.getSatClient().updateImageVersion(Session.getSatelliteToken(),
- versionId,
+ public static boolean updateImageVersion(final Frame frame, final String versionId,
+ final ImageVersionWrite versionInfo) {
+ try {
+ ThriftManager.getSatClient().updateImageVersion(Session.getSatelliteToken(), versionId,
versionInfo);
} catch (TException e) {
- Gui.showMessageBox(frame, "Konnte neue Version nicht erstellen!",
- MessageType.ERROR, LOGGER, e);
+ Gui.showMessageBox(frame, "Konnte neue Version nicht erstellen!", MessageType.ERROR, LOGGER, e);
return false;
}
return true;
}
+
/* *******************************************************************************
*
* IMAGE VERSION DOWNLOAD
@@ -339,7 +349,8 @@ public class ThriftActions {
*
********************************************************************************/
/**
- * The callback interface to inform the GUI about the status of the operation
+ * The callback interface to inform the GUI about the status of the
+ * operation
*/
public interface DownloadCallback {
void downloadInitialized(boolean success);
@@ -347,7 +358,8 @@ public class ThriftActions {
/**
* NON-BLOCKING
- * Initialises the download of the given imageVersionId saving it to the given
+ * Initialises the download of the given imageVersionId saving it to the
+ * given
* imageName
*
* @param frame caller of this method
@@ -355,30 +367,63 @@ public class ThriftActions {
* @param imageName destination file name
* @param virtualizerId id of the virtualizer
* @param imageSize size in bytes of the image to download
- * @param callback callback function to return status of this operation to the GUI
+ * @param callback callback function to return status of this operation to
+ * the GUI
*/
public static void initDownload(final Frame frame, final String imageVersionId, final String imageName,
final String virtualizerId, final long imageSize, final DownloadCallback callback) {
+ // TODO: Return value? Callback?
QFileChooser fc = new QFileChooser(Config.getDownloadPath(), true);
fc.setDialogTitle("Bitte wählen Sie einen Speicherort");
int action = fc.showSaveDialog(frame);
- final File file = fc.getSelectedFile();
- if (action != JFileChooser.APPROVE_OPTION || file == null)
+ File selected = fc.getSelectedFile();
+ if (action != JFileChooser.APPROVE_OPTION || selected == null)
return;
+ final File destDir = new File(selected, generateDirname(imageName, imageVersionId));
+ destDir.getAbsoluteFile().mkdirs();
+ final File diskFile = new File(destDir.getAbsolutePath(), generateFilename(imageName, virtualizerId));
+
+ if (diskFile.exists()) {
+ boolean ret = Gui.showMessageBox(frame, "Datei '" + diskFile.getAbsolutePath()
+ + "' existiert bereits, wollen Sie sie überschreiben?", MessageType.QUESTION_YESNO,
+ LOGGER, null);
+ if (!ret) {
+ // user aborted
+ return;
+ }
+ // delete it
+ if (!diskFile.delete() && diskFile.exists()) {
+ Gui.showMessageBox(frame, "Datei konnte nicht überschrieben werden!", MessageType.ERROR,
+ LOGGER, null);
+ return;
+ }
+ }
+
// Check the free space on disk
- if(file.getUsableSpace() < imageSize) {
- Gui.showMessageBox(frame, "Nicht genügend Speicherplatz im ausgewählten Verzeichnis verfügbar.", MessageType.ERROR, LOGGER, null);
+ if (destDir.getUsableSpace() < imageSize + SIZE_CHECK_EXTRA_DL) {
+ Gui.showMessageBox(frame, "Nicht genügend Speicherplatz im ausgewählten Verzeichnis verfügbar.\n"
+ + "Brauche: " + FormatHelper.bytes(imageSize + SIZE_CHECK_EXTRA_DL, false) + "\n"
+ + "Habe: " + FormatHelper.bytes(destDir.getUsableSpace(), false), MessageType.ERROR,
+ LOGGER, null);
+ return;
+ }
+
+ try {
+ diskFile.createNewFile();
+ } catch (IOException e) {
+ Gui.showMessageBox(frame, "Kann die Datei\n" + diskFile.getAbsolutePath() + "\nnicht erzeugen.",
+ MessageType.ERROR, LOGGER, e);
return;
}
QuickTimer.scheduleOnce(new Task() {
@Override
public void fire() {
- final TransferInformation transInf;
+ TransferInformation transInf;
try {
- transInf = ThriftManager.getSatClient()
- .requestDownload(Session.getSatelliteToken(), imageVersionId);
+ transInf = ThriftManager.getSatClient().requestDownload(Session.getSatelliteToken(),
+ imageVersionId);
} catch (TException e) {
ThriftError.showMessage(frame, LOGGER, e, "Die Download-Anfrage ist gescheitert");
if (callback != null)
@@ -386,41 +431,13 @@ public class ThriftActions {
return;
}
- File df = null;
- try {
- file.getAbsoluteFile().mkdirs();
- df = new File(file.getAbsolutePath(), generateFilename(imageName, virtualizerId));
- final File ff = df;
- if (df.exists()) {
- if (!Gui.syncExec(new GuiCallable<Boolean>() {
- @Override
- public Boolean run() {
- return Gui.showMessageBox(frame,
- "Datei '" + ff.getAbsolutePath() + "' existiert bereits, wollen Sie sie überschreiben?", MessageType.QUESTION_YESNO, LOGGER, null);
- }
- })) {
- // user aborted
- return;
- } else {
- // delete it
- if (!df.delete()) {
- // TODO what?
- Gui.showMessageBox(frame, "Datei konnte nicht überschrieben werden!", MessageType.ERROR, LOGGER, null);
- return;
- }
- }
- }
- df.createNewFile();
- } catch (IOException e) {
- LOGGER.warn("Cannot prepare download destination", e);
- }
- final File destFile = df;
final DownloadTask dlTask;
try {
- dlTask = new DownloadTask(Session.getSatelliteAddress(), transInf.getPlainPort(), transInf
- .getToken(), destFile, imageSize, null);
- } catch (final FileNotFoundException e) {
- Gui.asyncMessageBox("Konnte Download nicht vorbereiten: Der gewählte Zielort ist nicht beschreibbar",
+ dlTask = new DownloadTask(Session.getSatelliteAddress(), transInf.getPlainPort(),
+ transInf.getToken(), diskFile, imageSize, null);
+ } catch (FileNotFoundException e) {
+ Gui.asyncMessageBox(
+ "Konnte Download nicht vorbereiten: Der gewählte Zielort ist nicht beschreibbar",
MessageType.ERROR, LOGGER, e);
if (callback != null)
callback.downloadInitialized(false);
@@ -431,17 +448,29 @@ public class ThriftActions {
Gui.asyncExec(new Runnable() {
@Override
public void run() {
- Config.setDownloadPath(file.getAbsolutePath());
- MainWindow.addDownload(imageName, destFile.getName(), dlTask);
- if (callback != null)
- callback.downloadInitialized(true);
+ MainWindow.addDownload(imageName, diskFile.getName(), dlTask);
}
});
+
+ Config.setDownloadPath(destDir.getAbsolutePath());
+ if (callback != null)
+ callback.downloadInitialized(true);
}
});
}
+
+ private static String generateDirname(String imageName, String imageVersionId) {
+ String fileName = imageName.replaceAll("[^a-zA-Z0-9_\\.\\-]+", "_");
+ if (fileName.length() > 50) {
+ fileName = fileName.substring(0, 50);
+ }
+ fileName += "--" + imageVersionId.substring(0, 8);
+ return fileName;
+ }
+
/**
- * Generates a filename based on the given imageName and with the proper extension
+ * Generates a filename based on the given imageName and with the proper
+ * extension
* depending on the virtualizer
*
* @param imageName
@@ -480,21 +509,23 @@ public class ThriftActions {
public static ImageDetailsRead getImageDetails(final Frame frame, final String imageBaseId) {
ImageDetailsRead details = null;
try {
- details = ThriftManager.getSatClient().getImageDetails(Session.getSatelliteToken(),
- imageBaseId);
+ details = ThriftManager.getSatClient().getImageDetails(Session.getSatelliteToken(), imageBaseId);
} catch (TException e) {
ThriftError.showMessage(frame, LOGGER, e, "Fehler beim Lesen der Metadaten");
}
return details;
}
+
/**
* @param frame
* @param imageBaseId
* @param callback
*/
- public static void getImageDetails(final Frame frame, final String imageBaseId, final ImageMetaCallback callback) {
+ public static void getImageDetails(final Frame frame, final String imageBaseId,
+ final ImageMetaCallback callback) {
QuickTimer.scheduleOnce(new Task() {
ImageDetailsRead details = null;
+
@Override
public void fire() {
details = ThriftActions.getImageDetails(frame, imageBaseId);
@@ -509,10 +540,13 @@ public class ThriftActions {
}
});
}
- public static void getImageFullDetails(final Frame frame, final String imageBaseId, final ImageMetaCallback callback) {
+
+ public static void getImageFullDetails(final Frame frame, final String imageBaseId,
+ final ImageMetaCallback callback) {
QuickTimer.scheduleOnce(new Task() {
ImageDetailsRead details = null;
Map<String, ImagePermissions> permissions = null;
+
@Override
public void fire() {
// sync calls
@@ -531,9 +565,11 @@ public class ThriftActions {
}
// async
- public static void getImagePermissions(final Frame frame, final String imageBaseId, final ImageMetaCallback callback) {
+ public static void getImagePermissions(final Frame frame, final String imageBaseId,
+ final ImageMetaCallback callback) {
QuickTimer.scheduleOnce(new Task() {
Map<String, ImagePermissions> permissionMap = null;
+
@Override
public void fire() {
permissionMap = ThriftActions.getImagePermissions(frame, imageBaseId);
@@ -548,16 +584,20 @@ public class ThriftActions {
}
});
}
+
// sync
- public static Map<String, ImagePermissions> getImagePermissions(final Frame frame, final String imageBaseId) {
+ public static Map<String, ImagePermissions> getImagePermissions(final Frame frame,
+ final String imageBaseId) {
Map<String, ImagePermissions> permissionMap = null;
try {
- permissionMap = ThriftManager.getSatClient().getImagePermissions(Session.getSatelliteToken(), imageBaseId);
+ permissionMap = ThriftManager.getSatClient().getImagePermissions(Session.getSatelliteToken(),
+ imageBaseId);
} catch (TException e) {
ThriftError.showMessage(frame, LOGGER, e, "Fehler beim Lesen der Metadaten");
}
return permissionMap;
}
+
/**
* GUI-BLOCKING
* Sets the owner of the given lectureId to newOwner
@@ -569,14 +609,15 @@ public class ThriftActions {
*/
public static boolean setImageOwner(final Frame frame, final String lectureId, final UserInfo newOwner) {
try {
- ThriftManager.getSatClient().setImageOwner(Session.getSatelliteToken(),
- lectureId, newOwner.getUserId());
+ ThriftManager.getSatClient().setImageOwner(Session.getSatelliteToken(), lectureId,
+ newOwner.getUserId());
} catch (TException e) {
ThriftError.showMessage(frame, LOGGER, e, "Fehler beim Übertragen der Besitzrechte");
return false;
}
return true;
}
+
/* *******************************************************************************
*
* IMAGE / VERSION DELETION
@@ -585,7 +626,7 @@ public class ThriftActions {
*
********************************************************************************/
/**
- * Delete callback interface to be implemented by callers of
+ * Delete callback interface to be implemented by callers of
* ThriftActions.deleteImageVersion(..)
*/
public interface DeleteCallback {
@@ -596,7 +637,9 @@ public class ThriftActions {
*/
void isDeleted(boolean success);
}
- public static void deleteImageBase(final Frame frame, final String imageBaseId, final DeleteCallback callback) {
+
+ public static void deleteImageBase(final Frame frame, final String imageBaseId,
+ final DeleteCallback callback) {
if (imageBaseId == null || imageBaseId.isEmpty())
return;
// first look if we have versions
@@ -604,7 +647,8 @@ public class ThriftActions {
List<LectureSummary> lecturesToBeDeleted = new ArrayList<>();
try {
details = ThriftManager.getSatClient().getImageDetails(Session.getSatelliteToken(), imageBaseId);
- List<LectureSummary> lectureList = ThriftManager.getSatClient().getLectureList(Session.getSatelliteToken(), 100);
+ List<LectureSummary> lectureList = ThriftManager.getSatClient().getLectureList(
+ Session.getSatelliteToken(), 100);
for (LectureSummary lecture : lectureList) {
if (lecture.getImageBaseId().equals(imageBaseId)) {
lecturesToBeDeleted.add(lecture);
@@ -637,17 +681,22 @@ public class ThriftActions {
}
}
}
+
/**
* NON-BLOCKING
- * Deletes either an image base or an image version depending on the parameters.
- * To delete an image base, give the imageBaseId and let imageVersionId be null.
+ * Deletes either an image base or an image version depending on the
+ * parameters.
+ * To delete an image base, give the imageBaseId and let imageVersionId be
+ * null.
* To delete an image version, set both imageBaseId and imageVersionId.
- * The success of the operation will be forwarded to the GUI through the DeleteCallback.
+ * The success of the operation will be forwarded to the GUI through the
+ * DeleteCallback.
*
* @param frame next parent frame of the caller of this method
* @param imageBaseId uuid of the image that belongs to the version
* @param imageVersionId id of the image version to be deleted
- * @param callback called to inform the GUI about the deletion status (see DeleteCallback interface)
+ * @param callback called to inform the GUI about the deletion status (see
+ * DeleteCallback interface)
*/
public static void deleteImageVersion(final Frame frame, final String imageVersionId,
final DeleteCallback callback) {
@@ -722,23 +771,28 @@ public class ThriftActions {
}
return uuid;
}
+
/**
* GUI-BLOCKING
- * Writes custom lecture permissions (permissions param) for the given lectureId.
+ * Writes custom lecture permissions (permissions param) for the given
+ * lectureId.
*
* @param frame to show user feedback on
* @param lectureId lecture's id to write custom permissions for
* @param permissions actual permission map to push
*/
- public static boolean writeLecturePermissions(final Frame frame, final String lectureId, final Map<String, LecturePermissions> permissions) {
+ public static boolean writeLecturePermissions(final Frame frame, final String lectureId,
+ final Map<String, LecturePermissions> permissions) {
try {
- ThriftManager.getSatClient().writeLecturePermissions(Session.getSatelliteToken(), lectureId, permissions);
+ ThriftManager.getSatClient().writeLecturePermissions(Session.getSatelliteToken(), lectureId,
+ permissions);
} catch (TException e) {
ThriftError.showMessage(frame, LOGGER, e, "Failed to write lecture permissions");
return false;
}
return true;
}
+
/* *******************************************************************************
*
* LECTURE METADATA
@@ -748,19 +802,23 @@ public class ThriftActions {
********************************************************************************/
/**
* @author joe
- *
+ *
*/
public interface LectureMetaCallback {
void fetchedLectureDetails(LectureRead lecture, ImageDetailsRead image);
+
void fetchedLecturePermissions(Map<String, LecturePermissions> permissions);
}
+
/**
* NON-BLOCKING
+ *
* @param frame
* @param lectureId
* @param callback
*/
- public static void getLectureWithImageDetails(final Frame frame, final String lectureId, final LectureMetaCallback callback) {
+ public static void getLectureWithImageDetails(final Frame frame, final String lectureId,
+ final LectureMetaCallback callback) {
QuickTimer.scheduleOnce(new Task() {
@Override
public void fire() {
@@ -783,8 +841,10 @@ public class ThriftActions {
}
});
}
+
/**
* GUI-BLOCKING
+ *
* @param frame
* @param lectureId
* @param callback
@@ -806,35 +866,40 @@ public class ThriftActions {
* @param frame to show user feedback on
* @param lectureId lecture's is to update
* @param lecture LectureWrite data to update the lecture with
- * @return
+ * @return
*/
- public static boolean updateLecture(final Frame frame, final String lectureId, final LectureWrite lectureWrite) {
+ public static boolean updateLecture(final Frame frame, final String lectureId,
+ final LectureWrite lectureWrite) {
try {
- ThriftManager.getSatClient().updateLecture(Session.getSatelliteToken(),
- lectureId, lectureWrite);
+ ThriftManager.getSatClient().updateLecture(Session.getSatelliteToken(), lectureId, lectureWrite);
} catch (TException e) {
ThriftError.showMessage(frame, LOGGER, e, "Fehler beim Updaten der Veranstaltung");
return false;
}
return true;
}
+
/**
* GUI-BLOCKING
+ *
* @param frame
* @param lectureId
* @param callback
*/
- public static Map<String, LecturePermissions> getLecturePermissions(final Frame frame, final String lectureId) {
+ public static Map<String, LecturePermissions> getLecturePermissions(final Frame frame,
+ final String lectureId) {
Map<String, LecturePermissions> permissions = null;
try {
- permissions = ThriftManager.getSatClient().getLecturePermissions(Session.getSatelliteToken(), lectureId);
+ permissions = ThriftManager.getSatClient().getLecturePermissions(Session.getSatelliteToken(),
+ lectureId);
} catch (TException e) {
ThriftError.showMessage(frame, LOGGER, e, "Konnte Veranstaltungdaten nicht abrufen");
}
return permissions;
}
+
/**
* GUI-BLOCKING
* Sets the owner of the given lectureId to newOwner
@@ -846,14 +911,15 @@ public class ThriftActions {
*/
public static boolean setLectureOwner(final Frame frame, final String lectureId, final UserInfo newOwner) {
try {
- ThriftManager.getSatClient().setLectureOwner(Session.getSatelliteToken(),
- lectureId, newOwner.getUserId());
+ ThriftManager.getSatClient().setLectureOwner(Session.getSatelliteToken(), lectureId,
+ newOwner.getUserId());
} catch (TException e) {
ThriftError.showMessage(frame, LOGGER, e, "Fehler beim Übertragen der Besitzrechte");
return false;
}
return true;
}
+
/* *******************************************************************************
*
* LECTURE DELETION
@@ -864,11 +930,14 @@ public class ThriftActions {
public interface DeleteLectureCallback {
void deleted(boolean success);
}
- public static void deleteLecture(final Frame frame, final String lectureId, final DeleteLectureCallback callback) {
+
+ public static void deleteLecture(final Frame frame, final String lectureId,
+ final DeleteLectureCallback callback) {
if (lectureId == null)
return;
QuickTimer.scheduleOnce(new Task() {
boolean success = false;
+
@Override
public void fire() {
try {
@@ -888,12 +957,13 @@ public class ThriftActions {
}
});
}
+
/* *******************************************************************************
*
* PRIVATE HELPERS
*
********************************************************************************/
- /**
+ /**
* Helper to ask the user for confirmation. Returns his choice.
*
* @param frame frame to show this message box on
@@ -906,11 +976,12 @@ public class ThriftActions {
/**
* Wrapper class for UploadTask & AsyncHashGenerator
- *
+ *
*/
public static class InitUploadStatus {
public final UploadTask task;
public final AsyncHashGenerator hasher;
+
public InitUploadStatus(final UploadTask task, final AsyncHashGenerator hasher) {
this.task = task;
this.hasher = hasher;