market related changes merged into web UI
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 12 May 2016 19:34:28 +0000 (22:34 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 12 May 2016 19:34:28 +0000 (22:34 +0300)
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/ExportFileBuilder.java
webui/webapp/FileManager/src/org/netxms/ui/eclipse/filemanager/views/helpers/ViewAgentFilesProvider.java
webui/webapp/ServerConfig/META-INF/MANIFEST.MF
webui/webapp/ServerConfig/plugin.xml
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/Activator.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/ExportFileBuilder.java

index 3fd4892..c16ef57 100644 (file)
@@ -936,7 +936,7 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
        }
 
        /**
-        * Save settings
+        * Save exported configuration to file
         */
        private void save()
        {
index 21aedf1..2c0cb29 100644 (file)
@@ -54,7 +54,7 @@ public class ViewAgentFilesProvider implements ITreeContentProvider
        @Override
        public Object[] getChildren(final Object parentElement)
        {
-          if(((AgentFile)parentElement).getChildren() == null)
+          if (((AgentFile)parentElement).getChildren() == null)
           {
          ConsoleJob job = new ConsoleJob(Messages.get().ViewAgentFilesProvider_JobTitle, null, Activator.PLUGIN_ID, null) {
             @Override
index 5969c67..31345ee 100644 (file)
@@ -2,20 +2,20 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: NXMC Server Configuration Plug-in
 Bundle-SymbolicName: org.netxms.ui.eclipse.serverconfig;singleton:=true
-Bundle-Version: 2.0.6
+Bundle-Version: 2.0.8
 Bundle-Activator: org.netxms.ui.eclipse.serverconfig.Activator
 Bundle-Vendor: netxms.org
 Require-Bundle: org.eclipse.core.runtime;bundle-version="3.10.0",
  org.eclipse.rap.ui;bundle-version="2.3.1",
  org.eclipse.rap.ui.forms;bundle-version="2.3.1",
- org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.9",
+ org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.10",
  org.netxms.webui.core;bundle-version="2.0.10",
- org.netxms.ui.eclipse.filemanager;bundle-version="2.0.1",
+ org.netxms.ui.eclipse.filemanager;bundle-version="2.0.6",
  org.netxms.ui.eclipse.eventmanager;bundle-version="2.0.1",
- org.netxms.ui.eclipse.objectbrowser;bundle-version="2.0.3",
+ org.netxms.ui.eclipse.objectbrowser;bundle-version="2.0.7",
  org.netxms.ui.eclipse.nxsl;bundle-version="2.0.4",
  org.netxms.ui.eclipse.epp;bundle-version="2.0.4",
- org.netxms.ui.eclipse.objecttools;bundle-version="2.0.6",
+ org.netxms.ui.eclipse.objecttools;bundle-version="2.0.7",
  org.netxms.ui.eclipse.datacollection;bundle-version="2.0.5",
  org.eclipse.rap.addons.filedialog;bundle-version="0.6.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
index dbb129b..424081b 100644 (file)
             id="org.netxms.ui.eclipse.serverconfig.commands.open_scheduled_tasks"
             name="Scheduled tasks">
       </command>
+      <command
+            id="org.netxms.ui.eclipse.serverconfig.commands.publish_config"
+            name="Publish configuration">
+      </command>
    </extension>
 
    <extension point = "org.eclipse.ui.actionSets">
             schemeId="org.netxms.ui.eclipse.defaultKeyBinding"
             sequence="M1+N">
       </key>
+      <key
+            commandId="org.netxms.ui.eclipse.serverconfig.commands.publish_config"
+            contextId="org.netxms.ui.eclipse.serverconfig.context.ExportFileBuilder"
+            schemeId="org.netxms.ui.eclipse.defaultKeyBinding"
+            sequence="M1+P">
+      </key>
    </extension>
    <extension
          point="org.eclipse.ui.activities">
index 6cd8308..e0bf791 100644 (file)
@@ -1,5 +1,6 @@
 package org.netxms.ui.eclipse.serverconfig;
 
+import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
@@ -70,4 +71,35 @@ public class Activator extends AbstractUIPlugin
        {
                return imageDescriptorFromPlugin(PLUGIN_ID, path);
        }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    */
+   public static void logInfo(String msg)
+   {
+      log(Status.INFO, msg, null);
+   }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    */
+   public static void logError(String msg, Throwable t)
+   {
+      log(Status.ERROR, msg, t);
+   }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    * @param t
+    */
+   public static void log(int status, String msg, Throwable t)
+   {
+      getDefault().getLog().log(new Status(status, PLUGIN_ID, Status.OK, msg, t));
+   }
 }
index 742b46c..5dab556 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * NetXMS - open source network management system
- * Copyright (C) 2003-2015 Victor Kirhenshtein
+ * Copyright (C) 2003-2016 Victor Kirhenshtein
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,7 +20,11 @@ package org.netxms.ui.eclipse.serverconfig.views;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -56,11 +60,13 @@ import org.eclipse.ui.forms.widgets.TableWrapLayout;
 import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
 import org.eclipse.ui.part.ViewPart;
+import org.netxms.base.NXCommon;
 import org.netxms.client.NXCSession;
 import org.netxms.client.Script;
 import org.netxms.client.datacollection.DciSummaryTableDescriptor;
 import org.netxms.client.events.EventProcessingPolicyRule;
 import org.netxms.client.events.EventTemplate;
+import org.netxms.client.market.Repository;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.Template;
 import org.netxms.client.objecttools.ObjectTool;
@@ -75,6 +81,7 @@ import org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog;
 import org.netxms.ui.eclipse.serverconfig.Activator;
 import org.netxms.ui.eclipse.serverconfig.Messages;
 import org.netxms.ui.eclipse.serverconfig.dialogs.ObjectToolSelectionDialog;
+import org.netxms.ui.eclipse.serverconfig.dialogs.RepositorySelectionDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.SelectSnmpTrapDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.SummaryTableSelectionDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.helpers.TrapListLabelProvider;
@@ -109,6 +116,7 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
    private TableViewer toolsViewer;
    private TableViewer summaryTableViewer;
        private Action actionSave;
+       private Action actionPublish;
        private Map<Long, EventTemplate> events = new HashMap<Long, EventTemplate>();
        private Map<Long, Template> templates = new HashMap<Long, Template>();
        private Map<Long, SnmpTrap> traps = new HashMap<Long, SnmpTrap>();
@@ -160,7 +168,7 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
                contributeToActionBars();
        }
        
-       /**
+   /**
     * Activate context
     */
    private void activateContext()
@@ -685,9 +693,9 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
          public void linkActivated(HyperlinkEvent e)
          {
             removeObjects(summaryTableViewer, summaryTables);
-                       }
-               });
-       }
+         }
+      });
+   }
 
        /**
         * Create actions
@@ -705,6 +713,16 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
                };
                actionSave.setActionDefinitionId("org.netxms.ui.eclipse.serverconfig.commands.save_exported_config"); //$NON-NLS-1$
       handlerService.activateHandler(actionSave.getActionDefinitionId(), new ActionHandler(actionSave));
+      
+      actionPublish = new Action("&Publish...", Activator.getImageDescriptor("icons/publish.gif")) {
+         @Override
+         public void run()
+         {
+            publish();
+         }
+      };
+      actionPublish.setActionDefinitionId("org.netxms.ui.eclipse.serverconfig.commands.publish_config"); //$NON-NLS-1$
+      handlerService.activateHandler(actionPublish.getActionDefinitionId(), new ActionHandler(actionPublish));
        }
        
        /**
@@ -726,6 +744,7 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
        private void fillLocalPullDown(IMenuManager manager)
        {
                manager.add(actionSave);
+               manager.add(actionPublish);
        }
 
        /**
@@ -737,6 +756,7 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
        private void fillLocalToolBar(IToolBarManager manager)
        {
                manager.add(actionSave);
+      manager.add(actionPublish);
        }
 
        /* (non-Javadoc)
@@ -759,32 +779,123 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
                        firePropertyChange(PROP_DIRTY);
                }
        }
-
+       
        /**
-        * Save settings
+        * Publish configuration
         */
