diff options
| author | Simon Rettberg | 2015-05-29 17:56:36 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-05-29 17:56:36 +0200 |
| commit | 605857a1ef614964d73ea83e0561d1bfb06e611b (patch) | |
| tree | ae968412f038b1a53d07bf83ab8f7fdf808750d1 /dozentenmodul/src/main/java/gui/image | |
| parent | [server] Added some TODOs (diff) | |
| download | tutor-module-605857a1ef614964d73ea83e0561d1bfb06e611b.tar.gz tutor-module-605857a1ef614964d73ea83e0561d1bfb06e611b.tar.xz tutor-module-605857a1ef614964d73ea83e0561d1bfb06e611b.zip | |
[client] Compiles again, but is broken....
Diffstat (limited to 'dozentenmodul/src/main/java/gui/image')
5 files changed, 327 insertions, 526 deletions
diff --git a/dozentenmodul/src/main/java/gui/image/DeleteImage_GUI.java b/dozentenmodul/src/main/java/gui/image/DeleteImage_GUI.java index 21128e48..cf448f70 100644 --- a/dozentenmodul/src/main/java/gui/image/DeleteImage_GUI.java +++ b/dozentenmodul/src/main/java/gui/image/DeleteImage_GUI.java @@ -6,7 +6,6 @@ import gui.intro.MainMenue_GUI; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Font; -import java.awt.HeadlessException; import java.awt.SystemColor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -163,8 +162,7 @@ public class DeleteImage_GUI extends JInternalFrame { JTextPane txtpnBitteWhlenSie = new JTextPane(); txtpnBitteWhlenSie.setEditable(false); txtpnBitteWhlenSie.setBackground(SystemColor.menu); - txtpnBitteWhlenSie - .setText("Wählen Sie bitte aus der unten stehenden Liste das zu löschende Image aus."); + txtpnBitteWhlenSie.setText("Wählen Sie bitte aus der unten stehenden Liste das zu löschende Image aus."); txtpnBitteWhlenSie.setBounds(10, 36, 509, 32); panel.add(txtpnBitteWhlenSie); } @@ -291,97 +289,72 @@ public class DeleteImage_GUI extends JInternalFrame { String imageversion = ""; int eingabe; - if (tablemyImages.getSelectedRowCount() != 0) { - - // frage, soll das selektierte Daten geloescht werden? - eingabe = JOptionPane.showConfirmDialog(null, "Wollen Sie diese Daten löschen?", - "Löschen?", JOptionPane.YES_NO_OPTION); - - if (eingabe == JOptionPane.YES_OPTION) { - - imageid = modelMyImages.getValueAt( - tablemyImages.convertRowIndexToModel(tablemyImages.getSelectedRow()), 6) - .toString(); - - imageversion = modelMyImages.getValueAt( - tablemyImages.convertRowIndexToModel(tablemyImages.getSelectedRow()), 7) - .toString(); - - // Image darf nur geloescht werden, wenn keine - // Veranstaltung mehr auf das Image verweist. - // Unbdingt abfragen! - - try { - if (!ThriftManager.getSatClient().connectedToLecture(imageid, imageversion, - SessionData.authToken)) { - try { - - // try to delete file from file system - if (ThriftManager.getSatClient().deleteImageServer(imageid, imageversion, - SessionData.authToken) == true) { - // successful, now delete file from DB - if (ThriftManager.getSatClient().deleteImageData(imageid, - imageversion, SessionData.authToken)) { - - LOGGER.info("Image '" + imageid + "' erfolgreich gelöscht."); - - GuiManager.show(new DeleteImage_GUI()); - } else { - //could not delete file from DB - LOGGER.info("Image '" + imageid - + "' konnte nicht gelöscht werden."); - - JOptionPane.showMessageDialog(null, - "Image konnte nicht gelöscht werden.", "Fehler", - JOptionPane.INFORMATION_MESSAGE); - } - } else { - // could not delete file from file - // system - LOGGER.info("Image '" + imageid - + "' konnte nicht von Server gelöscht werden."); - - JOptionPane.showMessageDialog(null, - "Image konnte nicht vom Server gelöscht werden.", "Fehler", - JOptionPane.INFORMATION_MESSAGE); - } - - } catch (HeadlessException e) { - - e.printStackTrace(); - JOptionPane.showMessageDialog(null, - e.getCause() + "\n" + e.getStackTrace(), "Debug-Message", - JOptionPane.ERROR_MESSAGE); - } catch (TException e) { - - e.printStackTrace(); - JOptionPane.showMessageDialog(null, - e.getCause() + "\n" + e.getStackTrace(), "Debug-Message", - JOptionPane.ERROR_MESSAGE); - } - - } else { - LOGGER.info("Image '" - + imageid - + "' konnte nicht gelöscht werden, da mindestens eine Veranstaltung mit diesem Image verlinkt ist."); - - JOptionPane - .showMessageDialog( - null, - "Image kann nicht gelöscht werden, da mindestens eine Veranstaltung mit diesem Image verlinkt ist.", - "Verlinkung vorhanden", JOptionPane.INFORMATION_MESSAGE); - } - } catch (TException e) { - - e.printStackTrace(); - JOptionPane.showMessageDialog(null, e.getCause() + "\n" + e.getStackTrace(), - "Debug-Message", JOptionPane.ERROR_MESSAGE); - } + if (tablemyImages.getSelectedRowCount() != 1) { + JOptionPane.showMessageDialog(null, "Bitte wählen Sie ein Image aus", "Info", + JOptionPane.INFORMATION_MESSAGE); + return; + } + + // frage, soll das selektierte Daten geloescht werden? + eingabe = JOptionPane.showConfirmDialog(null, "Wollen Sie diese Daten löschen?", "Löschen?", + JOptionPane.YES_NO_OPTION); + + if (eingabe != JOptionPane.YES_OPTION) { + return; + } + + imageid = modelMyImages.getValueAt( + tablemyImages.convertRowIndexToModel(tablemyImages.getSelectedRow()), 6).toString(); + + imageversion = modelMyImages.getValueAt( + tablemyImages.convertRowIndexToModel(tablemyImages.getSelectedRow()), 7).toString(); + + // Image darf nur geloescht werden, wenn keine + // Veranstaltung mehr auf das Image verweist. + // Unbdingt abfragen! + // TODO: Check this server side on delete, then using exceptions... + try { + if (ThriftManager.getSatClient().connectedToLecture(imageid, imageversion, + SessionData.authToken)) { + LOGGER.info("Image '" + imageid + + "' konnte nicht gelöscht werden, da mindestens eine Veranstaltung mit" + + " diesem Image verlinkt ist."); + + JOptionPane.showMessageDialog(null, + "Image kann nicht gelöscht werden, da mindestens eine Veranstaltung mit" + + " diesem Image verlinkt ist.", "Verlinkung vorhanden", + JOptionPane.INFORMATION_MESSAGE); + return; } + } catch (Exception e) { + } + + try { + // try to delete file from file system + if (ThriftManager.getSatClient() + .deleteImage(imageid, imageversion, SessionData.authToken) == true) { + LOGGER.info("Image '" + imageid + "' erfolgreich gelöscht."); + + GuiManager.show(new DeleteImage_GUI()); + } else { + // could not delete file from file + // system + LOGGER.info("Image '" + imageid + "' konnte nicht gelöscht werden."); + + JOptionPane.showMessageDialog(null, "Image konnte nicht gelöscht werden.", "Fehler", + JOptionPane.INFORMATION_MESSAGE); + } + + } catch (TException e) { + + e.printStackTrace(); + JOptionPane.showMessageDialog(null, e.getCause() + "\n" + e.getStackTrace(), + "Debug-Message", JOptionPane.ERROR_MESSAGE); } } + }); btnDelete.setBounds(449, 508, 118, 23); contentPanel.add(btnDelete); 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(), diff --git a/dozentenmodul/src/main/java/gui/image/FTPEditDownloader_GUI.java b/dozentenmodul/src/main/java/gui/image/FTPEditDownloader_GUI.java index b7b0a9f4..11aed0f9 100644 --- a/dozentenmodul/src/main/java/gui/image/FTPEditDownloader_GUI.java +++ b/dozentenmodul/src/main/java/gui/image/FTPEditDownloader_GUI.java @@ -36,7 +36,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; @@ -46,23 +46,18 @@ import ftp.DownloadTask; import gui.intro.MainMenue_GUI; @SuppressWarnings("serial") -public class FTPEditDownloader_GUI extends JInternalFrame implements - PropertyChangeListener { +public class FTPEditDownloader_GUI extends JInternalFrame implements PropertyChangeListener { /** * Logger instance for this class. */ - private final static Logger LOGGER = Logger - .getLogger(FTPEditDownloader_GUI.class); - + private final static Logger LOGGER = Logger.getLogger(FTPEditDownloader_GUI.class); + private final JPanel contentPanel = new JPanel(); private JLabel lblPath; private JLabel lblDownSpeed; - private User user; private JProgressBar progressBar; private String host = SessionData.serverAdress; - private int port = 21; - private String downloadFile = ""; private DownloadTask task; private JLabel lblFertig; private JLabel lblFilesize; @@ -78,9 +73,9 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements private JButton btnDownloadStarten = new JButton("Download starten"); private JButton btnDownloadStoppen = new JButton("Download abbrechen"); private JLabel lblAnleitung; - private boolean isCurrentlyLoading = false; // currently up or downloading - // file + private boolean isCurrentlyLoading = false; // currently up or downloading file private boolean isAborted = false; // down- or upload was manually aborted + private TransferInformation transferInfo = null; public static final String HELP_MESSAGE = "<html><div align=\"center\">" + "Hier können Sie Images herunterladen.<br />" + "Klicken Sie anschließend auf \"Zurück\", um zu Ihrer vorherigen Auswahl zurückzugelangen.<br />" @@ -91,34 +86,25 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements */ public FTPEditDownloader_GUI() { + final String[] options = { "Beenden", "Abbrechen" }; - final Object[] options = { "Beenden", "Abbrechen" }; 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 Download 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 Download 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); - try { - ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken); - } catch (TException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } + ThriftManager.getSatClient().cancelDownload(transferInfo.token); + ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken); } catch (TException e1) { - - e1.printStackTrace(); + LOGGER.error("Error cancelling download..", e1); } task.cancel(true); System.exit(0); @@ -129,7 +115,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements setResizable(false); setBackground(Color.WHITE); - setTitle("Dozentenmodul - Image herunterladen - "+person.verantwortlicher.getUserID()); + setTitle("Dozentenmodul - Image herunterladen - " + person.verantwortlicher.getUserID()); // Aktion die beim Schliessen durchgefuehrt werden soll setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); @@ -141,9 +127,9 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(null); { - JButton btnSpeicherortAuswhlen = new JButton( - "Speicherort auswählen"); + JButton btnSpeicherortAuswhlen = new JButton("Speicherort auswählen"); btnSpeicherortAuswhlen.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent arg0) { fc = new JFileChooser(Config.getLastDownloadPath()); @@ -174,6 +160,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements lblPath.setText(Config.getLastDownloadPath()); lblPath.addPropertyChangeListener(new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent arg0) { if (lblPath.getText().trim().isEmpty()) { // wenn leer, dann upload button nicht freigeben @@ -191,6 +178,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements btnDownloadStarten.setEnabled(false); btnDownloadStarten.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent arg0) { buttonDownloadActionPerformed(arg0); } @@ -205,8 +193,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements progressBar.setBounds(102, 234, 485, 30); contentPanel.add(progressBar); - JLabel lblDownloadgeschwindigkeit = new JLabel( - "Downloadgeschwindigkeit:"); + JLabel lblDownloadgeschwindigkeit = new JLabel("Downloadgeschwindigkeit:"); lblDownloadgeschwindigkeit.setBounds(102, 275, 141, 14); contentPanel.add(lblDownloadgeschwindigkeit); @@ -238,8 +225,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements lblVerbleibend.setBounds(183, 350, 108, 14); contentPanel.add(lblVerbleibend); - JLabel lblGeschtzteVerbleibendeZeit = new JLabel( - "Geschätzte Verbleibende Zeit:"); + JLabel lblGeschtzteVerbleibendeZeit = new JLabel("Geschätzte Verbleibende Zeit:"); lblGeschtzteVerbleibendeZeit.setBounds(102, 300, 150, 14); contentPanel.add(lblGeschtzteVerbleibendeZeit); @@ -259,8 +245,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements panel.add(lblImageDownloader); JTextPane txtpnWhlenSieEinen = new JTextPane(); - txtpnWhlenSieEinen - .setText("Wählen Sie einen Ort aus, um das von Ihnen gewählte Image herunterzuladen."); + txtpnWhlenSieEinen.setText("Wählen Sie einen Ort aus, um das von Ihnen gewählte Image herunterzuladen."); txtpnWhlenSieEinen.setEditable(false); txtpnWhlenSieEinen.setBackground(SystemColor.menu); txtpnWhlenSieEinen.setBounds(10, 36, 509, 32); @@ -323,7 +308,6 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements menuBar.setBounds(0, 0, 597, 21); contentPanel.add(menuBar); - lblAnleitung = new JLabel( "<HTML><U>Anleitung zum Erstellen einer virtuellen Maschine herunterladen</U></HTML>"); lblAnleitung.setForeground(Color.BLUE); @@ -336,15 +320,13 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements lblAnleitung.setBounds(102, 448, 311, 14); contentPanel.add(lblAnleitung); btnDownloadStoppen.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { isAborted = true; // set flag try { - ThriftManager.getSatClient().DeleteFtpUser(user.userName,SessionData.authToken); - LOGGER.info("FTP user deleted."); + ThriftManager.getSatClient().cancelDownload(transferInfo.token); } catch (TException e1) { - - e1.printStackTrace(); } task.cancel(true); resetValues(); @@ -364,25 +346,20 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements getContentPane().add(buttonPane, BorderLayout.SOUTH); { btnZurck.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { // check if loading file or not if (isCurrentlyLoading() == true) { - int choice = JOptionPane - .showOptionDialog( - null, - "Nicht abgeschlossene Uploads werden beendet. Trotzdem zurück gehen?", - "Warnung", - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, null, - options, options[1]); + int choice = JOptionPane.showOptionDialog(null, + "Nicht abgeschlossene Uploads werden beendet. Trotzdem zurück gehen?", + "Warnung", JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE, null, options, options[1]); // 0=beenden, 1=abbrechen if (choice == 0) { task.cancel(true); try { - ThriftManager.getSatClient().DeleteFtpUser(user.userName,SessionData.authToken); + ThriftManager.getSatClient().cancelDownload(transferInfo.token); } catch (TException e1) { - - e1.printStackTrace(); } // go back one page @@ -400,8 +377,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements if (f.isDirectory()) { Config.setLastDownloadPath(f.toString()); } else if (f.getParentFile().isDirectory()) { - Config.setLastDownloadPath(f.getParentFile() - .toString()); + Config.setLastDownloadPath(f.getParentFile().toString()); } Config.store(); @@ -413,7 +389,6 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements } setVisible(true); - } private void buttonDownloadActionPerformed(ActionEvent event) { @@ -424,88 +399,70 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements // Klick btnDownloadStarten.setText("Bitte warten"); try { - user = ThriftManager.getSatClient().getFtpUser(SessionData.authToken); - - downloadFile = user.path - + "/" - + ThriftManager.getSatClient().getPathOfImage(Image.ImageId, - Image.Version,SessionData.authToken); - + transferInfo = ThriftManager.getSatClient().requestDownload(SessionData.authToken, Image.ImageId); } catch (TException e) { - - e.printStackTrace(); - JOptionPane.showMessageDialog(null, - e.getCause() + "\n" + e.getStackTrace(), "Debug-Message", + transferInfo = null; + JOptionPane.showMessageDialog(null, e.getCause() + "\n" + e.getStackTrace(), "Debug-Message", JOptionPane.ERROR_MESSAGE); } - task = new DownloadTask(host, port, user.userName, user.password, - downloadFile, lblPath.getText().trim().trim()); + task = new DownloadTask(host, transferInfo.plainPort, transferInfo.token, lblPath.getText().trim(), Image.Filesize); task.addPropertyChangeListener(this); task.execute(); taskrun = true; } + @Override public void propertyChange(PropertyChangeEvent arg0) { - if (isAborted == false) { - progress = 0; - if ("progress" == arg0.getPropertyName()) { - progress = (Integer) arg0.getNewValue(); - progressBar.setValue(progress); - } + if (isAborted) + return; + progress = 0; + if ("progress".equals(arg0.getPropertyName())) { + progress = (Integer) arg0.getNewValue(); + progressBar.setValue(progress); + } - if ("speed" == arg0.getPropertyName()) { - speed = (double) arg0.getNewValue(); + if ("speed".equals(arg0.getPropertyName())) { + speed = (double) arg0.getNewValue(); + lblDownSpeed.setText(String.format("%.2f", speed) + " MB/s"); + } - lblDownSpeed.setText(String.valueOf(speed).substring(0, - String.valueOf(speed).lastIndexOf(".") + 3) - + " MB/s"); - } + // Button zum Fertigstellen freischalten, wenn 100% erreicht sind + if (isCurrentlyLoading() == false || progressBar.getPercentComplete() == 1.0) { + // no download + btnDownloadStoppen.setEnabled(false); + } else { + // currently uploading, don't let user interact + btnDownloadStoppen.setEnabled(true); + } - // Button zum Fertigstellen freischalten, wenn 100% erreicht sind - if (isCurrentlyLoading() == false - || progressBar.getPercentComplete() == 1.0) { - // no download - btnDownloadStoppen.setEnabled(false); - } else { - // currently uploading, don't let user interact - btnDownloadStoppen.setEnabled(true); - } + if (arg0.getPropertyName().equals("bytesread")) { + bytesread = (long) arg0.getNewValue(); + lblFertig.setText((bytesread / 1024 / 1024) + " MB"); + lblVerbleibend.setText(((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) + " MB"); - if (arg0.getPropertyName().equals("bytesread")) { - bytesread = (long) arg0.getNewValue(); - 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) - .substring( - 0, - String.valueOf( - (((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60) - .lastIndexOf(".")) - + " Minuten"); + lblZeit.setText(String.valueOf( + ((((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60) + 1).substring( + 0, + String.valueOf((((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60) + .lastIndexOf(".")) + + " Minuten"); - } - if (arg0.getPropertyName().equals("filesize")) { - filesize = (long) arg0.getNewValue(); - lblFilesize.setText((filesize / 1024 / 1024) + " MB"); + } + if (arg0.getPropertyName().equals("filesize")) { + filesize = (long) arg0.getNewValue(); + lblFilesize.setText((filesize / 1024 / 1024) + " MB"); - } - }// end if + } }// end PropertyChange() - public boolean isCurrentlyLoading() { + private boolean isCurrentlyLoading() { isCurrentlyLoading = false; - if (lblVerbleibend.getText().trim().equals("0 MB") - || lblVerbleibend.getText().trim().equals("0")) { + if (lblVerbleibend.getText().trim().equals("0 MB") || lblVerbleibend.getText().trim().equals("0")) { isCurrentlyLoading = false; } else { isCurrentlyLoading = true; @@ -513,7 +470,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements return isCurrentlyLoading; }// end isCurrentlyLoading() - public void resetValues() { + private void resetValues() { lblDownSpeed.setText("0"); lblZeit.setText("0"); lblFertig.setText("0"); @@ -522,7 +479,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements progressBar.setValue(0); }// end resetValues - public void resetButtons() { + private void resetButtons() { btnDownloadStarten.setEnabled(true); btnDownloadStarten.setText("Download starten"); btnDownloadStoppen.setEnabled(false); diff --git a/dozentenmodul/src/main/java/gui/image/FTPEditUploader_GUI.java b/dozentenmodul/src/main/java/gui/image/FTPEditUploader_GUI.java index 7777bf37..27f3d7ce 100644 --- a/dozentenmodul/src/main/java/gui/image/FTPEditUploader_GUI.java +++ b/dozentenmodul/src/main/java/gui/image/FTPEditUploader_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,10 +37,11 @@ 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; +import util.MessageType; import config.Config; import ftp.UploadTask; import gui.intro.MainMenue_GUI; @@ -60,10 +58,8 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang private JLabel lblPath; private JProgressBar progressBar; private String host = SessionData.serverAdress; - private int port = 21; - private User user; private File uploadFile; - private UploadTask task; + private UploadTask task = null; private JLabel lblUpSpeed; private JLabel lblFertig; private JLabel lblFilesize; @@ -73,16 +69,14 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang private long filesize; private double speed; private long bytesread; - private boolean fileupload = false; - private boolean taskrun = false; private int progress = 0; private JButton btnUploadStarten = new JButton("Upload auf Server starten"); private JButton btnSpeicherortAuswhlen = new JButton("Image auswählen"); private JButton btnFinish = new JButton("Fertigstellen"); private JButton btnZurck = new JButton("Zurück"); private JButton btnUploadStoppen = new JButton("Upload abbrechen"); - private boolean isCurrentlyLoading = false; // currently up or downloading - // file + private TransferInformation transferInfo = null; + // file private boolean isAborted = false; // down- or upload was manually aborted public static final String HELP_MESSAGE = "<html><div align = \"center\">" + "Laden Sie hier Ihre bearbeitete .vmdk-Datei hoch, die dann als virtuelles Labor geladen werden kann.<br />" @@ -96,41 +90,28 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang */ public FTPEditUploader_GUI() { - final Object[] options = { "Beenden", "Abbrechen" }; + final String[] options = { "Beenden", "Abbrechen" }; 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]); - // 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(); - } - try { - ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken); - } catch (TException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - System.exit(0); - }// end if choice - } + if (!isCurrentlyLoading()) + return; + // 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]); + // 0=beenden, 1=abbrechen + if (choice == 0) { + try { + ThriftManager.getSatClient().cancelDownload(transferInfo.token); + ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken); + } catch (TException e1) { + } + task.cancel(true); + System.exit(0); + }// end if choice } }); setResizable(false); @@ -264,8 +245,7 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang panel.add(lblUploadIhresImage); JTextPane txtpnFhreSieBitte = new JTextPane(); - txtpnFhreSieBitte - .setText("Laden Sie optional ein neues Image hoch, oder klicken Sie direkt auf \"Fertigstellen\", um reine Änderungen der Angaben direkt zu übernehmen."); + txtpnFhreSieBitte.setText("Laden Sie optional ein neues Image hoch, oder klicken Sie direkt auf \"Fertigstellen\", um reine Änderungen der Angaben direkt zu übernehmen."); txtpnFhreSieBitte.setEditable(false); txtpnFhreSieBitte.setBackground(SystemColor.menu); txtpnFhreSieBitte.setBounds(10, 36, 509, 42); @@ -327,10 +307,8 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang isAborted = true; // set flag try { - ThriftManager.getSatClient().DeleteFtpUser(user.userName, SessionData.authToken); - LOGGER.info("FTP user deleted."); + ThriftManager.getSatClient().cancelDownload(transferInfo.token); } catch (TException e1) { - e1.printStackTrace(); } task.cancel(true); resetValues(); @@ -365,19 +343,11 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang // save data boolean success = updateData(); - if (success == true) { - LOGGER.info("Bearbeitetes Image '" + Image.Imagename - + "' erfolgreich gespeichert."); - JOptionPane.showMessageDialog(null, - "Die Änderungen wurden erfolgreich gespeichert.", - "Änderungen gespeichert", JOptionPane.INFORMATION_MESSAGE); - } else { - LOGGER.error("Bearbeitetes Image '" + Image.Imagename - + "' konnte nicht gespeichert werden."); - JOptionPane.showMessageDialog(null, - "Die Änderungen konnten nicht gespeichert werden.", "Fehler", - JOptionPane.ERROR_MESSAGE); - } + if (!success) + return; + LOGGER.info("Bearbeitetes Image '" + Image.Imagename + "' erfolgreich gespeichert."); + JOptionPane.showMessageDialog(null, "Die Änderungen wurden erfolgreich gespeichert.", + "Änderungen gespeichert", JOptionPane.INFORMATION_MESSAGE); if (lblPath.getText().trim().length() > 0) { File f = new File(lblPath.getText().trim()); @@ -393,17 +363,7 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang GuiManager.show(new MainMenue_GUI()); - 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); - } + if (isCurrentlyLoading()) { task.cancel(true); } @@ -421,8 +381,7 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang // 0=beenden, 1=abbrechen if (choice == 0) { try { - ThriftManager.getSatClient().DeleteFtpUser(user.userName, - SessionData.authToken); + ThriftManager.getSatClient().cancelDownload(transferInfo.token); } catch (TException e1) { e1.printStackTrace(); } @@ -449,11 +408,10 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang }// end if coice } 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) { try { System.out.println("userID in editimageuploader is : " @@ -491,31 +449,23 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang private void buttonUploadActionPerformed(ActionEvent event) { isAborted = false; - fileupload = true; progressBar.setValue(0); - btnUploadStarten.setEnabled(false); // verhindert einen weiteren klick + btnUploadStarten.setEnabled(false); // verhindert einen weiteren Klick btnUploadStarten.setText("Bitte warten"); try { - user = ThriftManager.getSatClient().getFtpUser(SessionData.authToken); - LOGGER.info("Received FTP user."); + transferInfo = ThriftManager.getSatClient().requestUpload(SessionData.authToken, + uploadFile.length(), null); } catch (TException e) { - e.printStackTrace(); + transferInfo = null; JOptionPane.showMessageDialog(null, "Konnte vom Satelliten keine FTP-User erhalten!", "Debug-Message", JOptionPane.ERROR_MESSAGE); } - DateFormat formatter = new SimpleDateFormat("yyyMMddHHmmss"); - - // set new file name and path only when uploading a new file. else use - // old filename and path - Image.NewName = formatter.format(new Date()) + "_" + person.verantwortlicher.getHochschule() + "_" - + person.verantwortlicher.getUsername() + "_" + Image.Imagename + ".vmdk"; - 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(); - taskrun = true; } @@ -523,7 +473,7 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang if (isAborted == false) { // set progressbar - if ("progress" == arg0.getPropertyName()) { + if ("progress".equals(arg0.getPropertyName())) { progress = (Integer) arg0.getNewValue(); progressBar.setValue(progress); } @@ -540,22 +490,20 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang btnFinish.setEnabled(false); } - if ("speed" == arg0.getPropertyName()) { + if ("speed".equals(arg0.getPropertyName())) { speed = (double) arg0.getNewValue(); // if(speed<=1){ - lblUpSpeed.setText(String.valueOf(speed).substring(0, - String.valueOf(speed).lastIndexOf(".") + 3) - + " MB/s"); + lblUpSpeed.setText(String.format("%.2f", speed) + " MB/s"); } - if ("bytesread" == arg0.getPropertyName()) { + if ("bytesread".equals(arg0.getPropertyName())) { bytesread = (long) arg0.getNewValue(); 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( @@ -564,7 +512,7 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang + " Minuten"); } - if ("filesize" == arg0.getPropertyName()) { + if ("filesize".equals(arg0.getPropertyName())) { filesize = (long) arg0.getNewValue(); lblFilesize.setText((filesize / 1024 / 1024) + " MB"); @@ -573,84 +521,90 @@ public class FTPEditUploader_GUI extends JInternalFrame implements PropertyChang }// end propertyChange public boolean updateData() { - - try { - //if a new file has been uploaded and new filename is set - if (Image.NewName != null) { - LOGGER.debug("New file uploaded and new filename is set"); - - ThriftManager.getSatClient().updateImageData(Image.Imagename, Image.Imagename, - Image.Desc, - //Image.Imagepath, - "temp/" + Image.NewName, Image.Licensed, Image.Internet, Image.Ram, Image.Cpu, - Image.ImageId, Image.Version, Image.Vorlage, Image.Filesize, Image.ShareMode, - Image.OS, SessionData.authToken); - if (fileupload == true) { - ThriftManager.getSatClient().startFileCopy(Image.NewName, SessionData.authToken); - } - - } else { //no new file uploaded and old file name stays - LOGGER.debug("old file should remain"); - - ThriftManager.getSatClient().updateImageData(Image.Imagename, Image.Imagename, - Image.Desc, - //"temp/" + Image.NewName, //wrong - Image.Imagepath, Image.Licensed, Image.Internet, Image.Ram, Image.Cpu, Image.ImageId, - Image.Version, Image.Vorlage, Image.Filesize, Image.ShareMode, Image.OS, - SessionData.authToken); - - if (fileupload == true) { - ThriftManager.getSatClient().startFileCopy(Image.NewName, SessionData.authToken); - // client.startFileCopy(Image.Imagename); - } + if (isCurrentlyLoading()) { + JOptionPane.showMessageDialog(null, "Vorgang noch nicht abgeschlossen!!", "Fehler", + JOptionPane.ERROR_MESSAGE); + return false; + } + boolean ret; + Exception ex; + //if a new file has been uploaded and new filename is set + if (task != null && task.isDone()) { + LOGGER.debug("New file uploaded, updating DB entry..."); + + ret = false; + ex = null; + try { + ret = ThriftManager.getSatClient().updateImageFile(transferInfo.token, Image.ImageId); + } catch (Exception e) { + ex = e; + } + if (!ret) { + GuiManager.showMessageBox( + "Die Metadaten des Images konnten nicht auf das neue Image umgeschrieben werden.", + MessageType.ERROR, LOGGER, ex); + return false; } + } - // remove all additional user permissions on first stage + LOGGER.debug("old file should remain"); + ret = false; + ex = null; + try { + ret = ThriftManager.getSatClient().updateImageData(SessionData.authToken, Image.ImageId, + Image.Imagename, Image.Desc, Image.Licensed, Image.Internet, Image.ShareMode, Image.OS); + } catch (TException e) { + ex = e; + } + if (!ret) { + GuiManager.showMessageBox("Serverseitiger Fehler beim Aktualisieren der Metadaten", + MessageType.ERROR, LOGGER, ex); + return false; + } + + // remove all additional user permissions on first stage + ret = false; + ex = null; + try { ThriftManager.getSatClient().deleteAllAdditionalImagePermissions(Image.ImageId, SessionData.authToken, person.verantwortlicher.getUserID()); + } catch (TException e) { + ex = e; + } + if (ex != null) { + GuiManager.showMessageBox("Konnte alte Permissions nicht aus der Datenbank entfernen.", + MessageType.WARNING, LOGGER, ex); + } - // then, add user permissions as they have been set new - for (int i = 0; i < RightsManagement.rightsManagement.getPermittedUserList().size(); i++) { - /*System.out.println("Writing additional rights for user " - + RightsManagement.rightsManagement - .getPermittedUserList().get(i).getUserID() - + ", User " - + i - + "/" - + RightsManagement.rightsManagement.getPermittedUserList().size()); - */ - - ThriftManager.getSatClient().writeAdditionalImageRights(Image.ImageId, + // then, add user permissions as they have been set new + ret = true; // (sic) + ex = null; + for (int i = 0; i < RightsManagement.rightsManagement.getPermittedUserList().size(); i++) { + try { + ret = ThriftManager.getSatClient().writeAdditionalImageRights(Image.ImageId, RightsManagement.rightsManagement.getPermittedUserList().get(i).getUserID(), RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageRead(), RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageWrite(), RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageLinkAllowed(), RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageAdmin(), - SessionData.authToken); - - }// end for - - } catch (TException e) { - e.printStackTrace(); - JOptionPane.showMessageDialog(null, - "Konnte die Metadaten des Images nicht in die Datenbank speichern!", "Debug-Message", - JOptionPane.ERROR_MESSAGE); - return false; + SessionData.authToken) + && ret; + } catch (TException e) { + ex = e; + } + }// end for + if (!ret) { + GuiManager.showMessageBox("Serverseitiger Fehler beim Schreiben der neuen Berechtigungen.", + MessageType.WARNING, LOGGER, ex); } + return true; } public boolean isCurrentlyLoading() { - isCurrentlyLoading = false; - - if (lblVerbleibend.getText().trim().equals("0 MB") || lblVerbleibend.getText().trim().equals("0")) { - isCurrentlyLoading = false; - } else { - isCurrentlyLoading = true; - } - return isCurrentlyLoading; + return task != null && !task.isDone(); }// end isCurrentlyLoading() public void resetValues() { diff --git a/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java b/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java index f92d6a5c..c4b79d0d 100644 --- a/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java +++ b/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java @@ -35,10 +35,11 @@ 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; +import util.MessageType; import util.OpenLinks; import config.Config; import ftp.DownloadTask; @@ -52,11 +53,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC private final JPanel contentPanel = new JPanel(); private JLabel lblPath; private JLabel lblDownSpeed; - private User user; private JProgressBar progressBar; private String host = SessionData.serverAdress; - private int port = 21; - private String downloadFile = ""; private DownloadTask task; private JLabel lblFertig; private JLabel lblFilesize; @@ -73,9 +71,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC private JButton btnMainMenu = new JButton("Hauptmenü"); private JButton btnDownloadStoppen = new JButton("Download abbrechen"); private JLabel lblAnleitung; - private boolean isCurrentlyLoading = false; // currently up or downloading - // file private boolean isAborted = false; // down- or upload was manually aborted + private TransferInformation transferInfo = null; public static final String HELP_MESSAGE = "<html><div align=\"center\">" + "Hier können Sie Images herunterladen.<br />" + "Klicken Sie anschließend auf \"Zurück\" oder \"Hauptmenü\", um zu Ihrer vorherigen Auswahl oder zum Menü zurückzugelangen.<br />" @@ -92,32 +89,18 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC public void internalFrameClosing(InternalFrameEvent arg0) { if (taskrun == true) { // check if user wants to quit. - int choice = JOptionPane - .showOptionDialog( - null, - "Aktuell ist ein Download 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 Download 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); - try { - ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken); - } catch (TException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - try { - ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken); - } catch (TException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } + ThriftManager.getSatClient().cancelDownload(transferInfo.token); + ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken); } catch (TException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); } task.cancel(true); @@ -324,11 +307,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC isAborted = true; // set flag try { - ThriftManager.getSatClient().DeleteFtpUser(user.userName, SessionData.authToken); - LOGGER.info("Deleted FTP user."); + ThriftManager.getSatClient().cancelDownload(transferInfo.token); } catch (TException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); } task.cancel(true); resetValues(); @@ -360,11 +340,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC if (choice == 0) { task.cancel(true); try { - ThriftManager.getSatClient().DeleteFtpUser(user.userName, - SessionData.authToken); + ThriftManager.getSatClient().cancelDownload(transferInfo.token); } catch (TException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); } // go back one page GuiManager.show(new SearchImage_GUI()); @@ -401,26 +378,18 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC isAborted = false; progressBar.setValue(0); - btnDownloadStarten.setEnabled(false); // verhindert schnellen zweiten - // Klick + btnDownloadStarten.setEnabled(false); // verhindert schnellen zweiten Klick btnDownloadStarten.setText("Bitte warten"); try { - user = ThriftManager.getSatClient().getFtpUser(SessionData.authToken); - - downloadFile = user.path - + "/" - + ThriftManager.getSatClient().getPathOfImage(Image.ImageId, - Image.Version, SessionData.authToken); - + transferInfo = ThriftManager.getSatClient().requestDownload(SessionData.authToken, Image.ImageId); } catch (TException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - JOptionPane.showMessageDialog(null, e.getCause() + "\n" + e.getStackTrace(), "Debug-Message", - JOptionPane.ERROR_MESSAGE); + transferInfo = null; + GuiManager.showMessageBox("Satellit verweigert den Download", MessageType.ERROR, LOGGER, e); + return; } - task = new DownloadTask(host, port, user.userName, user.password, downloadFile, lblPath.getText() - .trim()); + task = new DownloadTask(host, transferInfo.plainPort, transferInfo.token, lblPath.getText(), + Image.Filesize); task.addPropertyChangeListener(this); task.execute(); taskrun = true; @@ -462,8 +431,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC 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( @@ -480,15 +449,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC }// end if }// end propertyChange - public boolean isCurrentlyLoading() { - isCurrentlyLoading = false; - - if (lblVerbleibend.getText().trim().equals("0 MB") || lblVerbleibend.getText().trim().equals("0")) { - isCurrentlyLoading = false; - } else { - isCurrentlyLoading = true; - } - return isCurrentlyLoading; + private boolean isCurrentlyLoading() { + return task != null && !task.isDone(); }// end isCurrentlyLoading() public void resetValues() { |
