summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java
diff options
context:
space:
mode:
authorJonathan Bauer2015-08-21 16:23:42 +0200
committerJonathan Bauer2015-08-21 16:23:42 +0200
commit64479706808b0ff0d37ef16dd98554bec2435715 (patch)
tree10d3060e95be6328cd041180eafb18a9386b0bfd /dozentenmodul/src/main/java
parent[client] more ThriftActions (diff)
downloadtutor-module-64479706808b0ff0d37ef16dd98554bec2435715.tar.gz
tutor-module-64479706808b0ff0d37ef16dd98554bec2435715.tar.xz
tutor-module-64479706808b0ff0d37ef16dd98554bec2435715.zip
[client] minor code restructure
Diffstat (limited to 'dozentenmodul/src/main/java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java281
1 files changed, 153 insertions, 128 deletions
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 be4caa2b..e6ae11fc 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
@@ -44,132 +44,6 @@ public class ThriftActions {
/* *******************************************************************************
*
- * IMAGE VERSION DOWNLOAD
- *
- * Download image version action composed of the interface 'DownloadCallback'
- * and the actual static method 'initDownload' to start the download.
- *
- ********************************************************************************/
- /**
- * The callback interface to inform the GUI about the status of the operation
- */
- public interface DownloadCallback {
- void downloadInitialized(boolean success);
- }
- /**
- * NON-BLOCKING
- * Initializes the download of the given imageVersionId saving it to the given
- * imageName
- *
- * @param frame caller of this method
- * @param imageVersionId image version id to download
- * @param imageName destination file name
- * @param virtualizerId id of the virtualizer
- * @param imageSize size in bytes of the image to be downloaded
- * @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) {
- 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)
- return;
-
- QuickTimer.scheduleOnce(new Task() {
- @Override
- public void fire() {
- final TransferInformation transInf;
- try {
- transInf = ThriftManager.getSatClient()
- .requestDownload(Session.getSatelliteToken(), imageVersionId);
- } catch (TException e) {
- ThriftError.showMessage(frame, LOGGER, e, "Die Download-Anfrage ist gescheitert");
- if (callback != null)
- callback.downloadInitialized(false);
- 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",
- MessageType.ERROR, LOGGER, e);
- if (callback != null)
- callback.downloadInitialized(false);
- return;
- }
- new Thread(dlTask).start();
-
- Gui.asyncExec(new Runnable() {
- @Override
- public void run() {
- Config.setDownloadPath(file.getAbsolutePath());
- MainWindow.addDownload(imageName, destFile.getName(), dlTask);
- if (callback != null)
- callback.downloadInitialized(true);
- }
- });
- }
- });
- }
- /**
- * Generates a filename based on the given imageName and with the proper extension
- * depending on the virtualizer
- *
- * @param imageName
- * @param virtualizerId
- * @return the generated name as String
- */
- private static String generateFilename(String imageName, String virtualizerId) {
- String fileName = imageName.replaceAll("[^a-zA-Z0-9_\\.\\-]+", "_");
- if (fileName.length() > 50) {
- fileName = fileName.substring(0, 50);
- }
- if ("vmware".equals(virtualizerId)) {
- fileName += ".vmdk";
- } else if ("virtualbox".equals(virtualizerId)) {
- fileName += ".vdi";
- } else {
- fileName += ".img";
- }
- return fileName;
- }
-
- /* *******************************************************************************
- *
* IMAGE CREATION
*
* Creates a base image with the given name
@@ -341,19 +215,152 @@ public class ThriftActions {
}
Gui.showMessageBox(frame, "Neue Version erfolgreich erstellt", MessageType.INFO, LOGGER, null);
}
+ /* *******************************************************************************
+ *
+ * IMAGE VERSION DOWNLOAD
+ *
+ * Download image version action composed of the interface 'DownloadCallback'
+ * and the actual static method 'initDownload' to start the download.
+ *
+ ********************************************************************************/
+ /**
+ * The callback interface to inform the GUI about the status of the operation
+ */
+ public interface DownloadCallback {
+ void downloadInitialized(boolean success);
+ }
+ /**
+ * NON-BLOCKING
+ * Initializes the download of the given imageVersionId saving it to the given
+ * imageName
+ *
+ * @param frame caller of this method
+ * @param imageVersionId image version id to download
+ * @param imageName destination file name
+ * @param virtualizerId id of the virtualizer
+ * @param imageSize size in bytes of the image to be downloaded
+ * @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) {
+ 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)
+ return;
+
+ QuickTimer.scheduleOnce(new Task() {
+ @Override
+ public void fire() {
+ final TransferInformation transInf;
+ try {
+ transInf = ThriftManager.getSatClient()
+ .requestDownload(Session.getSatelliteToken(), imageVersionId);
+ } catch (TException e) {
+ ThriftError.showMessage(frame, LOGGER, e, "Die Download-Anfrage ist gescheitert");
+ if (callback != null)
+ callback.downloadInitialized(false);
+ 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",
+ MessageType.ERROR, LOGGER, e);
+ if (callback != null)
+ callback.downloadInitialized(false);
+ return;
+ }
+ new Thread(dlTask).start();
+
+ Gui.asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ Config.setDownloadPath(file.getAbsolutePath());
+ MainWindow.addDownload(imageName, destFile.getName(), dlTask);
+ if (callback != null)
+ callback.downloadInitialized(true);
+ }
+ });
+ }
+ });
+ }
+ /**
+ * Generates a filename based on the given imageName and with the proper extension
+ * depending on the virtualizer
+ *
+ * @param imageName
+ * @param virtualizerId
+ * @return the generated name as String
+ */
+ private static String generateFilename(String imageName, String virtualizerId) {
+ String fileName = imageName.replaceAll("[^a-zA-Z0-9_\\.\\-]+", "_");
+ if (fileName.length() > 50) {
+ fileName = fileName.substring(0, 50);
+ }
+ if ("vmware".equals(virtualizerId)) {
+ fileName += ".vmdk";
+ } else if ("virtualbox".equals(virtualizerId)) {
+ fileName += ".vdi";
+ } else {
+ fileName += ".img";
+ }
+ return fileName;
+ }
/* *******************************************************************************
*
- * IMAGE METADATA QUERY
+ * IMAGE METADATA
*
* Fetches image details or permissions
*
********************************************************************************/
+ /**
+ * TODO
+ */
public interface ImageMetaCallback {
void fetchedImageDetails(ImageDetailsRead details);
void fetchedImagePermissions(Map<String, ImagePermissions> permissions);
}
+ /**
+ * @param frame
+ * @param imageBaseId
+ * @param callback
+ */
public static void getImageDetails(final Frame frame, final String imageBaseId, final ImageMetaCallback callback) {
QuickTimer.scheduleOnce(new Task() {
ImageDetailsRead details = null;
@@ -412,7 +419,25 @@ public class ThriftActions {
});
}
-
+ /**
+ * GUI-BLOCKING
+ * Sets the owner of the given lectureId to newOwner
+ *
+ * @param frame to display user feedback on
+ * @param lectureId lecture's id to set the new owner of
+ * @param newOwner as UserInfo
+ * @return true if it worked, false otherwise
+ */
+ public static boolean setImageOwner(final Frame frame, final String lectureId, final UserInfo newOwner) {
+ try {
+ 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;
+ }
/* *******************************************************************************
*
* IMAGE / VERSION DELETION