summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java
diff options
context:
space:
mode:
authorStephan Schwaer2015-10-27 17:45:37 +0100
committerStephan Schwaer2015-10-27 17:45:37 +0100
commitc1e86bdfb57a71fbe1a90100b03964bf05f0aea1 (patch)
treea799fcd7aa04920213de8000ebbbabb59e49f7c9 /dozentenmodul/src/main/java
parent[client] Add two floppy drives to vmx of downloaded VM (diff)
downloadtutor-module-c1e86bdfb57a71fbe1a90100b03964bf05f0aea1.tar.gz
tutor-module-c1e86bdfb57a71fbe1a90100b03964bf05f0aea1.tar.xz
tutor-module-c1e86bdfb57a71fbe1a90100b03964bf05f0aea1.zip
[client] Clean up deleteLectures and improve it's user feadback.
Diffstat (limited to 'dozentenmodul/src/main/java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java54
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java54
2 files changed, 53 insertions, 55 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java
index d81ed319..882309d6 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java
@@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
+import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@@ -28,6 +29,7 @@ import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.bwlp.thrift.iface.LectureSummary;
@@ -380,43 +382,31 @@ public class LectureListWindow extends LectureListWindowLayout {
}
/**
- * Deletes the given lecture
- */
- private void deleteLecture(final LectureSummary lecture) {
- if (lecture == null)
- return;
- ThriftActions.deleteLecture(JOptionPane.getFrameForComponent(me), lecture.getLectureId(),
- new DeleteLectureCallback() {
- @Override
- public void deleted(boolean success) {
- refreshList(success);
- }
- });
- }
-
- /**
* Delete a list of lectures and display the lectures, which couldn't be
* deleted.
*
- * @param lectureList the images to be deleted.
+ * @param lectureList the lectures to be deleted.
*/
private void deleteLectures(List<LectureSummary> lectureList) {
- boolean failedToDeleteAll = false;
- StringBuilder builder = new StringBuilder();
- for (LectureSummary lecture : lectureList) {
- if (LecturePerms.canAdmin(lecture)) {
- deleteLecture(lecture);
- } else {
- failedToDeleteAll = true;
- builder.append('\n');
- builder.append(lecture.lectureName);
- }
- }
- if (failedToDeleteAll) {
- Gui.showMessageBox(
- "Folgende Veranstaltungen konnten nicht gelöscht werden: " + builder.toString(),
- MessageType.INFO, LOGGER, null);
- }
+
+ ThriftActions.deleteLecture(JOptionPane.getFrameForComponent(me), lectureList,
+ new DeleteLectureCallback() {
+ @Override
+ public void deleted(Map<LectureSummary, TException> fLectures) {
+ refreshList(true);
+ if (fLectures.size() > 0) {
+ StringBuilder builder = new StringBuilder();
+ for (LectureSummary lecture : fLectures.keySet()) {
+ builder.append('\n');
+ builder.append(lecture.lectureName);
+ LOGGER.error("Couldn't delete lecture " + lecture.lectureName + ", reason:", fLectures.get(lecture) );
+ // TODO Should the exception be printed in the debugger or is this to much information?
+ }
+ Gui.showMessageBox("Folgende Veranstaltungen konnten nicht gelöscht werden: "
+ + builder.toString(), MessageType.INFO, LOGGER, null);
+ }
+ }
+ });
}
/**
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 6a7be596..b1c21cff 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
@@ -6,6 +6,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -146,7 +147,7 @@ public class ThriftActions {
remoteVersion = 1; // Assume something old
}
}
-
+
if (client == null || remoteVersion == -1) {
if (interactive) {
Gui.asyncMessageBox(
@@ -157,19 +158,18 @@ public class ThriftActions {
}
return false;
}
-
+
if (remoteVersion != Version.VERSION) {
if (interactive) {
Gui.asyncMessageBox("Das von Ihnen verwendete Dozentenmodul ist nicht mit dem"
- + " gewählten Satelliten-Server kompatibel.\n"
- + "Ihre Version: "+ Version.VERSION + "\n"
- + "Satelliten-Version: " + remoteVersion,
+ + " gewählten Satelliten-Server kompatibel.\n" + "Ihre Version: "
+ + Version.VERSION + "\n" + "Satelliten-Version: " + remoteVersion,
MessageType.ERROR, LOGGER, null);
continue;
}
return false;
}
-
+
// all good, try to get the whoami info
try {
whoami = client.whoami(satToken);
@@ -177,7 +177,7 @@ public class ThriftActions {
if (interactive) {
ThriftError.showMessage(window, LOGGER, e,
"Authentifizierung erfolgreich, der Satelliten-Server verweigert jedoch die Verbindung.\n"
- + "Versuchen Sie, sich erneut anzumelden.\n");
+ + "Versuchen Sie, sich erneut anzumelden.\n");
}
return false;
} catch (TException e) {
@@ -197,7 +197,7 @@ public class ThriftActions {
return false;
}
} while (interactive && whoami == null);
-
+
if (whoami != null) {
Session.initialize(whoami, address, satToken, masterToken);
ThriftManager.setSatelliteAddress(
@@ -783,7 +783,8 @@ public class ThriftActions {
questionText += "\nWollen Sie diese Version samt Veranstaltungen löschen?\n";
}
if (!matches)
- questionText = "Wollen Sie die Image-Version vom " + FormatHelper.shortDate(version.createTime) + " Uhr wirklich löschen?";
+ questionText = "Wollen Sie die Image-Version vom " + FormatHelper.shortDate(version.createTime)
+ + " Uhr wirklich löschen?";
if (!userConfirmed(frame, questionText))
return;
@@ -987,38 +988,45 @@ public class ThriftActions {
* Callback interface reporting the status of the deletion back to the gui
*/
public interface DeleteLectureCallback {
- void deleted(boolean success);
+ void deleted(Map<LectureSummary, TException> failedLectures);
}
/**
- * NON-BLOCKING Deletes the lecture with the given lectureId
+ * NON-BLOCKING Deletes the lectures of the given list
*
* @param frame to display user feedback on
- * @param lectureId id of the lecture to delete
- * @param callback interface to report the status back to the gui
+ * @param list of lectures to be deleted
+ * @param callback interface to report the lectures, which haven't been
+ * deleted.
*/
- public static void deleteLecture(final Frame frame, final String lectureId,
+ public static void deleteLecture(final Frame frame, final List<LectureSummary> lectures,
final DeleteLectureCallback callback) {
- if (lectureId == null)
+ if (lectures == null)
return;
- if (!userConfirmed(frame, "Wollen Sie diese Veranstaltung wirklick löschen?"))
+ String messageText = lectures.size() == 1 ? "Wollen Sie diese Veranstaltung wirklich löschen?"
+ : "Wollen Sie die " + lectures.size() + " Veranstaltungen wirklich löschen?";
+ if (!userConfirmed(frame, messageText))
return;
+
QuickTimer.scheduleOnce(new Task() {
- boolean success = false;
+ Map<LectureSummary, TException> failedLectures = new HashMap<LectureSummary, TException>();
@Override
public void fire() {
- try {
- ThriftManager.getSatClient().deleteLecture(Session.getSatelliteToken(), lectureId);
- success = true;
- } catch (TException e) {
- ThriftError.showMessage(frame, LOGGER, e, "Konnte Veranstaltungdaten nicht abrufen");
+ for (final LectureSummary l : lectures) {
+ if (l == null)
+ continue;
+ try {
+ ThriftManager.getSatClient().deleteLecture(Session.getSatelliteToken(), l.lectureId);
+ } catch (TException e) {
+ failedLectures.put(l, e);
+ }
}
Gui.asyncExec(new Runnable() {
@Override
public void run() {
if (callback != null) {
- callback.deleted(success);
+ callback.deleted(failedLectures);
}
}
});