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();
}
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;
}
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;
}
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();
}
});
}
Aggregations