Tomas Jelinek has uploaded a new change for review.

Change subject: userportal,webadmin: console error message translation ignored
......................................................................

userportal,webadmin: console error message translation ignored

When the SPICE or RDP console returns an error code, it was ignored.

Fixed by creating a common ConsoleModelErrorEventListener which listens on the
error events and if one occures, shows a popup dialog with the message. It
also translates the error code to human readable form.

This listener is than used in both userportal and webadmin for both RDP and
SPICE

This patch also deletes the unused ResourceManager and Assembly classes which
where not used anymore and had only empty implementations.

Change-Id: Iaa0b0d144dcaafffba8911c0cfa41670e179a7c5
Bug-Url: https://bugzilla.redhat.com/888774
Signed-off-by: Tomas Jelinek <[email protected]>
---
A 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/ConsoleErrorTranslator.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java
A 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModelErrorEventListener.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
D 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Assembly.java
A 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ConsoleErrorTranslator.java
A 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ConsoleErrors.java
M 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Messages.java
D 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ResourceManager.java
9 files changed, 197 insertions(+), 128 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/52/11052/1

diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/ConsoleErrorTranslator.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/ConsoleErrorTranslator.java
new file mode 100644
index 0000000..a963350
--- /dev/null
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/ConsoleErrorTranslator.java
@@ -0,0 +1,19 @@
+package org.ovirt.engine.ui.frontend;
+
+import java.util.MissingResourceException;
+
+
+import com.google.gwt.core.client.GWT;
+
+public class ConsoleErrorTranslator {
+
+    private static final ConsoleErrors consoleErrors = 
GWT.create(ConsoleErrors.class);
+
+    public String translateErrorCode(int errorCode) {
+        try {
+            return consoleErrors.getString("E" + errorCode); //$NON-NLS-1$
+        } catch (MissingResourceException e) {
+            return Integer.toString(errorCode);
+        }
+    }
+}
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java
index d0f40fa..2c36977 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java
@@ -18,6 +18,7 @@
 import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
 import org.ovirt.engine.ui.uicommonweb.models.ListWithDetailsModel;
 import org.ovirt.engine.ui.uicommonweb.models.vms.ConsoleModel;
+import 
org.ovirt.engine.ui.uicommonweb.models.vms.ConsoleModelErrorEventListener;
 import org.ovirt.engine.ui.uicommonweb.models.vms.ConsoleSelectionContext;
 import org.ovirt.engine.ui.uicommonweb.models.vms.RdpConsoleModel;
 import org.ovirt.engine.ui.uicommonweb.models.vms.SpiceConsoleModel;
@@ -174,9 +175,14 @@
                 SpiceConsoleModel spiceConsoleModel = new SpiceConsoleModel();
                 spiceConsoleModel.getErrorEvent().addListener(this);
                 spiceConsoleModel.setModel(this);
+                spiceConsoleModel.getErrorEvent().addListener(new 
ConsoleModelErrorEventListener(this));
+
                 VncConsoleModel vncConsoleModel = new VncConsoleModel();
                 vncConsoleModel.setModel(this);
+
                 RdpConsoleModel rdpConsoleModel = new RdpConsoleModel();
