use of org.netxms.client.NXCSession in project netxms by netxms.
the class ResponsibleUsers method applyChanges.
/**
* Apply changes
*
* @param isApply true if update operation caused by "Apply" button
*/
protected void applyChanges(final boolean isApply) {
if (isApply)
setValid(false);
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
List<Long> userIds = new ArrayList<Long>(userList.size());
for (AbstractUserObject o : userList) userIds.add(o.getId());
md.setResponsibleUsers(userIds);
new ConsoleJob(String.format(Messages.get().AccessControl_JobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.modifyObject(md);
}
@Override
protected void jobFinalize() {
if (isApply) {
runInUIThread(new Runnable() {
@Override
public void run() {
ResponsibleUsers.this.setValid(true);
}
});
}
}
@Override
protected String getErrorMessage() {
return Messages.get().AccessControl_JobError;
}
}.start();
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class ObjectToolsDynamicMenu method buildNodeSet.
/**
* Build node set from selection
*
* @param selection
* @return
*/
private Set<ObjectContext> buildNodeSet(IStructuredSelection selection) {
final Set<ObjectContext> nodes = new HashSet<ObjectContext>();
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
for (Object o : selection.toList()) {
if (o instanceof AbstractNode) {
nodes.add(new ObjectContext((AbstractNode) o, null));
} else if ((o instanceof Container) || (o instanceof ServiceRoot) || (o instanceof Subnet) || (o instanceof Cluster)) {
for (AbstractObject n : ((AbstractObject) o).getAllChilds(AbstractObject.OBJECT_NODE)) nodes.add(new ObjectContext((AbstractNode) n, null));
} else if (o instanceof Alarm) {
AbstractNode n = (AbstractNode) session.findObjectById(((Alarm) o).getSourceObjectId(), AbstractNode.class);
if (n != null)
nodes.add(new ObjectContext(n, (Alarm) o));
} else if (o instanceof ObjectWrapper) {
AbstractObject n = ((ObjectWrapper) o).getObject();
if ((n != null) && (n instanceof AbstractNode))
nodes.add(new ObjectContext((AbstractNode) n, null));
}
}
return nodes;
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class WakeupToolHandler method execute.
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler#execute(org.netxms.client.objects.AbstractNode, org.netxms.client.objecttools.ObjectTool)
*/
@Override
public void execute(final AbstractNode node, ObjectTool tool) {
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().WakeupToolHandler_JobName, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.wakeupNode(node.getObjectId());
}
@Override
protected String getErrorMessage() {
return Messages.get().WakeupToolHandler_JobError;
}
}.start();
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class ObjectToolExecutor method executeFileDownload.
/**
* @param node
* @param tool
* @param inputValues
* @param inputValues
*/
private static void executeFileDownload(final ObjectContext node, final ObjectTool tool, final Map<String, String> inputValues) {
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
// $NON-NLS-1$
String[] parameters = tool.getData().split("\u007F");
final String fileName = parameters[0];
final int maxFileSize = Integer.parseInt(parameters[1]);
// $NON-NLS-1$
final boolean follow = parameters[2].equals("true") ? true : false;
ConsoleJobCallingServerJob job = new ConsoleJobCallingServerJob(Messages.get().ObjectToolsDynamicMenu_DownloadFromAgent, null, Activator.PLUGIN_ID, null) {
@Override
protected String getErrorMessage() {
return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, fileName, node.object.getObjectName());
}
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
final AgentFileData file = session.downloadFileFromAgent(node.object.getObjectId(), fileName, maxFileSize, follow, inputValues, node.getAlarmId(), new ProgressListener() {
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask("Download file " + fileName, (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) workDone);
}
}, this);
runInUIThread(new Runnable() {
@Override
public void run() {
try {
// $NON-NLS-1$ //$NON-NLS-2$
String secondaryId = Long.toString(node.object.getObjectId()) + "&" + URLEncoder.encode(fileName, "UTF-8");
AgentFileViewer.createView(secondaryId, node.object.getObjectId(), file, follow);
} catch (Exception e) {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
}
}
});
}
};
job.start();
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class ObjectToolExecutor method execute.
/**
* Execute object tool on node set
*
* @param tool Object tool
*/
public static void execute(final Set<ObjectContext> nodes, final ObjectTool tool) {
final Map<String, String> inputValues;
final InputField[] fields = tool.getInputFields();
if (fields.length > 0) {
Arrays.sort(fields, new Comparator<InputField>() {
@Override
public int compare(InputField f1, InputField f2) {
return f1.getSequence() - f2.getSequence();
}
});
inputValues = readInputFields(fields);
if (inputValues == null)
// cancelled
return;
} else {
inputValues = new HashMap<String, String>(0);
}
final NXCSession session = ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().ObjectToolExecutor_JobName, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
List<String> expandedText = null;
if ((tool.getFlags() & ObjectTool.ASK_CONFIRMATION) != 0) {
String message = tool.getConfirmationText();
if (nodes.size() == 1) {
// Expand message and action for 1 node, otherwise expansion occurs after confirmation
List<String> textToExpand = new ArrayList<String>();
textToExpand.add(tool.getConfirmationText());
if (tool.getToolType() == ObjectTool.TYPE_URL || tool.getToolType() == ObjectTool.TYPE_LOCAL_COMMAND) {
textToExpand.add(tool.getData());
}
ObjectContext node = nodes.iterator().next();
expandedText = session.substitureMacross(node, textToExpand, inputValues);
message = expandedText.remove(0);
} else {
ObjectContext node = nodes.iterator().next();
message = node.substituteMacrosForMultiNodes(message, inputValues);
}
ConfirmationRunnable runnable = new ConfirmationRunnable(message);
getDisplay().syncExec(runnable);
if (!runnable.isConfirmed())
return;
if (tool.getToolType() == ObjectTool.TYPE_URL || tool.getToolType() == ObjectTool.TYPE_LOCAL_COMMAND) {
expandedText = session.substitureMacross(nodes.toArray(new ObjectContext[nodes.size()]), tool.getData(), inputValues);
}
} else {
if (tool.getToolType() == ObjectTool.TYPE_URL || tool.getToolType() == ObjectTool.TYPE_LOCAL_COMMAND) {
expandedText = session.substitureMacross(nodes.toArray(new ObjectContext[nodes.size()]), tool.getData(), inputValues);
}
}
// Check if password validation needed
boolean validationNeeded = false;
for (int i = 0; i < fields.length; i++) if (fields[i].getOptions().validatePassword) {
validationNeeded = true;
break;
}
if (validationNeeded) {
for (int i = 0; i < fields.length; i++) {
if ((fields[i].getType() == InputFieldType.PASSWORD) && (fields[i].getOptions().validatePassword)) {
boolean valid = session.validateUserPassword(inputValues.get(fields[i].getName()));
if (!valid) {
final String fieldName = fields[i].getDisplayName();
getDisplay().syncExec(new Runnable() {
@Override
public void run() {
MessageDialogHelper.openError(null, Messages.get().ObjectToolExecutor_ErrorTitle, String.format(Messages.get().ObjectToolExecutor_ErrorText, fieldName));
}
});
return;
}
}
}
}
int i = 0;
for (final ObjectContext n : nodes) {
if (tool.getToolType() == ObjectTool.TYPE_URL || tool.getToolType() == ObjectTool.TYPE_LOCAL_COMMAND) {
final String tmp = expandedText.get(i++);
getDisplay().syncExec(new Runnable() {
@Override
public void run() {
executeOnNode(n, tool, inputValues, tmp);
}
});
} else {
getDisplay().syncExec(new Runnable() {
@Override
public void run() {
executeOnNode(n, tool, inputValues, null);
}
});
}
}
}
@Override
protected String getErrorMessage() {
return Messages.get().ObjectToolExecutor_PasswordValidationFailed;
}
class ConfirmationRunnable implements Runnable {
private boolean confirmed;
private String message;
public ConfirmationRunnable(String message) {
this.message = message;
}
@Override
public void run() {
confirmed = MessageDialogHelper.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().ObjectToolsDynamicMenu_ConfirmExec, message);
}
boolean isConfirmed() {
return confirmed;
}
}
}.start();
}
Aggregations