Search in sources :

Example 1 with Repository

use of org.netxms.client.market.Repository in project netxms by netxms.

the class RepositoryManager method addRepository.

/**
 * Add repository
 */
private void addRepository() {
    RepositoryPropertiesDlg dlg = new RepositoryPropertiesDlg(getSite().getShell(), null);
    if (dlg.open() != Window.OK)
        return;
    final Repository repository = new Repository(dlg.getUrl(), dlg.getToken(), dlg.getDescription());
    new ConsoleJob("Add repository", this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.addRepository(repository);
            runInUIThread(new Runnable() {

                @SuppressWarnings("unchecked")
                @Override
                public void run() {
                    ArrayList<RepositoryRuntimeInfo> repositories = (ArrayList<RepositoryRuntimeInfo>) viewer.getInput();
                    repositories.add(new RepositoryRuntimeInfo(repository));
                    viewer.refresh();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot add repository";
        }
    }.start();
}
Also used : RepositoryPropertiesDlg(org.netxms.ui.eclipse.market.dialogs.RepositoryPropertiesDlg) Repository(org.netxms.client.market.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) RepositoryRuntimeInfo(org.netxms.ui.eclipse.market.objects.RepositoryRuntimeInfo)

Example 2 with Repository

use of org.netxms.client.market.Repository in project netxms by netxms.

the class RepositorySelectionDialog method createDialogArea.

/* (non-Javadoc)
    * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    dialogArea.setLayout(layout);
    Label label = new Label(dialogArea, SWT.LEFT);
    label.setText("Available repositories");
    viewer = new TableViewer(dialogArea, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Repository) element).getDescription();
        }
    });
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ((Repository) e1).getDescription().compareToIgnoreCase(((Repository) e2).getDescription());
        }
    });
    viewer.setInput(repositories);
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            okPressed();
        }
    });
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.widthHint = 500;
    gd.heightHint = 300;
    viewer.getControl().setLayoutData(gd);
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Repository(org.netxms.client.market.Repository) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 3 with Repository

use of org.netxms.client.market.Repository in project netxms by netxms.

the class NXCSession method getRepositories.

/**
 * Get list of configured repositories
 *
 * @return list of configured repositories
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<Repository> getRepositories() throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_REPOSITORIES);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_ELEMENTS);
    List<Repository> list = new ArrayList<Repository>(count);
    long fieldId = NXCPCodes.VID_ELEMENT_LIST_BASE;
    for (int i = 0; i < count; i++) {
        list.add(new Repository(response, fieldId));
        fieldId += 10;
    }
    return list;
}
Also used : Repository(org.netxms.client.market.Repository) NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 4 with Repository

use of org.netxms.client.market.Repository in project netxms by netxms.

the class ExportFileBuilder method publishStage2.

/**
 * 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();
        }
    });
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) RepositorySelectionDialog(org.netxms.ui.eclipse.serverconfig.dialogs.RepositorySelectionDialog) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) Repository(org.netxms.client.market.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) HttpURLConnection(java.net.HttpURLConnection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

Repository (org.netxms.client.market.Repository)4 ArrayList (java.util.ArrayList)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1