diff options
author | Jonathan Bauer | 2016-04-27 17:24:15 +0200 |
---|---|---|
committer | Jonathan Bauer | 2016-04-27 17:24:15 +0200 |
commit | a40ddb0a580348d68ff0c515275ffa252b686c1e (patch) | |
tree | e2436a05c935fd7b6c408e4cafb5be5dce6e16ce | |
parent | [server] Fix upload handling if image already exists (diff) | |
download | tutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.tar.gz tutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.tar.xz tutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.zip |
[client] first working draft for published images stuff
18 files changed, 743 insertions, 96 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java index ed2645ff..97384ab0 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java @@ -38,7 +38,7 @@ public class App { // Logger private final static Logger LOGGER = Logger.getLogger(App.class); - public static final String MASTER_SERVER_ADDRESS = "bwlp-masterserver.ruf.uni-freiburg.de"; + private static final String MASTER_SERVER_ADDRESS = "bwlp-masterserver.ruf.uni-freiburg.de"; public static final int THRIFT_PORT = 9090; @@ -48,6 +48,8 @@ public class App { private static Thread proxyThread = null; + private static String masterServerHost = null; + private static void setupLogger() { // path to the log file @@ -167,6 +169,8 @@ public class App { port = THRIFT_SSL_PORT; useSsl = true; } + // remember masterserver host + masterServerHost = host; if (useSsl) { try { SSLContext ctx = SSLContext.getInstance("TLSv1.2"); @@ -298,4 +302,8 @@ public class App { public static synchronized boolean isInitDone() { return proxyThread == null; } + + public static synchronized String getMasterServerAddress() { + return masterServerHost; + } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java index 1d9b8571..5a7fd9d2 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java @@ -28,7 +28,6 @@ import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.dozmod.gui.helper.TextChangeListener; import org.openslx.dozmod.permissions.ImagePerms; import org.openslx.dozmod.thrift.Session; -import org.openslx.dozmod.thrift.ThriftActions; import org.openslx.dozmod.thrift.cache.ImageCache; import org.openslx.dozmod.thrift.cache.UserCache; import org.openslx.util.QuickTimer; @@ -37,13 +36,17 @@ import org.openslx.util.QuickTimer.Task; @SuppressWarnings("serial") public class ImageListViewer extends QLabel { - private static final Logger LOGGER = Logger.getLogger(ThriftActions.class); + private static final Logger LOGGER = Logger.getLogger(ImageListViewer.class); + // search/filter components protected JTextField searchTextField; - protected ImageTable imageTable; protected JComboBox<FilterType> filterCbo; protected JLabel imageCountLabel; + // image table + protected ImageTable imageTable; + + private final RowFilter<ListModel<ImageSummaryRead>, Integer> filterOwn = new RowFilter<ListModel<ImageSummaryRead>, Integer>() { public boolean include(Entry<? extends ListModel<ImageSummaryRead>, ? extends Integer> entry) { ImageSummaryRead img = imageTable.getModelRow(entry.getIdentifier()); @@ -134,14 +137,12 @@ public class ImageListViewer extends QLabel { imageCountPanel.add(new JLabel("Sichtbar:")); imageCountPanel.add(imageCountLabel); filterPanel.add(imageCountPanel); - - // the actual table - imageTable = new ImageTable(); - grid.add(filterPanel).fill(true, false).expand(true, false); grid.nextRow(); - QScrollPane jsp = new QScrollPane(imageTable); + // the actual image table + imageTable = new ImageTable(); + QScrollPane jsp = new QScrollPane(imageTable); jsp.setBackground(UIManager.getColor("Table.background")); grid.add(jsp).fill(true, true).expand(true, true); grid.finish(false); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImagePublishedTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImagePublishedTable.java new file mode 100644 index 00000000..d2e96e63 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImagePublishedTable.java @@ -0,0 +1,75 @@ +package org.openslx.dozmod.gui.control.table; + +import java.util.Comparator; + +import org.openslx.bwlp.thrift.iface.ImageSummaryRead; +import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.dozmod.thrift.Sorters; +import org.openslx.dozmod.thrift.cache.MetaDataCache; +import org.openslx.dozmod.thrift.cache.OrganizationCache; +import org.openslx.dozmod.thrift.cache.UserCache; +import org.openslx.dozmod.util.FormatHelper; + +@SuppressWarnings("serial") +public class ImagePublishedTable extends ListTable<ImageSummaryRead> { + +// public static final ListTableColumn COL_TEMPLATE = new ListTableColumn("Vorlage", Boolean.class); +// public static final ListTableColumn COL_USABLE = new ListTableColumn("Verwendbar", Boolean.class); +// public static final ListTableColumn COL_SIZE = new ListTableColumn("Größe", Long.class); +// public static final ListTableColumn COL_LASTCHANGE = new ListTableColumn("Geändert", Long.class); + public static final ListTableColumn COL_NAME = new ListTableColumn("Name"); + public static final ListTableColumn COL_OS = new ListTableColumn("OS", Integer.class, Sorters.osNameById); + public static final ListTableColumn COL_OWNER = new ListTableColumn("Besitzer", Sorters.userName); + public static final ListTableColumn COL_UPLOADER = new ListTableColumn("Hochgeladen von", Sorters.userName); + public static final ListTableColumn COL_ORG = new ListTableColumn("Organisation"); + + public ImagePublishedTable() { + super(new Comparator<ImageSummaryRead>() { + @Override + public int compare(ImageSummaryRead o1, ImageSummaryRead o2) { + if (o1 == null && o2 == null) + return 0; + if (o1 == null) + return 1; + if (o2 == null) + return -1; + return o1.imageBaseId.compareTo(o2.imageBaseId); + } + }, COL_NAME, COL_OS, COL_OWNER, COL_UPLOADER, COL_ORG); //, COL_LASTCHANGE, COL_SIZE, COL_USABLE, COL_TEMPLATE); + } + + // return the right value of our image (row) depending on given column + @Override + protected Object getValueAtInternal(ImageSummaryRead row, ListTableColumn column) { + if (column == COL_NAME) + return row.getImageName(); + if (column == COL_OS) + return row.getOsId(); + if (column == COL_OWNER) + return row.getOwnerId(); + if (column == COL_UPLOADER) + return row.getUploaderId(); + if (column == COL_ORG) { + UserInfo user = UserCache.find(row.getOwnerId()); + if (user != null) + return user.getOrganizationId(); + return null; + } + throw new IndexOutOfBoundsException(); + } + + @Override + public Object modelValueToDisplayFormat(Object value, ListTableColumn column) { + if (column == COL_NAME) + return value; + if (column == COL_OS) + return FormatHelper.osName(MetaDataCache.getOsById((int) value, true)); + if (column == COL_OWNER || column == COL_UPLOADER) + return FormatHelper.userName(UserCache.find((String) value)); + if (column == COL_ORG) { + return FormatHelper.orgName(OrganizationCache.find((String) value)); + } + throw new IndexOutOfBoundsException(); + } + +} 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 baa23b9a..3d4b7d0d 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 @@ -50,6 +50,7 @@ import org.openslx.dozmod.gui.window.layout.ImageDetailsWindowLayout; import org.openslx.dozmod.gui.wizard.ImageUpdateWizard; import org.openslx.dozmod.gui.wizard.LectureWizard; import org.openslx.dozmod.permissions.ImagePerms; +import org.openslx.dozmod.thrift.ImageDetailsActions; import org.openslx.dozmod.thrift.Session; import org.openslx.dozmod.thrift.ThriftActions; import org.openslx.dozmod.thrift.ThriftActions.DeleteCallback; @@ -76,7 +77,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe * Self-reference */ private final ImageDetailsWindow me = this; - + private final ImageDetailsActions actionHandler; /** * Callback interface to refresh image list after changing image details */ @@ -125,9 +126,11 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe * @param modalParent parent of this popup window * @param callback callback to be called when the image details have changed */ - public ImageDetailsWindow(Frame modalParent, ImageUpdatedCallback callback) { + public ImageDetailsWindow(Frame modalParent, ImageUpdatedCallback callback, ImageDetailsActions actionHandler) { super(modalParent); this.callback = callback; + this.actionHandler = actionHandler; + // Hook when user presses X (top right) setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @@ -374,7 +377,10 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe fillDetails(); } }; - ThriftActions.getImageFullDetails(JOptionPane.getFrameForComponent(me), imageBaseId, callback); + +// ThriftActions.getImageFullDetails(JOptionPane.getFrameForComponent(me), imageBaseId, callback); + actionHandler.getImageDetails(JOptionPane.getFrameForComponent(me), imageBaseId, callback); + //ThriftActions.getImageFullDetails(JOptionPane.getFrameForComponent(me), imageBaseId, callback); } /** @@ -383,7 +389,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe * @param user UserInfo to set the owner to */ private void setImageOwner(final UserInfo user) { - if (!ThriftActions.setImageOwner(JOptionPane.getFrameForComponent(me), image.getImageBaseId(), user)) { + if (!actionHandler.setImageOwner(JOptionPane.getFrameForComponent(me), image.getImageBaseId(), user)) { return; } Gui.showMessageBox(me, "Besitzrechte übertragen an " + FormatHelper.userName(user), MessageType.INFO, @@ -444,7 +450,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe if (originalDefaultPermissions.admin && permissionsChanged) { if (!writeImagePermMap()) return false; - LOGGER.info("Successfully saved new permissions"); + LOGGER.info("Successfully saved new default permissions"); permissionsChanged = false; } @@ -458,7 +464,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe image.defaultPermissions.admin), cboShareMode.getItemAt(cboShareMode.getSelectedIndex())); try { - ThriftActions.updateImageBase(image.getImageBaseId(), ibw); + actionHandler.updateImageBase(image.getImageBaseId(), ibw); } catch (TException e) { ThriftError.showMessage(me, LOGGER, e, "Konnte aktualisierte Metadaten nicht an den Server übermitteln"); @@ -472,7 +478,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe if (permissionsChanged) { if (!writeImagePermMap()) return false; - LOGGER.info("Successfully saved new permissions"); + LOGGER.info("Successfully saved new custom permissions"); permissionsChanged = false; } return true; @@ -480,7 +486,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe private boolean writeImagePermMap() { try { - ThriftActions.writeImagePermissions(image.getImageBaseId(), customPermissions); + actionHandler.writeImagePermissions(image.getImageBaseId(), customPermissions); } catch (TException e) { ThriftError.showMessage(me, LOGGER, e, "Konnte geänderte Berechtigungen nicht an den Server übermitteln"); @@ -499,6 +505,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe Gui.showMessageBox(this, "Ausgewählte Version ist ungültig", MessageType.ERROR, null, null); return; } + // using actionHandler here is not needed, as this ThriftAction works for downloads + // from either the master server or the satellite server ThriftActions.initDownload(JOptionPane.getFrameForComponent(this), selected.versionId, image.imageName, image.virtId, image.osId, selected.fileSize, null); } @@ -511,7 +519,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe private void deleteVersion(final ImageVersionDetails version) { if (version == null) return; - ThriftActions.deleteImageVersion(JOptionPane.getFrameForComponent(this), version, + actionHandler.deleteImageVersion(JOptionPane.getFrameForComponent(this), version, new DeleteCallback() { @Override public void isDeleted(boolean success) { @@ -609,10 +617,12 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } cboShareMode.setSelectedItem(image.getShareMode()); } - + String tagsString = ""; - for (String tag : image.getTags()) { - tagsString = tagsString + ", " + tag; + if (image.getTags() != null) { + for (String tag : image.getTags()) { + tagsString = tagsString + ", " + tag; + } } txtTags.setText(tagsString); @@ -715,8 +725,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe * @param modalParent parent of this window * @param imageBaseId id of the image to set the details of */ - public static void open(Frame modalParent, String imageBaseId, ImageUpdatedCallback callback) { - ImageDetailsWindow win = new ImageDetailsWindow(modalParent, callback); + public static void open(Frame modalParent, String imageBaseId, ImageUpdatedCallback callback, ImageDetailsActions actionHandler) { + ImageDetailsWindow win = new ImageDetailsWindow(modalParent, callback, actionHandler); win.setImage(imageBaseId); win.setVisible(true); } @@ -766,3 +776,4 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe return true; } } + diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java index fb76d0e1..b4814713 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java @@ -31,6 +31,7 @@ import org.openslx.dozmod.gui.window.layout.ImageListWindowLayout; import org.openslx.dozmod.gui.wizard.ImageCreationWizard; import org.openslx.dozmod.gui.wizard.LectureWizard; import org.openslx.dozmod.permissions.ImagePerms; +import org.openslx.dozmod.thrift.ImageLocalDetailsActions; import org.openslx.dozmod.thrift.ThriftActions; import org.openslx.dozmod.thrift.ThriftActions.DeleteCallback; import org.openslx.dozmod.thrift.ThriftActions.DownloadCallback; @@ -199,6 +200,12 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa deleteImages(imageTable.getSelectedItems()); } }); + btnShowPublishedImages.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ImagePublishedWindow.open(JOptionPane.getFrameForComponent(me)); + } + }); btnSwitchView.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -305,7 +312,7 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa public void updated() { ctlImageListViewer.refreshList(true, 100); } - }); + }, new ImageLocalDetailsActions()); } /** diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImagePublishedWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImagePublishedWindow.java new file mode 100644 index 00000000..056b1a4d --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImagePublishedWindow.java @@ -0,0 +1,205 @@ +package org.openslx.dozmod.gui.window; + +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.List; + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import org.apache.log4j.Logger; +import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.ImageSummaryRead; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.MainWindow; +import org.openslx.dozmod.gui.helper.UiFeedback; +import org.openslx.dozmod.gui.window.layout.ImagePublishedWindowLayout; +import org.openslx.dozmod.thrift.ImagePublishedDetailsActions; +import org.openslx.dozmod.thrift.Session; +import org.openslx.dozmod.thrift.ThriftActions; +import org.openslx.dozmod.thrift.ThriftActions.DownloadCallback; +import org.openslx.dozmod.thrift.ThriftError; +import org.openslx.dozmod.thrift.cache.ImagePublishedCache; +import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; + +public class ImagePublishedWindow extends ImagePublishedWindowLayout implements + UiFeedback, DownloadCallback { + + private final static Logger LOGGER = Logger + .getLogger(ImagePublishedWindow.class); + private final ImagePublishedWindow me = this; + + public ImagePublishedWindow(Frame modalParent) { + super(modalParent); + // Hook when user presses X (top right) + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + dispose(); + } + }); + btnClose.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + btnSatDownload.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ImageSummaryRead item = imagePublishedTable.getSelectedItem(); + if (item == null) + return; + String transferToken = null; + try { + transferToken = ThriftManager.getSatClient() + .requestImageReplication( + Session.getSatelliteToken(), + item.latestVersionId); + } catch (TException ex) { + ThriftError.showMessage(me, LOGGER, ex, + "Could not start download"); + } + MainWindow.addPassiveTransfer(transferToken, item.imageName, + false); + } + }); + btnDownload.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + final ImageSummaryRead item = imagePublishedTable + .getSelectedItem(); + if (item == null) + return; + btnDownload.setEnabled(false); + ThriftActions.initDownload( + (JFrame) SwingUtilities.getWindowAncestor(me), + item.latestVersionId, item.imageName, item.virtId, + item.osId, item.fileSize, null); + } + }); + + imagePublishedTable.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (SwingUtilities.isLeftMouseButton(e) + && e.getClickCount() == 2) { + ImageSummaryRead item = imagePublishedTable + .getSelectedItem(); + if (item == null || item.getImageBaseId() == null) + return; + ImageDetailsWindow.open( + (JFrame) SwingUtilities.getWindowAncestor(me), + item.getImageBaseId(), null, + new ImagePublishedDetailsActions()); + } + processClick(e); + } + + @Override + public void mousePressed(MouseEvent e) { + processClick(e); + } + + @Override + public void mouseReleased(MouseEvent e) { + processClick(e); + } + + private void processClick(MouseEvent e) { + // TODO popup menu? + } + }); + + // init data + refreshList(true, 0); + } + /** + * Callback when download initialized + * + * @param success true if downloading, false otherwise + */ + @Override + public void downloadInitialized(boolean success) { + if (!success) { + Gui.asyncExec(new Runnable() { + @Override + public void run() { + btnDownload.setEnabled(true); + } + }); + } + } + /** + * Refreshes the image list in the table + * + * @param forceRefresh + * true to force a refresh, false to use the cached list + */ + public void refreshList(final boolean forceRefresh, int delay) { + QuickTimer.scheduleOnce(new Task() { + @Override + public void fire() { + final List<ImageSummaryRead> imagePublishedList = ImagePublishedCache + .get(forceRefresh); + if (imagePublishedList == null) + return; + Gui.asyncExec(new Runnable() { + @Override + public void run() { + imagePublishedTable.setData(imagePublishedList, true); + } + }); + } + }, delay); + } + + /** + * Opens a new ImageDetailsWindow showing the details of the image with ID = + * imageBaseId + * + * @param modalParent + * parent of this window + * @param imageBaseId + * id of the image to set the details of + */ + public static void open(Frame modalParent) { + ImagePublishedWindow win = new ImagePublishedWindow(modalParent); + win.setVisible(true); + } + + /* ******************************************************************************* + * + * Dialog class overrides + * + * ************************************************************************** + * ***** + */ + @SuppressWarnings("deprecation") + @Override + public void show() { + if (!isVisible()) { + pack(); + MainWindow.centerShell(this); + } + super.show(); + } + + @Override + public boolean wantConfirmQuit() { + return false; + } + + @Override + public void escapePressed() { + dispose(); + } +}
\ No newline at end of file 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 a1477ba2..97027cc5 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 @@ -750,7 +750,6 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements pnlTabs.setEnabledAt(pnlTabs.indexOfTab("Berechtigungen"), editable && LecturePerms.canAdmin(lecture)); pnlTabs.setEnabledAt(pnlTabs.indexOfTab("Raumauswahl"), editable); pnlTabs.setEnabledAt(pnlTabs.indexOfTab("Erweitert"), editable); - // special shit for those shitty special buttons.... btnChangeOwner.setEnabled(LecturePerms.canAdmin(lecture)); btnDownloadImage.setEnabled(ImagePerms.canDownload(image)); } 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 c6f9a894..90404916 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 @@ -44,6 +44,7 @@ import org.openslx.dozmod.gui.window.LectureDetailsWindow.LectureUpdatedCallback import org.openslx.dozmod.gui.window.layout.LectureListWindowLayout; import org.openslx.dozmod.gui.wizard.LectureWizard; import org.openslx.dozmod.permissions.LecturePerms; +import org.openslx.dozmod.thrift.ImageLocalDetailsActions; import org.openslx.dozmod.thrift.Session; import org.openslx.dozmod.thrift.ThriftActions; import org.openslx.dozmod.thrift.ThriftActions.DeleteLectureCallback; @@ -244,7 +245,7 @@ public class LectureListWindow extends LectureListWindowLayout { } if (e.getSource().equals(popupItemLinked)) { - ImageDetailsWindow.open(JOptionPane.getFrameForComponent(me), lecture.imageBaseId, null); + ImageDetailsWindow.open(JOptionPane.getFrameForComponent(me), lecture.imageBaseId, null, new ImageLocalDetailsActions()); } if (e.getSource().equals(popupItemDelete)) { deleteLectures(tblLectures.getSelectedItems()); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java index fb83e911..c38686a3 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java @@ -2,8 +2,6 @@ package org.openslx.dozmod.gui.window.layout; import java.awt.BorderLayout; import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.Box; @@ -12,17 +10,12 @@ import javax.swing.JButton; import javax.swing.JPanel; import org.apache.log4j.Logger; -import org.apache.thrift.TException; import org.openslx.dozmod.gui.Gui; -import org.openslx.dozmod.gui.MainWindow; import org.openslx.dozmod.gui.control.ImageListViewer; import org.openslx.dozmod.gui.control.ImageListViewer.FilterType; import org.openslx.dozmod.gui.control.QLabel; import org.openslx.dozmod.gui.helper.CompositePage; import org.openslx.dozmod.gui.helper.GridManager; -import org.openslx.dozmod.thrift.Session; -import org.openslx.dozmod.thrift.ThriftError; -import org.openslx.thrifthelper.ThriftManager; @SuppressWarnings("serial") public abstract class ImageListWindowLayout extends CompositePage { @@ -30,7 +23,7 @@ public abstract class ImageListWindowLayout extends CompositePage { private final static Logger LOGGER = Logger.getLogger(ImageListWindowLayout.class); private static final int ICON_SIZE_Y = 24; - + private final ImageListWindowLayout me = this; protected final static String infoTextString = "Hier können Sie Virtuelle Maschinen hochladen, herunterladen, bearbeiten und löschen."; protected final static String infoTitleString = "Übersicht Virtuelle Maschinen"; protected final static String newButtonLabel = "Neue VM"; @@ -39,6 +32,7 @@ public abstract class ImageListWindowLayout extends CompositePage { protected final static String downloadButtonLabel = "Download"; protected final static String deleteButtonLabel = "Löschen"; protected final static String switchViewButtonLabel = "Veranstaltungen zeigen"; + protected final static String showPublishedImagesLabel = "Öffentliche VMs anzeigen"; // -------------------------------------- // search field, table and buttons @@ -49,6 +43,7 @@ public abstract class ImageListWindowLayout extends CompositePage { protected final JButton btnDownload; protected final JButton btnDelete; protected final JButton btnSwitchView; + protected final JButton btnShowPublishedImages; public ImageListWindowLayout() { super(new BorderLayout()); @@ -80,6 +75,7 @@ public abstract class ImageListWindowLayout extends CompositePage { "New VM", ICON_SIZE_Y, buttonPanel)); btnNewLecture = new JButton(newLectureButtonLabel, Gui.getScaledIconResource( "/img/new-lecture-icon.png", "New Lecture", ICON_SIZE_Y, buttonPanel)); + btnShowPublishedImages = new JButton(showPublishedImagesLabel, null); // TODO icon btnSwitchView = new JButton(switchViewButtonLabel, Gui.getScaledIconResource("/img/switch-icon.png", "Switch", ICON_SIZE_Y, buttonPanel)); buttonPanel.add(btnNewVm); @@ -89,30 +85,11 @@ public abstract class ImageListWindowLayout extends CompositePage { buttonPanel.add(btnDownload); buttonPanel.add(Box.createHorizontalStrut(5)); buttonPanel.add(btnNewLecture); + buttonPanel.add(Box.createHorizontalStrut(5)); + buttonPanel.add(btnShowPublishedImages); buttonPanel.add(Box.createHorizontalGlue()); buttonPanel.add(btnSwitchView); - /* - * WARNING: Test crap - */ - JButton butt = new JButton("LOL"); - butt.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - try { - String token = ThriftManager.getSatClient().requestImageReplication(Session.getSatelliteToken(), - "e9de1941-b673-4711-b033-d8c37d1e2d3e"); - MainWindow.addPassiveTransfer(token, "POO POO VM", false); - } catch (TException e1) { - ThriftError.showMessage(ImageListWindowLayout.this, null, e1, "BOO BOO"); - } - } - }); - buttonPanel.add(butt); - /* - * END TEST - */ - // put everything together GridManager grid = new GridManager(this, 1); grid.add(infoPanel).fill(true, false).expand(true, false); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImagePublishedWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImagePublishedWindowLayout.java new file mode 100644 index 00000000..26f53220 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImagePublishedWindowLayout.java @@ -0,0 +1,82 @@ +package org.openslx.dozmod.gui.window.layout; + +import java.awt.Window; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.UIManager; + +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.control.QLabel; +import org.openslx.dozmod.gui.control.table.ImagePublishedTable; +import org.openslx.dozmod.gui.control.table.QScrollPane; +import org.openslx.dozmod.gui.helper.GridManager; + +@SuppressWarnings("serial") +public class ImagePublishedWindowLayout extends JDialog { + + protected final ImagePublishedTable imagePublishedTable; + + protected final JButton btnDownload; + protected final JButton btnSatDownload; + protected final JButton btnClose; + protected final JTextField txtSearch; + + private static String title = "Öffentliche Images"; + + protected ImagePublishedWindowLayout(Window modalParent) { + super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL + : ModalityType.MODELESS); + + GridManager grid = new GridManager(this, 1); + + // --------------- filter field -------------------------------------- + JPanel filterPanel = new JPanel(); + filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.LINE_AXIS)); + filterPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); + filterPanel.add(new QLabel("Suchen: ")); + txtSearch = new JTextField(); + filterPanel.add(txtSearch); + // --------------- end filter field -------------------------------- + + // --------------- user table -------------------------------------- + JPanel listPane = new JPanel(); + listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); + listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + imagePublishedTable = new ImagePublishedTable(); + QScrollPane jsp = new QScrollPane(imagePublishedTable); + jsp.setBackground(UIManager.getColor("Table.background")); + listPane.add(jsp); + // --------------- end user table ------------------------------------ + + // --------------- button panel -------------------------------------- + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); + buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); + btnDownload = new JButton("Herunterladen"); + buttonPane.add(btnDownload); + btnSatDownload = new JButton("Auf Satellit herunterladen"); + buttonPane.add(btnSatDownload); + buttonPane.add(Box.createHorizontalGlue()); + btnClose = new JButton("Schließen"); + buttonPane.add(btnClose); + // --------------- end button panel ---------------------------------- + + // pack it all +// grid.add(filterPanel).fill(true, false).expand(true, false); +// grid.nextRow(); // TODO working search box + grid.add(listPane).fill(true, true).expand(true, true); + grid.nextRow(); + grid.add(buttonPane).fill(true, false).expand(true, false); + grid.nextRow(); + grid.finish(false); + + setPreferredSize(Gui.getScaledDimension(950, 400)); + pack(); + } +}
\ No newline at end of file diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageDetailsActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageDetailsActions.java new file mode 100644 index 00000000..2f8ad062 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageDetailsActions.java @@ -0,0 +1,27 @@ +package org.openslx.dozmod.thrift; + +import java.awt.Frame; +import java.util.Map; + +import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.ImageBaseWrite; +import org.openslx.bwlp.thrift.iface.ImagePermissions; +import org.openslx.bwlp.thrift.iface.ImageVersionDetails; +import org.openslx.bwlp.thrift.iface.TAuthorizationException; +import org.openslx.bwlp.thrift.iface.TInvocationException; +import org.openslx.bwlp.thrift.iface.TNotFoundException; +import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.dozmod.thrift.ThriftActions.DeleteCallback; +import org.openslx.dozmod.thrift.ThriftActions.DownloadCallback; +import org.openslx.dozmod.thrift.ThriftActions.ImageMetaCallback; + +public interface ImageDetailsActions { + public void getImageDetails(final Frame parent, final String imageBaseId, final ImageMetaCallback callback); + public boolean setImageOwner(final Frame parent, final String imageBaseId, final UserInfo user); + public void updateImageBase(final String imageBaseId, final ImageBaseWrite data) throws TException, TAuthorizationException, TNotFoundException, TInvocationException; + public void writeImagePermissions(final String imageBaseId, Map<String, ImagePermissions> customPermissions) throws TException, TAuthorizationException, TNotFoundException, TInvocationException; + public void initDownload(final Frame frame, final String imageVersionId, final String imageName, + final String virtualizerId, final int osId, final long imageSize, final DownloadCallback callback); + public void deleteImageVersion(final Frame frame, final ImageVersionDetails version, final DeleteCallback callback); + // TODO button enable function +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageLocalDetailsActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageLocalDetailsActions.java new file mode 100644 index 00000000..c72ad67e --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageLocalDetailsActions.java @@ -0,0 +1,78 @@ +package org.openslx.dozmod.thrift; + +import java.awt.Frame; +import java.util.Map; + +import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.ImageBaseWrite; +import org.openslx.bwlp.thrift.iface.ImageDetailsRead; +import org.openslx.bwlp.thrift.iface.ImagePermissions; +import org.openslx.bwlp.thrift.iface.ImageVersionDetails; +import org.openslx.bwlp.thrift.iface.TAuthorizationException; +import org.openslx.bwlp.thrift.iface.TInvocationException; +import org.openslx.bwlp.thrift.iface.TNotFoundException; +import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.thrift.ThriftActions.DeleteCallback; +import org.openslx.dozmod.thrift.ThriftActions.DownloadCallback; +import org.openslx.dozmod.thrift.ThriftActions.ImageMetaCallback; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; + +public class ImageLocalDetailsActions implements ImageDetailsActions { + + @Override + public void getImageDetails(final Frame parent, final String imageBaseId, final ImageMetaCallback callback) { + QuickTimer.scheduleOnce(new Task() { + ImageDetailsRead details = null; + Map<String, ImagePermissions> permissions = null; + + @Override + public void fire() { + details = ThriftActions.getImageDetails(parent, imageBaseId); + permissions = ThriftActions.getImagePermissions(parent, imageBaseId); + Gui.asyncExec(new Runnable() { + @Override + public void run() { + if (callback != null) { + callback.fetchedImageDetails(details, permissions); + } + } + }); + } + }); + } + + @Override + public boolean setImageOwner(final Frame parent, final String imageBaseId, final UserInfo user) { + return ThriftActions.setImageOwner(parent, imageBaseId, user); + } + + @Override + public void updateImageBase(final String imageBaseId, final ImageBaseWrite data) throws TException, TAuthorizationException, TNotFoundException, TInvocationException { + ThriftActions.updateImageBase(imageBaseId, data); + } + + @Override + public void writeImagePermissions(final String imageBaseId, Map<String, ImagePermissions> customPermissions) throws TException { + ThriftActions.writeImagePermissions(imageBaseId, customPermissions); + } + + @Override + public void initDownload(final Frame parent, final String imageVersionId, + final String imageName, final String virtualizerId, final int osId, final long imageSize, + final DownloadCallback callback) { + // TODO Auto-generated method stub + + } + + @Override + public void deleteImageVersion(final Frame parent, final ImageVersionDetails version, + final DeleteCallback callback) { + ThriftActions.deleteImageVersion(parent, version, callback); + + } + + + +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImagePublishedDetailsActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImagePublishedDetailsActions.java new file mode 100644 index 00000000..c60b2dfa --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImagePublishedDetailsActions.java @@ -0,0 +1,74 @@ +package org.openslx.dozmod.thrift; + +import java.awt.Frame; +import java.util.Map; + +import org.openslx.bwlp.thrift.iface.ImageBaseWrite; +import org.openslx.bwlp.thrift.iface.ImageDetailsRead; +import org.openslx.bwlp.thrift.iface.ImagePermissions; +import org.openslx.bwlp.thrift.iface.ImageVersionDetails; +import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.thrift.ThriftActions.DeleteCallback; +import org.openslx.dozmod.thrift.ThriftActions.DownloadCallback; +import org.openslx.dozmod.thrift.ThriftActions.ImageMetaCallback; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; + +public class ImagePublishedDetailsActions implements ImageDetailsActions{ + + @Override + public void getImageDetails(final Frame parent, final String imageBaseId, final ImageMetaCallback callback) { + QuickTimer.scheduleOnce(new Task() { + ImageDetailsRead details = null; + + @Override + public void fire() { + details = ThriftActions.getPublishedImageDetails(imageBaseId); + + Gui.asyncExec(new Runnable() { + @Override + public void run() { + if (callback != null) { + // send null permissions to forbid any action + callback.fetchedImageDetails(details, null); + } + } + }); + } + }); + + } + + @Override + public boolean setImageOwner(Frame parent, String imageBaseId, UserInfo user) { + return false; + } + + @Override + public void updateImageBase(String imageBaseId, ImageBaseWrite data) { + return; + } + + @Override + public void writeImagePermissions(String imageBaseId, + Map<String, ImagePermissions> customPermissions) { + return; + } + + @Override + public void initDownload(Frame frame, String imageVersionId, + String imageName, String virtualizerId, int osId, long imageSize, + DownloadCallback callback) { + // TODO download stuff + } + + @Override + public void deleteImageVersion(Frame frame, ImageVersionDetails version, + DeleteCallback callback) { + return; + } + + + +} 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 a6584bad..3467e4e9 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java @@ -407,20 +407,43 @@ public class ThriftActions { QuickTimer.scheduleOnce(new Task() { @Override public void fire() { - final TransferInformation transInf; + // since this function (initDownload) supports both download from the satellite and from the masterserver + // we simply try to download from the sat first and if that fails, we try to download from the masterserver + // this has the nice side effect, that if a download from the masterserver is requested, it tries + // to download that image from the sat first (which is probably faster than from the masterserver) + TException transEx = null; + String transHost = null; + TransferInformation transInf = null; try { transInf = ThriftManager.getSatClient().requestDownload(Session.getSatelliteToken(), imageVersionId); + transHost = Session.getSatelliteAddress(); } catch (TException e) { - ThriftError.showMessage(frame, LOGGER, e, "Die Download-Anfrage ist gescheitert"); + transEx = e; + } + if (transInf == null) { + // satellite denied download, try master + transHost = null; + try { + transInf = ThriftManager.getMasterClient().downloadImage(Session.getSatelliteToken(), + imageVersionId); + transHost = App.getMasterServerAddress(); + } catch (TException e) { + transEx = e; + } + } + if (transInf == null) { + // both download request failed, show user feedback + ThriftError.showMessage(frame, LOGGER, transEx, "Die Download-Anfrage ist gescheitert"); if (callback != null) callback.downloadInitialized(false); return; } - + final String fTransHost = transHost; + final TransferInformation fTransInf = transInf; final DownloadTask dlTask; try { - dlTask = new DownloadTask(Session.getSatelliteAddress(), transInf.getPlainPort(), + dlTask = new DownloadTask(fTransHost, transInf.getPlainPort(), transInf.getToken(), tmpDiskFile, imageSize, null); } catch (FileNotFoundException e) { Gui.asyncMessageBox( @@ -463,7 +486,7 @@ public class ThriftActions { destImage = tmpDiskFile; // Must be Windows... } try { - VmWrapper.wrapVm(destImage, imageName, transInf.getMachineDescription(), + VmWrapper.wrapVm(destImage, imageName, fTransInf.getMachineDescription(), virtualizerId, osId, diskImage); } catch (MetaDataMissingException | IOException e) { Gui.asyncMessageBox( @@ -517,7 +540,8 @@ public class ThriftActions { * *******************************************************************************/ /** - * Callback interface for image meta calls + * Callback interface for image meta calls. + * */ public interface ImageMetaCallback { void fetchedImageDetails(ImageDetailsRead details, Map<String, ImagePermissions> permissions); @@ -573,37 +597,6 @@ public class ThriftActions { } /** - * NON-BLOCKING Gets the image details and the user-specific permission list - * of - * the given imageBaseId. Will return the objects through the given callback - * - * @param frame to display user feedback on - * @param imageBaseId image's id to get the full details of - * @param callback interface called to return the details back to the gui - */ - public static void getImageFullDetails(final Frame frame, final String imageBaseId, - final ImageMetaCallback callback) { - QuickTimer.scheduleOnce(new Task() { - ImageDetailsRead details = null; - Map<String, ImagePermissions> permissions = null; - - @Override - public void fire() { - details = ThriftActions.getImageDetails(frame, imageBaseId); - permissions = ThriftActions.getImagePermissions(frame, imageBaseId); - Gui.asyncExec(new Runnable() { - @Override - public void run() { - if (callback != null) { - callback.fetchedImageDetails(details, permissions); - } - } - }); - } - }); - } - - /** * NON-BLOCKING Gets the user-specific permission list for the given * imageBaseId * @@ -1049,7 +1042,26 @@ public class ThriftActions { } }); } - + /* ******************************************************************************* + * + * PUBLIC IMAGES + * + * *******************************************************************************/ + /** + * BLOCKING Gets the image details of an image on the masterserver + * + * @param imageVersionId + * @return ImageDetailsRead if fetching the details worked, null otherwise. + */ + public static ImageDetailsRead getPublishedImageDetails(final String imageBaseId) { + ImageDetailsRead data = null; + try { + data = ThriftManager.getMasterClient().getImageDetails(Session.getMasterToken(), imageBaseId); + } catch (TException e) { + LOGGER.error("Could not query masterserver for ImagePublishData for version '" + imageBaseId + "':", e); + } + return data; + } /* ******************************************************************************* * * PRIVATE HELPERS diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java new file mode 100644 index 00000000..e57a4a24 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java @@ -0,0 +1,55 @@ +package org.openslx.dozmod.thrift.cache; + +import java.util.List; + +import org.apache.log4j.Logger; +import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.ImagePublishData; +import org.openslx.bwlp.thrift.iface.ImageSummaryRead; +import org.openslx.bwlp.thrift.iface.TAuthorizationException; +import org.openslx.bwlp.thrift.iface.TInvocationException; +import org.openslx.dozmod.gui.window.ImageListWindow; +import org.openslx.dozmod.thrift.Session; +import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.GenericDataCache; +import org.openslx.util.GenericDataCache.CacheMode; + +public class ImagePublishedCache { + + private final static Logger LOGGER = Logger.getLogger(ImagePublishedCache.class); + + private static final int CACHE_TIME_LIST_MS = 30 * 1000; + + private static final GenericDataCache<List<ImageSummaryRead>> listCache = new GenericDataCache<List<ImageSummaryRead>>( + CACHE_TIME_LIST_MS) { + @Override + protected List<ImageSummaryRead> update() + throws TAuthorizationException, TInvocationException, + TException { + List<ImageSummaryRead> result = null; + int pageSize = Session.getSatelliteConfig().pageSize; + for (int i = 0;; ++i) { + List<ImageSummaryRead> page = null; + try { + page = ThriftManager.getMasterClient().getPublicImages(Session.getMasterToken(), i); + } catch (TException e) { + LOGGER.error("Could not get the list of public images from the masterserver.", e); + } + if (result == null) { + result = page; + } else { + result.addAll(page); + } + if (page.size() < pageSize) + break; + } + return result; + } + }; + + public static List<ImageSummaryRead> get(boolean forceRefresh) { + return listCache.get(forceRefresh ? CacheMode.NEVER_CACHED + : CacheMode.DEFAULT); + } + +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java index 809c29fd..c831cd54 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java @@ -1,11 +1,13 @@ package org.openslx.dozmod.thrift.cache; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; +import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.UserInfo; -import org.openslx.bwlp.thrift.iface.Virtualizer; import org.openslx.dozmod.thrift.Session; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.GenericDataCache; @@ -45,6 +47,9 @@ public class UserCache { } }; + // map for caching users found on the masterserver + private static final Map<String, UserInfo> cachedUserFromMaster = new HashMap<String, UserInfo>(); + private UserCache() { // No instancing } @@ -70,11 +75,28 @@ public class UserCache { UserInfo user = find(userId, list); if (user != null) return user; + // still no user, look in local cache for master user + // TODO check validity of the map? + if (cachedUserFromMaster.containsKey(userId)) + return cachedUserFromMaster.get(userId); // Try again with a potential refresh List<UserInfo> newList = cache.get(CacheMode.DEFAULT); if (list == newList) // Returned list from cache as it was still recent enough return null; - return find(userId, newList); + user = find(userId, newList); + if (user == null) { + // not in cached map either, query master + try { + user = ThriftManager.getMasterClient().getUser(Session.getMasterToken(), userId); + } catch (TException e) { + LOGGER.error("User with ID '" + userId + "' not found on the masterserver."); + return null; + } + // remember it + if (user != null) + cachedUserFromMaster.put(userId, user); + } + return user; } private static UserInfo find(String userId, List<UserInfo> list) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java index 34108eaa..2580e209 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java @@ -11,6 +11,7 @@ import org.joda.time.format.PeriodFormat; import org.joda.time.format.PeriodFormatter; import org.openslx.bwlp.thrift.iface.Location; import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.Organization; import org.openslx.bwlp.thrift.iface.UserInfo; public class FormatHelper { @@ -162,4 +163,16 @@ public class FormatHelper { return "Unknown"; return location.getLocationName(); } + + /** + * Format the given organisation name. + * + * @param Organisation a {@link Organisation} instance + * @return Display name for that organisation, string "unknown" otherwise + */ + public static String orgName(Organization org) { + if (org == null) + return "Unknown"; + return org.getDisplayName(); + } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java index 96659989..cadae6f8 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java @@ -33,7 +33,7 @@ public class ProxyConfigurator { * Initialization method. */ public static void init() { - MasterServer.Client masterClient = ThriftManager.getNewMasterClient(null, App.MASTER_SERVER_ADDRESS, + MasterServer.Client masterClient = ThriftManager.getNewMasterClient(null, App.getMasterServerAddress(), App.THRIFT_PORT, 4000); if (masterClient != null) { try { |