From 25a2cdd73fd8d3e6202bbf6cb4139ebea3f0c0cb Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 20 Aug 2015 17:17:47 +0200 Subject: [client] fix image name / uuid not beeing read from the existing image --- .../org/openslx/dozmod/gui/wizard/ImageWizard.java | 2 +- .../openslx/dozmod/gui/wizard/UpdateWizard.java | 15 +++++-- .../dozmod/gui/wizard/page/ImageUploadPage.java | 46 +++++++++++++--------- .../org/openslx/dozmod/thrift/ThriftActions.java | 9 +++-- 4 files changed, 45 insertions(+), 27 deletions(-) (limited to 'dozentenmodul/src/main/java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java index 73235920..6de120e3 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java @@ -33,7 +33,7 @@ public class ImageWizard extends Wizard implements UiFeedback { */ public ImageWizard(Window parent) { super(parent); - imageUploadPage = new ImageUploadPage(this, uploadWizardState, false); + imageUploadPage = new ImageUploadPage(this, uploadWizardState, false, null); imageMetaDataPage = new ImageMetaDataPage(this, uploadWizardState); imageCustomPermissionPage = new ImageCustomPermissionPage(this, uploadWizardState); addPage(imageUploadPage); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/UpdateWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/UpdateWizard.java index c534df63..07279b86 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/UpdateWizard.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/UpdateWizard.java @@ -7,6 +7,8 @@ import javax.swing.JOptionPane; import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.ImageDetailsRead; import org.openslx.bwlp.thrift.iface.ImageVersionWrite; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.wizard.page.ImageUploadPage; import org.openslx.dozmod.state.UploadWizardState; @@ -21,15 +23,22 @@ public class UpdateWizard extends Wizard implements UiFeedback { protected ImageUploadPage imageUploadPage; public UpdateWizard(final Window parent, final ImageDetailsRead image) { super(parent); - imageUploadPage = new ImageUploadPage(this, uploadWizardState, true); + + imageUploadPage = new ImageUploadPage(this, uploadWizardState, true, image); addPage(imageUploadPage); } @Override public void performFinish() { - ThriftActions.updateImageVersion(JOptionPane.getFrameForComponent(this), - uploadWizardState.transferInformation, + LOGGER.debug("Finishing: " + uploadWizardState.transferInformation.getToken()); + try { + ThriftActions.updateImageVersion(JOptionPane.getFrameForComponent(this), + uploadWizardState.transferInformation.getToken(), new ImageVersionWrite(uploadWizardState.isRestricted)); + } catch (Exception e) { + // failure + Gui.showMessageBox(this, "Failed to update version", MessageType.ERROR, LOGGER, e); + } } @Override public boolean wantConfirmQuit() { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java index 18e61fd5..e74e4adb 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java @@ -14,6 +14,7 @@ import javax.swing.JOptionPane; import javax.swing.filechooser.FileNameExtensionFilter; import org.apache.log4j.Logger; +import org.openslx.bwlp.thrift.iface.ImageDetailsRead; import org.openslx.dozmod.Config; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.MainWindow; @@ -35,13 +36,20 @@ public class ImageUploadPage extends ImageUploadPageLayout { private UploadWizardState state; private String lastDetectedName = null; private boolean updateExisting = false; + private ImageDetailsRead existingImage = null; - public ImageUploadPage(Wizard wizard, UploadWizardState uploadWizardState, boolean updateExisting) { + public ImageUploadPage(Wizard wizard, UploadWizardState uploadWizardState, boolean updateExisting, final ImageDetailsRead existingImage) { super(wizard); setPageComplete(false); this.canComeBack = false; this.state = uploadWizardState; this.updateExisting = updateExisting; + this.existingImage = existingImage; + // safety check + if (updateExisting && existingImage == null) { + LOGGER.error("Wrong initialization of ImageUploadPage for updating an existing image!"); + return; + } imageNameCaption.setVisible(!updateExisting); imageNameTextField.setVisible(!updateExisting); @@ -158,25 +166,25 @@ public class ImageUploadPage extends ImageUploadPageLayout { */ @Override protected boolean wantNextOrFinish() { - // are we creating a new image? - if (!updateExisting) { - // get the image name either auto filled by VmwareMetaData or by user - state.name = imageNameTextField.getText(); - } else { - // get the image name from the image we are uploading a new version of - state.name = "HAX"; - } - + // are we creating a new image? then either: + // get the image name either auto filled by VmwareMetaData or by user + // get the image name from the image we are uploading a new version of + state.name = updateExisting ? + existingImage.getImageName() : imageNameTextField.getText(); // -- create image to get uuid -- - if (state.uuid == null) { - state.uuid = ThriftActions.createImage(JOptionPane.getFrameForComponent(this), state.name); - if (state.uuid == null) - return false; - - imageNameTextField.setEnabled(false); - imageFileBrowseButton.setEnabled(false); - imageFileTextField.setEnabled(false); + if (!updateExisting) { + if (state.uuid == null) { + state.uuid = ThriftActions.createImage(JOptionPane.getFrameForComponent(this), state.name); + if (state.uuid == null) + return false; + + imageNameTextField.setEnabled(false); + imageFileBrowseButton.setEnabled(false); + imageFileTextField.setEnabled(false); + } + } else { + state.uuid = existingImage.getImageBaseId(); } // -- request upload for that uuid -- if (state.transferInformation == null) { @@ -188,7 +196,7 @@ public class ImageUploadPage extends ImageUploadPageLayout { // -- start uploading our diskFile with the transfer information we just received -- if (state.uploadTask == null) { state.uploadTask = ThriftActions.initUpload(JOptionPane.getFrameForComponent(this), - state.transferInformation, state.hashGen, state.diskFile); + state.transferInformation, state.diskFile); if (state.uploadTask == null) return false; } 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 68eb935b..5ffc323a 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java @@ -241,7 +241,7 @@ public class ThriftActions { * @return UploadTask if the uploading initialized, or null if uploading failed */ public static UploadTask initUpload(final Frame frame, final TransferInformation transferInformation, - AsyncHashGenerator hashGen, final File diskFile) { + final File diskFile) { UploadTask uploadTask = null; // do actually start the upload now LOGGER.debug("Starting upload for: " + diskFile.toPath()); @@ -254,7 +254,7 @@ public class ThriftActions { + diskFile.getAbsolutePath(), MessageType.ERROR, LOGGER, e); return null; } - hashGen = new AsyncHashGenerator(transferInformation.token, diskFile); + AsyncHashGenerator hashGen = new AsyncHashGenerator(transferInformation.token, diskFile); Thread hashThread = new Thread(hashGen); hashThread.setDaemon(true); hashThread.start(); @@ -283,10 +283,11 @@ public class ThriftActions { * @param transferInformation * @param versionInfo */ - public static void updateImageVersion(final Frame frame, final TransferInformation transferInformation, final ImageVersionWrite versionInfo) { + public static void updateImageVersion(final Frame frame, + final String versionId, final ImageVersionWrite versionInfo) { try { ThriftManager.getSatClient().updateImageVersion(Session.getSatelliteToken(), - transferInformation.getToken(), + versionId, versionInfo); } catch (TException e) { Gui.asyncMessageBox("Could not set active/restricted flags to satellite: ", -- cgit v1.2.3-55-g7522