use of org.netxms.client.datacollection.TransformationTestResult in project netxms by netxms.
the class NXCSession method testTransformationScript.
/**
* Test DCI transformation script.
*
* @param nodeId ID of the node object to test script on
* @param script script source code
* @param inputValue input value for the script
* @return test execution results
* @throws IOException if socket I/O error occurs
* @throws NXCException if NetXMS server returns an error or operation was timed out
*/
public TransformationTestResult testTransformationScript(long nodeId, String script, String inputValue) throws IOException, NXCException {
NXCPMessage msg = newMessage(NXCPCodes.CMD_TEST_DCI_TRANSFORMATION);
msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
msg.setField(NXCPCodes.VID_SCRIPT, script);
msg.setField(NXCPCodes.VID_VALUE, inputValue);
sendMessage(msg);
final NXCPMessage response = waitForRCC(msg.getMessageId());
TransformationTestResult r = new TransformationTestResult();
r.success = response.getFieldAsBoolean(NXCPCodes.VID_EXECUTION_STATUS);
r.result = response.getFieldAsString(NXCPCodes.VID_EXECUTION_RESULT);
return r;
}
use of org.netxms.client.datacollection.TransformationTestResult in project netxms by netxms.
the class TestTransformationDlg method runScript.
/**
* Run script
*/
private void runScript() {
getButton(RUN).setEnabled(false);
final String input = inputValue.getText();
inputValue.getTextControl().setEditable(false);
status.setText(Messages.get().TestTransformationDlg_Running);
status.setImage(imageWaiting);
// $NON-NLS-1$
result.setText("");
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().TestTransformationDlg_JobTitle, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final TransformationTestResult r = session.testTransformationScript(nodeId, script, input);
runInUIThread(new Runnable() {
@Override
public void run() {
if ((getShell() == null) || getShell().isDisposed())
return;
if (r.success) {
status.setText(Messages.get().TestTransformationDlg_Success);
status.setImage(StatusDisplayInfo.getStatusImage(Severity.NORMAL));
} else {
status.setText(Messages.get().TestTransformationDlg_Failure);
status.setImage(StatusDisplayInfo.getStatusImage(Severity.CRITICAL));
}
result.setText(r.result);
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().TestTransformationDlg_JobError;
}
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.jobs.ConsoleJob#jobFinalize()
*/
@Override
protected void jobFinalize() {
runInUIThread(new Runnable() {
@Override
public void run() {
if ((getShell() == null) || getShell().isDisposed())
return;
getButton(RUN).setEnabled(true);
inputValue.getTextControl().setEditable(true);
inputValue.getTextControl().setFocus();
}
});
}
}.start();
}
Aggregations