summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java')
-rw-r--r--dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java147
1 files changed, 51 insertions, 96 deletions
diff --git a/dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java b/dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java
index 6638de8c..ee0de205 100644
--- a/dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java
+++ b/dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java
@@ -12,9 +12,6 @@ import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
import javax.swing.JButton;
import javax.swing.JFileChooser;
@@ -40,7 +37,7 @@ import models.person;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
-import org.openslx.sat.thrift.iface.User;
+import org.openslx.sat.thrift.iface.TransferInformation;
import org.openslx.thrifthelper.ThriftManager;
import util.GuiManager;
@@ -61,9 +58,7 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
private JLabel lblPath;
private JProgressBar progressBar;
- private String host = SessionData.serverAdress;
- private int port = 21;
- private User user;
+ private final String host = SessionData.serverAdress;
private File uploadFile;
private UploadTask task;
private JLabel lblUpSpeed;
@@ -83,7 +78,7 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
private int progress = 0; // progress of upload
private boolean isCurrentlyLoading = false; // currently up or downloading file
private boolean isAborted = false; // down- or upload was manually aborted
- private String uuid;
+ private TransferInformation transferInfo = null;
public static final String HELP_MESSAGE = "<html><div align = \"center\">"
+ "Laden Sie hier Ihre .vmdk-Datei hoch, die dann als virtuelles Labor geladen werden kann.<br />"
@@ -99,40 +94,20 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
final String[] options = { "Beenden", "Abbrechen" };
- try {
-
- uuid = ThriftManager.getSatClient().createRandomUUID(SessionData.authToken);
-
- } catch (TException e1) {
-
- e1.printStackTrace();
- }
addInternalFrameListener(new InternalFrameAdapter() {
@Override
public void internalFrameClosing(InternalFrameEvent arg0) {
if (taskrun == true) {
// check if user wants to quit.
- int choice = JOptionPane
- .showOptionDialog(
- null,
- "Aktuell ist ein Upload aktiv. Wollen Sie diesen Abbrechen und das Programm beenden?",
- "Upload aktiv", JOptionPane.YES_NO_CANCEL_OPTION,
- JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
+ int choice = JOptionPane.showOptionDialog(
+ null,
+ "Aktuell ist ein Upload aktiv. Wollen Sie diesen Abbrechen und das Programm beenden?",
+ "Upload aktiv", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
+ null, options, options[1]);
// 0=beenden, 1=abbrechen
if (choice == 0) {
- try {
- ThriftManager.getSatClient().DeleteFtpUser(user.userName, SessionData.authToken);
- } catch (TException e1) {
-
- e1.printStackTrace();
- }
task.cancel(true);
- try {
- ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken);
- } catch (TException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ // TODO: Generic exit callback?
System.exit(0);
}// end if choice
}
@@ -278,8 +253,7 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
panel.add(lblUploadIhresImage);
JTextPane txtpnFhreSieBitte = new JTextPane();
- txtpnFhreSieBitte
- .setText("Führen Sie bitte die folgenden 3 Schritte aus um Ihr Image auf unseren Server zu laden.");
+ txtpnFhreSieBitte.setText("Führen Sie bitte die folgenden 3 Schritte aus um Ihr Image auf unseren Server zu laden.");
txtpnFhreSieBitte.setEditable(false);
txtpnFhreSieBitte.setBackground(SystemColor.menu);
txtpnFhreSieBitte.setBounds(10, 36, 509, 32);
@@ -343,14 +317,7 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
public void actionPerformed(ActionEvent e) {
isAborted = true; // set flag
- try {
- ThriftManager.getSatClient().DeleteFtpUser(user.userName, SessionData.authToken);
- LOGGER.info("Deleted FTP user.");
- } catch (TException e1) {
-
- e1.printStackTrace();
- }
- task.cancel(true);
+ cancelUpload();
resetValues();
// reset buttons
@@ -398,30 +365,18 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
Config.store();
if (taskrun == true) {
- try {
- ThriftManager.getSatClient().DeleteFtpUser(user.userName,
- SessionData.authToken);
-
- } catch (TException e1) {
-
- e1.printStackTrace();
- JOptionPane.showMessageDialog(null,
- e1.getCause() + "\n" + e1.getStackTrace(), "Debug-Message",
- JOptionPane.ERROR_MESSAGE);
- }
- task.cancel(true);
+ cancelUpload();
}
// Erstellung Array vom Datentyp Object, Hinzufügen der
// Optionen
Object[] options = { "Neue Veranstaltung erstellen", "Zum Hauptmenü zurückkehren" };
- int choice = JOptionPane
- .showOptionDialog(
- null,
- "Möchten Sie eine neue Veranstaltung zu diesem Image erstellen oder in das Hauptmenü zurückkehren?",
- "Alternativen", JOptionPane.DEFAULT_OPTION,
- JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
+ int choice = JOptionPane.showOptionDialog(
+ null,
+ "Möchten Sie eine neue Veranstaltung zu diesem Image erstellen oder in das Hauptmenü zurückkehren?",
+ "Alternativen", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
+ null, options, options[0]);
// 0=New Lecture, 1=Main Menu
if (choice == 0) {
@@ -442,24 +397,16 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
// 0=beenden, 1=abbrechen
if (choice == 0) {
- try {
- ThriftManager.getSatClient().DeleteFtpUser(user.userName,
- SessionData.authToken);
- } catch (TException e1) {
-
- e1.printStackTrace();
- }
- task.cancel(true);
+ cancelUpload();
// not loading files, go back one page
dispose();
}// end if choice
} else {
- int selectedOption = JOptionPane
- .showConfirmDialog(
- null,
- "<html>Achtung: Alle Änderungen gehen verloren!<br />Klicken Sie auf fertigstellen, wenn Sie die Änderungen dauerhaft speichern möchten.<br /><br />Möchten Sie jetzt abbrechen und zurück?</html>",
- "Abbrechen und zurück", JOptionPane.YES_NO_OPTION);
+ int selectedOption = JOptionPane.showConfirmDialog(
+ null,
+ "<html>Achtung: Alle Änderungen gehen verloren!<br />Klicken Sie auf fertigstellen, wenn Sie die Änderungen dauerhaft speichern möchten.<br /><br />Möchten Sie jetzt abbrechen und zurück?</html>",
+ "Abbrechen und zurück", JOptionPane.YES_NO_OPTION);
if (selectedOption == JOptionPane.YES_OPTION) {
GuiManager.show(new PermissionCreateImage_GUI());
} else {
@@ -478,6 +425,16 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
}
+ protected void cancelUpload() {
+ try {
+ ThriftManager.getSatClient().cancelUpload(transferInfo.token);
+ } catch (TException e1) {
+ // Don't care if it fails, will time out eventually....
+ }
+ task.cancel(true);
+ transferInfo = null;
+ }
+
private void buttonUploadActionPerformed(ActionEvent event) {
isAborted = false;
@@ -486,22 +443,22 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
btnUploadStarten.setText("Bitte warten");
try {
- user = ThriftManager.getSatClient().getFtpUser(SessionData.authToken);
+ transferInfo = ThriftManager.getSatClient().requestUpload(SessionData.authToken,
+ uploadFile.length(), null);
LOGGER.info("Received FTP user.");
} catch (TException e) {
- LOGGER.error("Konnte vom Satellit keinen FTP-User erhalten!");
+ LOGGER.error("Konnte vom Satellit kein upload token erhalten!");
e.printStackTrace();
- JOptionPane.showMessageDialog(null, "Konnte vom Satellit keinen FTP-User erhalten!",
+ JOptionPane.showMessageDialog(null, "Konnte vom Satellit kein upload token erhalten!",
"Debug-Message", JOptionPane.ERROR_MESSAGE);
+ transferInfo = null;
+ return;
}
- DateFormat formatter = new SimpleDateFormat("yyyMMddHHmmss");
- Image.NewName = formatter.format(new Date()) + "_" + person.verantwortlicher.getHochschule() + "_"
- + person.verantwortlicher.getUsername() + "_" + Image.Imagename + ".vmdk";
LOGGER.info("Uploading to host: " + host);
- task = new UploadTask(host, port, user.userName, user.password, user.path + "temp/", uploadFile);
+ task = new UploadTask(host, transferInfo.plainPort, transferInfo.token, uploadFile);
task.addPropertyChangeListener(this);
task.execute();
@@ -531,10 +488,8 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
btnFinish.setEnabled(false);
}
- if ("speed" == arg0.getPropertyName()) {
+ if ("speed".equals(arg0.getPropertyName())) {
speed = (double) arg0.getNewValue();
- // if(speed<=1){
-
lblUpSpeed.setText(String.format("%.2f", speed) + " MB/s");
}
@@ -543,8 +498,8 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
lblFertig.setText((bytesread / 1024 / 1024) + " MB");
lblVerbleibend.setText(((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) + " MB");
- lblZeit.setText(String
- .valueOf(((((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60) + 1)
+ lblZeit.setText(String.valueOf(
+ ((((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60) + 1)
.substring(
0,
String.valueOf(
@@ -565,21 +520,21 @@ public class FTPCreateUploader_GUI extends JInternalFrame implements PropertyCha
try {
- ThriftManager.getSatClient().writeVLdata(Image.Imagename, Image.Desc,
- person.verantwortlicher.getTel(), person.verantwortlicher.getFakultaet(), Image.Licensed,
- Image.Internet, Image.Ram, Image.Cpu, "temp/" + Image.NewName, Image.Vorlage,
- Image.Filesize, Image.ShareMode, Image.OS, uuid, SessionData.authToken,
- person.verantwortlicher.getUserID());
+ Image.ImageId = ThriftManager.getSatClient().finishImageUpload(Image.Imagename, Image.Desc,
+ Image.Licensed, Image.Internet, Image.Filesize, Image.ShareMode, Image.OS,
+ transferInfo.token);
- System.out.println("starting file copy...");
- ThriftManager.getSatClient().startFileCopy(Image.NewName, SessionData.authToken);
+ if (Image.ImageId == null) {
+ // Should never happen, but let's handle it
+ throw new TException("no image id returned");
+ }
- ThriftManager.getSatClient().writeImageRights(uuid, SessionData.authToken,
+ ThriftManager.getSatClient().writeImageRights(Image.ImageId, SessionData.authToken,
person.verantwortlicher.getRole(), person.verantwortlicher.getHochschule(),
person.verantwortlicher.getUserID());
for (int i = 0; i < RightsManagement.rightsManagement.getPermittedUserList().size(); i++) {
- ThriftManager.getSatClient().writeAdditionalImageRights(uuid,
+ ThriftManager.getSatClient().writeAdditionalImageRights(Image.ImageId,
RightsManagement.rightsManagement.getPermittedUserList().get(i).getUserID(),
RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageRead(),
RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageWrite(),