diff options
| author | Jonathan Bauer | 2015-08-21 15:59:03 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2015-08-21 15:59:03 +0200 |
| commit | 32f69464f571f7db8d8aa82df965588da0adc636 (patch) | |
| tree | f83141da824ab74bb4b36d22318dd5c3f1caf73d | |
| parent | [client] ThriftActions & calls in LectureWizard (diff) | |
| download | tutor-module-32f69464f571f7db8d8aa82df965588da0adc636.tar.gz tutor-module-32f69464f571f7db8d8aa82df965588da0adc636.tar.xz tutor-module-32f69464f571f7db8d8aa82df965588da0adc636.zip | |
[client] more ThriftActions
3 files changed, 151 insertions, 62 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java index cc778e54..e712904a 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java @@ -42,7 +42,7 @@ import org.openslx.dozmod.permissions.ImagePerms; import org.openslx.dozmod.thrift.Session; import org.openslx.dozmod.thrift.ThriftActions; import org.openslx.dozmod.thrift.ThriftActions.DeleteCallback; -import org.openslx.dozmod.thrift.ThriftActions.MetadataCallback; +import org.openslx.dozmod.thrift.ThriftActions.ImageMetaCallback; import org.openslx.dozmod.thrift.ThriftError; import org.openslx.dozmod.thrift.cache.MetaDataCache; import org.openslx.dozmod.thrift.cache.UserCache; @@ -228,7 +228,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe // Just prime the cache... MetaDataCache.getOperatingSystems(); MetaDataCache.getVirtualizers(); - final MetadataCallback callback = new MetadataCallback() { + final ImageMetaCallback callback = new ImageMetaCallback() { @Override public void fetchedImageDetails(ImageDetailsRead details) { LOGGER.debug("detail cb: " + details); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java index 6c16debd..6ec5a554 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java @@ -29,8 +29,10 @@ import org.openslx.dozmod.gui.window.UserListWindow.UserAddedCallback; import org.openslx.dozmod.gui.window.layout.LectureDetailsWindowLayout; import org.openslx.dozmod.permissions.LecturePerms; import org.openslx.dozmod.thrift.Session; -import org.openslx.dozmod.thrift.ThriftError; import org.openslx.dozmod.thrift.ThriftActions; +import org.openslx.dozmod.thrift.ThriftActions.ImageMetaCallback; +import org.openslx.dozmod.thrift.ThriftActions.LectureMetaCallback; +import org.openslx.dozmod.thrift.ThriftError; import org.openslx.dozmod.thrift.cache.UserCache; import org.openslx.dozmod.util.FormatHelper; import org.openslx.thrifthelper.ThriftManager; @@ -117,37 +119,40 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements * @param lectureId the id of the lecture to be displayed */ public void setLecture(final String lectureId) { - QuickTimer.scheduleOnce(new Task() { - @Override - public void fire() { - TException error = null; - try { - synchronized (me) { - if (lecture != null) - return; - lecture = ThriftManager.getSatClient().getLectureDetails(Session.getSatelliteToken(), - lectureId); - image = ThriftManager.getSatClient().getImageDetails(Session.getSatelliteToken(), - lecture.getImageBaseId()); + synchronized (me) { + if (lecture != null) + return; + + // teh fugleh + final Frame parentFrame = JOptionPane.getFrameForComponent(me); + ThriftActions.getLectureDetails(parentFrame, lectureId, new LectureMetaCallback() { + @Override + public void fetchedLectureDetails(LectureRead lectureDetails) { + if (lectureDetails != null) { + lecture = lectureDetails; + ThriftActions.getImageDetails(parentFrame, lecture.getImageBaseId(), new ImageMetaCallback() { + @Override + public void fetchedImageDetails(ImageDetailsRead imageDetails) { + if (imageDetails != null) { + image = imageDetails; + if (lecture != null) + fill(); + } + } + @Override + public void fetchedImagePermissions(Map<String, ImagePermissions> permissions) { + return; + } + }); } - } catch (TException e) { - error = e; } - final TException e = error; - Gui.asyncExec(new Runnable() { - @Override - public void run() { - if (e != null || lecture == null || image == null) { - ThriftError.showMessage(btnAutoUpdate, LOGGER, e, - "Konnte Daten der Vorlesung nicht abrufen"); - dispose(); - } else { - fill(); - } - } - }); - } - }); + @Override + public void fetchedLecturePermissions(Map<String, LecturePermissions> permissions) { + return; + } + }); + + } } /** @@ -209,27 +214,20 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements } private void setLectureOwner(final UserInfo user) { - QuickTimer.scheduleOnce(new Task() { - @Override - public void fire() { - try { - ThriftManager.getSatClient().setLectureOwner(Session.getSatelliteToken(), - lecture.getLectureId(), user.getUserId()); - } catch (TException e) { - ThriftError.showMessage(me, LOGGER, e, "Fehler beim Übertragen der Besitzrechte"); - return; - } - Gui.showMessageBox(me, "Besitzrechte übertragen an " + FormatHelper.userName(user), - MessageType.INFO, null, null); - makeEditable(false); - String lectureId = lecture.getLectureId(); - synchronized (me) { - image = null; - lecture = null; - } - setLecture(lectureId); - } - }); + if (!ThriftActions.setLectureOwner(JOptionPane.getFrameForComponent(this), + lecture.getLectureId(), user)) { + return; + } + // success + Gui.showMessageBox(me, "Besitzrechte übertragen an " + FormatHelper.userName(user), + MessageType.INFO, null, null); + makeEditable(false); + String lectureId = lecture.getLectureId(); + synchronized (me) { + image = null; + lecture = null; + } + setLecture(lectureId); } /** 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 19ada0f2..be4caa2b 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java @@ -18,10 +18,11 @@ import org.openslx.bwlp.thrift.iface.ImageDetailsRead; import org.openslx.bwlp.thrift.iface.ImagePermissions; import org.openslx.bwlp.thrift.iface.ImageVersionWrite; import org.openslx.bwlp.thrift.iface.LecturePermissions; +import org.openslx.bwlp.thrift.iface.LectureRead; import org.openslx.bwlp.thrift.iface.LectureWrite; import org.openslx.bwlp.thrift.iface.TAuthorizationException; -import org.openslx.bwlp.thrift.iface.TImageDataException; import org.openslx.bwlp.thrift.iface.TransferInformation; +import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.dozmod.Config; import org.openslx.dozmod.filetransfer.AsyncHashGenerator; import org.openslx.dozmod.filetransfer.DownloadTask; @@ -31,8 +32,7 @@ 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.dozmod.gui.wizard.LectureWizard; -import org.openslx.dozmod.thrift.cache.MetaDataCache; +import org.openslx.dozmod.util.FormatHelper; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; @@ -349,14 +349,12 @@ public class ThriftActions { * Fetches image details or permissions * ********************************************************************************/ - public interface MetadataCallback { + public interface ImageMetaCallback { void fetchedImageDetails(ImageDetailsRead details); void fetchedImagePermissions(Map<String, ImagePermissions> permissions); -// void fetchedLectureDetails(LectureRead details); -// void fetchedLecturePermissions(Map<String, ImagePermissions> permissions); } - public static void getImageDetails(final Frame frame, final String imageBaseId, final MetadataCallback callback) { + public static void getImageDetails(final Frame frame, final String imageBaseId, final ImageMetaCallback callback) { QuickTimer.scheduleOnce(new Task() { ImageDetailsRead details = null; @Override @@ -386,7 +384,7 @@ public class ThriftActions { * @param imageBaseId * @param callback */ - public static void getImagePermissions(final Frame frame, final String imageBaseId, final MetadataCallback callback) { + public static void getImagePermissions(final Frame frame, final String imageBaseId, final ImageMetaCallback callback) { QuickTimer.scheduleOnce(new Task() { Map<String, ImagePermissions> permissionMap = null; @Override @@ -534,7 +532,100 @@ public class ThriftActions { } return true; } - + /* ******************************************************************************* + * + * LECTURE METADATA + * + * Methods to push metadata of lectures + * + ********************************************************************************/ + /** + * @author joe + * + */ + public interface LectureMetaCallback { + void fetchedLectureDetails(LectureRead details); + void fetchedLecturePermissions(Map<String, LecturePermissions> permissions); + } + /** + * @param frame + * @param lectureId + * @param callback + */ + public static void getLectureDetails(final Frame frame, final String lectureId, final LectureMetaCallback callback) { + QuickTimer.scheduleOnce(new Task() { + LectureRead lecture = null; + @Override + public void fire() { + try { + + lecture = ThriftManager.getSatClient().getLectureDetails(Session.getSatelliteToken(), lectureId); + } catch (TException e) { + ThriftError.showMessage(frame, LOGGER, e, "Konnte Veranstaltungdaten nicht abrufen"); + if (callback != null) + callback.fetchedLectureDetails(null); + return; + } + Gui.asyncExec(new Runnable() { + @Override + public void run() { + if (callback != null) { + callback.fetchedLectureDetails(lecture); + } + } + }); + } + }); + } + /** + * @param frame + * @param lectureId + * @param callback + */ + public static void getLecturePermissions(final Frame frame, final String lectureId, final LectureMetaCallback callback) { + QuickTimer.scheduleOnce(new Task() { + Map<String, LecturePermissions> permissions = null; + @Override + public void fire() { + try { + + permissions = ThriftManager.getSatClient().getLecturePermissions(Session.getSatelliteToken(), lectureId); + } catch (TException e) { + ThriftError.showMessage(frame, LOGGER, e, "Konnte Veranstaltungdaten nicht abrufen"); + if (callback != null) + callback.fetchedLecturePermissions(null); + return; + } + Gui.asyncExec(new Runnable() { + @Override + public void run() { + if (callback != null) { + callback.fetchedLecturePermissions(permissions); + } + } + }); + } + }); + } + /** + * 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 setLectureOwner(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; + } /* ******************************************************************************* * * PRIVATE HELPERS |