+                rdpConsoleModel.getErrorEvent().addListener(this);
+                rdpConsoleModel.getErrorEvent().addListener(new 
ConsoleModelErrorEventListener(this));
 
                 cachedConsoleModels.put(vm.getId(),
                         new ArrayList<ConsoleModel>(Arrays.asList(new 
ConsoleModel[] {
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModelErrorEventListener.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModelErrorEventListener.java
new file mode 100644
index 0000000..3c67147
--- /dev/null
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModelErrorEventListener.java
@@ -0,0 +1,82 @@
+package org.ovirt.engine.ui.uicommonweb.models.vms;
+
+import org.ovirt.engine.core.compat.Event;
+import org.ovirt.engine.core.compat.EventArgs;
+import org.ovirt.engine.core.compat.IEventListener;
+import org.ovirt.engine.ui.frontend.ConsoleErrorTranslator;
+import org.ovirt.engine.ui.uicommonweb.ICommandTarget;
+import org.ovirt.engine.ui.uicommonweb.UICommand;
+import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel;
+import org.ovirt.engine.ui.uicommonweb.models.Model;
+import org.ovirt.engine.ui.uicompat.ConstantsManager;
+
+/**
+ * Listens to error events of the ConsoleModel. If one catched, translates the 
error code to human readable message and
+ * displays a popup.
+ */
+public class ConsoleModelErrorEventListener implements IEventListener, 
ICommandTarget {
+
+    private ConsoleErrorTranslator consoleErrorCodeTranslator = new 
ConsoleErrorTranslator();
+
+    private Model parentModel;
+
+    public ConsoleModelErrorEventListener(Model parentModel) {
+        super();
+        this.parentModel = parentModel;
+    }
+
+    @Override
+    public void eventRaised(Event ev, Object sender, EventArgs args) {
+        if (ev.equals(ConsoleModel.ErrorEventDefinition)
+                && ((sender instanceof SpiceConsoleModel) || (sender 
instanceof RdpConsoleModel)))
+        {
+            consoleModelError(sender, getConsoleModelErrorMessage(sender, 
(ErrorCodeEventArgs) args));
+        }
+    }
+
+    private String getConsoleModelErrorMessage(Object sender, 
ErrorCodeEventArgs e) {
+        String translatedError = 
consoleErrorCodeTranslator.translateErrorCode(e.getErrorCode());
+
+        if (sender instanceof SpiceConsoleModel) {
+            return ConstantsManager.getInstance()
+                    .getMessages()
+                    .errConnectingVmUsingSpiceMsg(translatedError);
+        } else if (sender instanceof RdpConsoleModel) {
+            return ConstantsManager.getInstance()
+                    .getMessages()
+                    .errConnectingVmUsingRdpMsg(translatedError);
+        }
+
+        throw new IllegalArgumentException("Message recieved from an unknown 
model " + sender.getClass().getName()); //$NON-NLS-1$
+    }
+
+    private void consoleModelError(Object sender, String message) {
+        ConfirmationModel model = new ConfirmationModel();
+        if (parentModel.getConfirmWindow() == null)
+        {
+            parentModel.setConfirmWindow(model);
+        }
+        
model.setTitle(ConstantsManager.getInstance().getConstants().consoleDisconnectedTitle());
+        model.setHashName("console_disconnected"); //$NON-NLS-1$
+        model.setMessage(message);
+
+        UICommand tempVar = new UICommand("CancelError", this); //$NON-NLS-1$
+        
tempVar.setTitle(ConstantsManager.getInstance().getConstants().close());
+        tempVar.setIsDefault(true);
+        tempVar.setIsCancel(true);
+        model.getCommands().add(tempVar);
+    }
+
+    @Override
+    public void ExecuteCommand(UICommand command) {
+        if ("CancelError".equals(command.getName())) //$NON-NLS-1$
+        {
+            parentModel.setConfirmWindow(null);
+        }
+    }
+
+    @Override
+    public void ExecuteCommand(UICommand uiCommand, Object... parameters) {
+        ExecuteCommand(uiCommand);
+    }
+}
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
index af13928..a07314a 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
@@ -32,7 +32,6 @@
 import org.ovirt.engine.core.common.action.VmOperationParameterBase;
 import org.ovirt.engine.core.common.businessentities.Disk;
 import org.ovirt.engine.core.common.businessentities.Disk.DiskStorageType;
-import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.DisplayType;
 import org.ovirt.engine.core.common.businessentities.MigrationSupport;
@@ -47,6 +46,7 @@
 import org.ovirt.engine.core.common.businessentities.VolumeType;
 import org.ovirt.engine.core.common.businessentities.storage_domains;
 import org.ovirt.engine.core.common.businessentities.storage_pool;
+import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
 import org.ovirt.engine.core.common.interfaces.SearchType;
 import org.ovirt.engine.core.common.mode.ApplicationMode;
 import org.ovirt.engine.core.common.queries.GetAllDisksByVmIdParameters;
@@ -75,7 +75,6 @@
 import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel;
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicommonweb.models.ISupportSystemTreeContext;
-import org.ovirt.engine.ui.uicommonweb.models.Model;
 import org.ovirt.engine.ui.uicommonweb.models.SystemTreeItemModel;
 import org.ovirt.engine.ui.uicommonweb.models.configure.ChangeCDModel;
 import org.ovirt.engine.ui.uicommonweb.models.configure.PermissionListModel;
@@ -83,7 +82,6 @@
 import org.ovirt.engine.ui.uicommonweb.models.tags.TagModel;
 import org.ovirt.engine.ui.uicommonweb.models.templates.VmBaseListModel;
 import org.ovirt.engine.ui.uicommonweb.models.userportal.AttachCdModel;
-import org.ovirt.engine.ui.uicompat.Assembly;
 import org.ovirt.engine.ui.uicompat.ConstantsManager;
 import org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult;
 import org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult;
@@ -91,7 +89,6 @@
 import org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback;
 import org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback;
 import org.ovirt.engine.ui.uicompat.IFrontendMultipleQueryAsyncCallback;
-import org.ovirt.engine.ui.uicompat.ResourceManager;
 
 public class VmListModel extends VmBaseListModel<VM> implements 
ISupportSystemTreeContext
 {
@@ -308,22 +305,6 @@
     private void setAssignTagsCommand(UICommand value)
     {
         privateAssignTagsCommand = value;
-    }
-
-    private Model errorWindow;
-
-    public Model getErrorWindow()
-    {
-        return errorWindow;
-    }
-
-    public void setErrorWindow(Model value)
-    {
-        if (errorWindow != value)
-        {
-            errorWindow = value;
-            OnPropertyChanged(new PropertyChangedEventArgs("ErrorWindow")); 
//$NON-NLS-1$
-        }
     }
 
     private ConsoleModel defaultConsoleModel;
@@ -743,10 +724,12 @@
             if (!cachedConsoleModels.containsKey(vm.getId()))
             {
                 SpiceConsoleModel spiceConsoleModel = new SpiceConsoleModel();
-                spiceConsoleModel.getErrorEvent().addListener(this);
+                spiceConsoleModel.getErrorEvent().addListener(new 
ConsoleModelErrorEventListener(this));
                 VncConsoleModel vncConsoleModel = new VncConsoleModel();
                 vncConsoleModel.setModel(this);
+
                 RdpConsoleModel rdpConsoleModel = new RdpConsoleModel();
+                rdpConsoleModel.getErrorEvent().addListener(new 
ConsoleModelErrorEventListener(this));
 
                 cachedConsoleModels.put(vm.getId(),
                         new ArrayList<ConsoleModel>(Arrays.asList(new 
ConsoleModel[] {
@@ -951,7 +934,9 @@
                     for (int i = 0; i < result.getReturnValues().size(); i++) {
                         if (result.getReturnValues().get(i).getSucceeded()) {
                             Guid vmId = ((GetAllDisksByVmIdParameters) 
result.getParameters().get(i)).getVmId();
-                            initRemoveDisksChecboxesPost(vmId, (List<Disk>) 
result.getReturnValues().get(i).getReturnValue());
+                            initRemoveDisksChecboxesPost(vmId, (List<Disk>) 
result.getReturnValues()
+                                    .get(i)
+                                    .getReturnValue());
                         }
                     }
                 }
@@ -2648,11 +2633,6 @@
         setConfirmWindow(null);
     }
 
-    public void CancelError()
-    {
-        setErrorWindow(null);
-    }
-
     @Override
     protected void OnSelectedItemChanged()
     {
@@ -2748,35 +2728,6 @@
         {
             changeCD(sender, args);
         }
-        else if (ev.equals(ConsoleModel.ErrorEventDefinition) && sender 
instanceof SpiceConsoleModel)
-        {
-            SpiceConsoleModel_Error(sender, (ErrorCodeEventArgs) args);
-        }
-    }
-
-    private void SpiceConsoleModel_Error(Object sender, ErrorCodeEventArgs e)
-    {
-        ResourceManager rm =
-                new ResourceManager("UICommon.Resources.RdpErrors.RdpErrors", 
Assembly.GetExecutingAssembly()); //$NON-NLS-1$
-
-        ConfirmationModel model = new ConfirmationModel();
-        if (getErrorWindow() == null)
-        {
-            setErrorWindow(model);
-        }
-        
model.setTitle(ConstantsManager.getInstance().getConstants().consoleDisconnectedTitle());
-        model.setHashName("console_disconnected"); //$NON-NLS-1$
-        model.setMessage(ConstantsManager.getInstance()
-                .getMessages()
-                .errConnectingVmUsingSpiceMsg(rm.GetString("E" + 
e.getErrorCode()))); //$NON-NLS-1$
-
-        rm.ReleaseAllResources();
-
-        UICommand tempVar = new UICommand("CancelError", this); //$NON-NLS-1$
-        
tempVar.setTitle(ConstantsManager.getInstance().getConstants().close());
-        tempVar.setIsDefault(true);
-        tempVar.setIsCancel(true);
-        model.getCommands().add(tempVar);
     }
 
     @Override
@@ -2882,7 +2833,7 @@
         }
         else if (StringHelper.stringsEqual(command.getName(), "CancelError")) 
//$NON-NLS-1$
         {
-            CancelError();
+            setConfirmWindow(null);
         }
         else if (StringHelper.stringsEqual(command.getName(), "OnRunOnce")) 
//$NON-NLS-1$
         {
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Assembly.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Assembly.java
deleted file mode 100644
index 1cb790a..0000000
--- 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Assembly.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.ovirt.engine.ui.uicompat;
-
-public class Assembly {
-
-       public String FullName;
-
-/*     public AssemblyName GetName() {
-               // TODO Auto-generated method stub
-               return null;
-       }
-*/
-       public static Assembly GetExecutingAssembly() {
-               // TODO Auto-generated method stub
-               return null;
-       }
-/*
-       public static Assembly Load(String fullName2) {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       public Object[] getAnnotations() {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       public Class GetType(String string) {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       public Object getLocation() {
-               // TODO Auto-generated method stub
-               return null;
-       }
-*/
-}
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ConsoleErrorTranslator.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ConsoleErrorTranslator.java
new file mode 100644
index 0000000..e9f1915
--- /dev/null
+++ 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ConsoleErrorTranslator.java
@@ -0,0 +1,12 @@
+package org.ovirt.engine.ui.uicompat;
+
+import com.google.gwt.core.client.GWT;
+
+public class ConsoleErrorTranslator {
+    
+    private static final ConsoleErrors consoleErrors = 
GWT.create(ConsoleErrors.class);
+    
+    public String translateErrorCode(int errorCode) {
+        return consoleErrors.getString("E" + errorCode);
+    }
+}
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ConsoleErrors.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ConsoleErrors.java
new file mode 100644
index 0000000..d12b37c
--- /dev/null
+++ 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ConsoleErrors.java
@@ -0,0 +1,67 @@
+package org.ovirt.engine.ui.uicompat;
+
+import com.google.gwt.i18n.client.ConstantsWithLookup;
+
+public interface ConsoleErrors extends ConstantsWithLookup {
+    String E1028();
+
+    String E1030();
+
+    String E1032();
+
+    String E1286();
+
+    String E1288();
+
+    String E1540();
+
+    String E1542();
+
+    String E1544();
+
+    String E1796();
+
+    String E1798();
+
+    String E2052();
+
+    String E2054();
+
+    String E2308();
+
+    String E2310();
+
+    String E2566();
+
+    String E260();
+
+    String E262();
+
+    String E264();
+
+    String E2822();
+
+    String E3078();
+
+    String E516();
+
+    String E518();
+
+    String E520();
+
+    String E772();
+
+    String E774();
+
+    String E776();
+
+    String E2824();
+
+    String E107();
+
+    String E110();
+
+    String E111();
+
+    String E112();
+}
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Messages.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Messages.java
index 54da3ff..39f4503 100644
--- 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Messages.java
+++ 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Messages.java
@@ -99,6 +99,9 @@
     @DefaultMessage("Error connecting to Virtual Machine using Spice:\n{0}")
     String errConnectingVmUsingSpiceMsg(Object errCode);
 
+    @DefaultMessage("Error connecting to Virtual Machine using RPD:\n{0}")
+    String errConnectingVmUsingRdpMsg(Object errCode);
+
     @DefaultMessage("Are you sure you want to delete snapshot from {0} with 
description ''{1}''?")
     String areYouSureYouWantToDeleteSanpshot(Date from, Object description);
 
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ResourceManager.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ResourceManager.java
deleted file mode 100644
index 41e3daf..0000000
--- 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/ResourceManager.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.ovirt.engine.ui.uicompat;
-
-import org.ovirt.engine.ui.uicompat.Assembly;
-import org.ovirt.engine.core.compat.CultureInfo;
-import org.ovirt.engine.core.compat.NotImplementedException;
-
-public class ResourceManager {
-
-       public ResourceManager(String string, Assembly getExecutingAssembly) {
-               // TODO Auto-generated constructor stub
-       }
-
-/*
-       public Iterable<DictionaryEntry> GetResourceSet(String currentCulture, 
boolean b, boolean c) {
-               // TODO Auto-generated method stub
-               throw new NotImplementedException();
-       }
-*/
-       public String GetString(String key, CultureInfo currentCulture) {
-               // TODO Auto-generated method stub
-               throw new NotImplementedException();
-       }
-
-       public void ReleaseAllResources() {
-               // TODO Auto-generated method stub
-               throw new NotImplementedException();
-       }
-
-       public Object GetString(String string) {
-               // TODO Auto-generated method stub
-               throw new NotImplementedException();
-       }
-
-}


--
To view, visit http://gerrit.ovirt.org/11052
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa0b0d144dcaafffba8911c0cfa41670e179a7c5
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Tomas Jelinek <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to