use of org.netxms.client.NXCException in project netxms by netxms.
the class HistoricalData method get.
/* (non-Javadoc)
* @see org.netxms.websvc.handlers.AbstractHandler#get(java.lang.String)
*/
@Override
protected Object get(String id, Map<String, String> query) throws Exception {
NXCSession session = getSession();
AbstractObject obj = getObject();
long dciId = 0;
try {
dciId = Long.parseLong(id);
} catch (NumberFormatException e) {
dciId = session.dciNameToId(obj.getObjectId(), id);
}
if (obj == null || dciId == 0 || !(obj instanceof DataCollectionTarget))
throw new NXCException(RCC.INVALID_OBJECT_ID);
String timeFrom = query.get("from");
String timeTo = query.get("to");
String timeInteval = query.get("timeInterval");
String itemCount = query.get("itemCount");
DciData data = null;
if (timeFrom != null || timeTo != null) {
data = session.getCollectedData(obj.getObjectId(), dciId, new Date(parseLong(timeFrom, 0) * 1000), new Date(parseLong(timeTo, System.currentTimeMillis() / 1000) * 1000), parseInt(itemCount, 0), false);
} else if (timeInteval != null) {
Date now = new Date();
long from = now.getTime() - parseLong(timeInteval, 0) * 1000;
data = session.getCollectedData(obj.getObjectId(), dciId, new Date(from), new Date(), parseInt(itemCount, 0), false);
} else if (itemCount != null) {
data = session.getCollectedData(obj.getObjectId(), dciId, null, null, parseInt(itemCount, 0), false);
} else {
Date now = new Date();
// one hour
long from = now.getTime() - 3600000;
data = session.getCollectedData(obj.getObjectId(), dciId, new Date(from), now, parseInt(itemCount, 0), false);
}
return new ResponseContainer("values", data);
}
use of org.netxms.client.NXCException in project netxms by netxms.
the class AbstractObjectHandler method getObject.
/**
* Get object from URL entity ID part
*
* @return object
* @throws Exception if object cannot be found or request is invalid
*/
protected AbstractObject getObject() throws Exception {
String entityId = (String) getRequest().getAttributes().get("object-id");
NXCSession session = getSession();
if (!session.isObjectsSynchronized())
session.syncObjects();
AbstractObject object;
try {
long objectId = Long.parseLong(entityId);
object = session.findObjectById(objectId);
} catch (NumberFormatException e) {
UUID objectGuid = UUID.fromString(entityId);
object = session.findObjectByGUID(objectGuid);
}
if (object == null)
throw new NXCException(RCC.INVALID_OBJECT_ID);
return object;
}
use of org.netxms.client.NXCException in project netxms by netxms.
the class Alarms method getCollection.
/* (non-Javadoc)
* @see org.netxms.websvc.handlers.AbstractHandler#getCollection(org.json.JSONObject)
*/
@Override
protected Object getCollection(Map<String, String> query) throws Exception {
NXCSession session = getSession();
Collection<Alarm> alarms = session.getAlarms().values();
String queryGuid = query.get("objectGuid");
if (queryGuid != null) {
UUID objectGuid = UUID.fromString(queryGuid);
if (!session.isObjectsSynchronized())
session.syncObjects();
AbstractObject object = session.findObjectByGUID(objectGuid);
if (object == null)
throw new NXCException(RCC.INVALID_OBJECT_ID);
Iterator<Alarm> iterator = alarms.iterator();
while (iterator.hasNext()) {
Alarm alarm = iterator.next();
if (alarm.getSourceObjectId() != object.getObjectId()) {
iterator.remove();
}
}
}
return new ResponseContainer("alarms", alarms);
}
use of org.netxms.client.NXCException in project netxms by netxms.
the class DataCollectionEditor method convertToTemplate.
/**
* Convert selected item(s) to template items
*/
private void convertToTemplate() {
final ObjectSelectionDialog dlg = new ObjectSelectionDialog(getSite().getShell(), null, ObjectSelectionDialog.createTemplateSelectionFilter());
dlg.showFilterToolTip(false);
if (dlg.open() != Window.OK)
return;
AbstractObject[] objects = dlg.getSelectedObjects(Template.class);
if (objects.length == 0)
return;
final Template template = (Template) objects[0];
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Iterator<?> it = selection.iterator();
final long[] dciList = new long[selection.size()];
for (int i = 0; (i < dciList.length) && it.hasNext(); i++) dciList[i] = ((DataCollectionObject) it.next()).getId();
new ConsoleJob(Messages.get().DataCollectionEditor_ConvertJob_TitlePrefix + object.getObjectName() + Messages.get().DataCollectionEditor_ConvertJob_TitleSuffix, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
monitor.beginTask(Messages.get(getDisplay()).DataCollectionEditor_ConvertJob_TaskName, 4);
boolean needApply = true;
for (long id : template.getChildIdList()) {
if (id == dciConfig.getNodeId()) {
needApply = false;
break;
}
}
monitor.worked(1);
dciConfig.copyObjects(template.getObjectId(), dciList);
for (long id : dciList) dciConfig.deleteObject(id);
dciConfig.close();
monitor.worked(1);
if (needApply) {
boolean success = false;
int retries = 5;
do {
try {
session.applyTemplate(template.getObjectId(), dciConfig.getNodeId());
success = true;
} catch (NXCException e) {
if (e.getErrorCode() != RCC.COMPONENT_LOCKED)
throw e;
Thread.sleep(200);
}
retries--;
} while (!success && (retries > 0));
}
monitor.worked(1);
boolean success = false;
int retries = 5;
do {
try {
Thread.sleep(500);
dciConfig.open();
success = true;
} catch (NXCException e) {
if (e.getErrorCode() != RCC.COMPONENT_LOCKED)
throw e;
}
retries--;
} while (!success && (retries > 0));
runInUIThread(new Runnable() {
@Override
public void run() {
viewer.setInput(dciConfig.getItems());
}
});
monitor.done();
}
@Override
protected String getErrorMessage() {
return Messages.get().DataCollectionEditor_ConvertJob_ErrorPrefix + object.getObjectName() + Messages.get().DataCollectionEditor_ConvertJob_ErrorSuffix;
}
}.start();
}
use of org.netxms.client.NXCException in project netxms by netxms.
the class HistoricalGraphView method saveGraph.
/**
* Save this graph as predefined
*/
private void saveGraph(String graphName, String errorMessage, final boolean canBeOverwritten, final boolean asTemplate) {
if (asTemplate && useMoreThanOneShoucrNode) {
String templateError = "More than one node is used for template creation.\nThis may cause undefined behaviour.";
errorMessage = errorMessage == null ? templateError : errorMessage + "\n\n" + templateError;
}
SaveGraphDlg dlg = new SaveGraphDlg(getSite().getShell(), graphName, errorMessage, canBeOverwritten);
int result = dlg.open();
if (result == Window.CANCEL)
return;
final GraphSettings gs = new GraphSettings(0, session.getUserId(), 0, new ArrayList<AccessListElement>(0));
gs.setName(dlg.getName());
gs.setConfig(settings);
if (asTemplate) {
gs.setFlags(GraphSettings.GRAPH_FLAG_TEMPLATE);
}
if (result == SaveGraphDlg.OVERRIDE) {
new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.saveGraph(gs, canBeOverwritten);
}
@Override
protected String getErrorMessage() {
return Messages.get().HistoricalGraphView_SaveSettingsError;
}
}.start();
} else {
new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
try {
session.saveGraph(gs, canBeOverwritten);
} catch (NXCException e) {
if (e.getErrorCode() == RCC.OBJECT_ALREADY_EXISTS) {
runInUIThread(new Runnable() {
@Override
public void run() {
saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExist, true, asTemplate);
}
});
} else {
if (e.getErrorCode() == RCC.ACCESS_DENIED) {
runInUIThread(new Runnable() {
@Override
public void run() {
saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExistNoOverwrite, false, asTemplate);
}
});
} else {
throw e;
}
}
}
}
@Override
protected String getErrorMessage() {
return Messages.get().HistoricalGraphView_SaveError;
}
}.start();
}
updateChart();
}
Aggregations