-       private void save()
+       private void publish()
        {
-               final long[] eventList = new long[events.size()];
-               int i = 0;
-               for(EventTemplate t : events.values())
-                       eventList[i++] = t.getCode();
-               
-               final long[] templateList = new long[templates.size()];
-               i = 0;
-               for(Template t : templates.values())
-                       templateList[i++] = t.getObjectId();
-               
-               final long[] trapList = new long[traps.size()];
-               i = 0;
-               for(SnmpTrap t : traps.values())
-                       trapList[i++] = t.getId();
-               
-               final UUID[] ruleList = new UUID[rules.size()];
-               i = 0;
-               for(EventProcessingPolicyRule r : rules.values())
-                       ruleList[i++] = r.getGuid();
-               
+          new ConsoleJob("Get list of configured repositories", this, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            final List<Repository> repositories = session.getRepositories();
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  publishStage2(repositories);
+               }
+            });
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot get list of configured repositories";
+         }
+      }.start();
+       }
+       
+       /**
+        * Publish configuration - stage 2
+        * 
+        * @param repositories
+        */
+       private void publishStage2(List<Repository> repositories)
+       {
+          RepositorySelectionDialog dlg = new RepositorySelectionDialog(getSite().getShell(), repositories);
+          if (dlg.open() != Window.OK)
+             return;
+          
+          final Repository repository = dlg.getSelection();
+          doExport(new ExportCompletionHandler() {
+         @Override
+         public void exportCompleted(final String xml)
+         {
+            new ConsoleJob("Publish configuration", ExportFileBuilder.this, Activator.PLUGIN_ID, null) {
+               @Override
+               protected void runInternal(IProgressMonitor monitor) throws Exception
+               {
+                  URL url = new URL(repository.getUrl() + "/rest-api/push-export?accessToken=" + repository.getAuthToken());
+                  URLConnection conn = url.openConnection();
+                  if (!(conn instanceof HttpURLConnection))
+                  {
+                     throw new Exception("Unsupported URL type");
+                  }
+                  ((HttpURLConnection)conn).setRequestMethod("POST");
+                  ((HttpURLConnection)conn).setRequestProperty("User-Agent", "NetXMS Console/" + NXCommon.VERSION);
+                  ((HttpURLConnection)conn).setRequestProperty("Content-Type", "application/xml; charset=utf-8");
+                  ((HttpURLConnection)conn).setDoOutput(true);
+                  ((HttpURLConnection)conn).setAllowUserInteraction(false);
+                  ((HttpURLConnection)conn).setUseCaches(false);
+                  
+                  OutputStream out = conn.getOutputStream();
+                  try
+                  {
+                     out.write(xml.getBytes("UTF-8"));
+                     out.flush();
+                     
+                     int responseCode = ((HttpURLConnection)conn).getResponseCode();
+                     Activator.logInfo("Publish config: url=" + url.toString() + " response=" + responseCode);
+                     if (responseCode != 200)
+                     {
+                        throw new Exception(String.format("HTTP error %d", responseCode));
+                     }
+                  }
+                  finally
+                  {
+                     out.close();
+                  }
+               }
+               
+               @Override
+               protected String getErrorMessage()
+               {
+                  return "Cannot publish configuration to repository";
+               }
+            }.start();
+         }
+      });
+       }
+       
+       /**
+        * Do export operation and call completion handler when done
+        * 
+        * @param completionHandler
+        */
+       private void doExport(final ExportCompletionHandler completionHandler)
+       {
+      final long[] eventList = new long[events.size()];
+      int i = 0;
+      for(EventTemplate t : events.values())
+         eventList[i++] = t.getCode();
+      
+      final long[] templateList = new long[templates.size()];
+      i = 0;
+      for(Template t : templates.values())
+         templateList[i++] = t.getObjectId();
+      
+      final long[] trapList = new long[traps.size()];
+      i = 0;
+      for(SnmpTrap t : traps.values())
+         trapList[i++] = t.getId();
+      
+      final UUID[] ruleList = new UUID[rules.size()];
+      i = 0;
+      for(EventProcessingPolicyRule r : rules.values())
+         ruleList[i++] = r.getGuid();
+      
       final long[] scriptList = new long[scripts.size()];
       i = 0;
       for(Script s : scripts.values())
@@ -800,41 +911,73 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
       for(DciSummaryTableDescriptor t : summaryTables.values())
          summaryTableList[i++] = t.getId();
       
-               final String descriptionText = description.getText();
-               
-               new ConsoleJob(Messages.get().ExportFileBuilder_ExportJobName, this, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               final String xml = session.exportConfiguration(descriptionText, eventList, trapList, templateList, ruleList, scriptList, toolList, summaryTableList);
-                               final File file = File.createTempFile("export_config_" + ExportFileBuilder.this.hashCode(), "_" + System.currentTimeMillis()); 
-            OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); //$NON-NLS-1$
-            try
-            {
-               out.write(xml);
-            }
-            finally
-            {
-               out.close();
-            }
-            DownloadServiceHandler.addDownload(file.getName(), "export.xml", file, "application/xml");
-                               runInUIThread(new Runnable() {
+      final String descriptionText = description.getText();
+      
+      new ConsoleJob(Messages.get().ExportFileBuilder_ExportJobName, this, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            final String xml = session.exportConfiguration(descriptionText, eventList, trapList, templateList, ruleList, scriptList, toolList, summaryTableList);
+            runInUIThread(new Runnable() {
                @Override
                public void run()
                {
-                                               modified = false;
-                                               firePropertyChange(PROP_DIRTY);
-                                               DownloadServiceHandler.startDownload(file.getName());
+                  completionHandler.exportCompleted(xml);
                }
             });
-                       }
-                       
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().ExportFileBuilder_ExportJobError;
-                       }
-               }.start();
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return Messages.get().ExportFileBuilder_ExportJobError;
+         }
+      }.start();
+       }
+
+       /**
+        * Save settings
+        */
+       private void save()
+       {
+          doExport(new ExportCompletionHandler() {
+         @Override
+         public void exportCompleted(final String xml)
+         {
+               new ConsoleJob(Messages.get().ExportFileBuilder_ExportJobName, ExportFileBuilder.this, Activator.PLUGIN_ID, null) {
+                       @Override
+                       protected void runInternal(IProgressMonitor monitor) throws Exception
+                       {
+                               final File file = File.createTempFile("export_config_" + ExportFileBuilder.this.hashCode(), "_" + System.currentTimeMillis()); 
+                  OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); //$NON-NLS-1$
+                  try
+                  {
+                     out.write(xml);
+                  }
+                  finally
+                  {
+                     out.close();
+                  }
+                  DownloadServiceHandler.addDownload(file.getName(), "export.xml", file, "application/xml");
+                               runInUIThread(new Runnable() {
+                     @Override
+                     public void run()
+                     {
+                                               modified = false;
+                                               firePropertyChange(PROP_DIRTY);
+                                               DownloadServiceHandler.startDownload(file.getName());
+                     }
+                  });
+                       }
+                       
+                       @Override
+                       protected String getErrorMessage()
+                       {
+                               return Messages.get().ExportFileBuilder_ExportJobError;
+                       }
+               }.start();
+         }
+          });
        }
 
        /* (non-Javadoc)
@@ -920,12 +1063,12 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
        {
       IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
       if (selection.size() > 0)
-               {
+      {
          for(Object o : selection.toList())
             objects.remove(keyFromObject(o));
          viewer.setInput(objects.values().toArray());
-                       setModified();
-               }
+         setModified();
+      }
        }
        
        /**
@@ -1066,22 +1209,22 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
                        };
                }
        }
-       
-       /**
+   
+   /**
     * Add script to list
-        */
+    */
    private void addScripts()
-       {
+   {
       SelectScriptDialog dlg = new SelectScriptDialog(getSite().getShell());
       dlg.setMultiSelection(true);
       if (dlg.open() == Window.OK)
-               {
+      {
          for(Script s : dlg.getSelection())
             scripts.put(s.getId(), s);
          scriptViewer.setInput(scripts.values().toArray());
-                       setModified();
-               }
-       }
+         setModified();
+      }
+   }
    
    /**
     * Add oject tools to list
@@ -1112,4 +1255,17 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
          setModified();
       }
    }
+   
+   /**
+    * Export completion handler
+    */
+   private interface ExportCompletionHandler
+   {
+      /**
+       * Called when export is complete
+       * 
+       * @param xml resulting XML document
+       */
+      public void exportCompleted(final String xml);
+   }
 }