use of jmri.Reporter in project JMRI by JMRI.
the class JsonReporterHttpService method doGet.
@Override
public JsonNode doGet(String type, String name, Locale locale) throws JsonException {
ObjectNode root = mapper.createObjectNode();
root.put(TYPE, REPORTER);
ObjectNode data = root.putObject(DATA);
Reporter reporter = InstanceManager.getDefault(ReporterManager.class).getReporter(name);
if (reporter == null) {
throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", REPORTER, name));
}
data.put(NAME, reporter.getSystemName());
data.put(USERNAME, reporter.getUserName());
data.put(STATE, reporter.getState());
data.put(COMMENT, reporter.getComment());
if (reporter.getCurrentReport() != null) {
data.put(REPORT, reporter.getCurrentReport().toString());
} else {
data.putNull(REPORT);
}
if (reporter.getLastReport() != null) {
data.put(LAST_REPORT, reporter.getLastReport().toString());
} else {
data.putNull(LAST_REPORT);
}
return root;
}
use of jmri.Reporter in project JMRI by JMRI.
the class ReporterTest method testReportStringObject.
public void testReportStringObject() {
// Create a new reporter
Reporter r = createNewReporter("SYS", "usr");
// Report a String
r.setReport("Something To Report");
// Check that both CurrentReport and LastReport are String objects
Assert.assertTrue("CurrentReport Object is 'String'", r.getCurrentReport() instanceof String);
Assert.assertTrue("LastReport Object is 'String'", r.getLastReport() instanceof String);
// Check the value of both CurrentReport and LastReport
Assert.assertEquals("CurrentReport String is 'Something To Report'", "Something To Report", r.getCurrentReport());
Assert.assertEquals("LastReport String is 'Something To Report'", "Something To Report", r.getLastReport());
// Nothing to report now
r.setReport(null);
// Check that CurrentReport returns a null value, but LastReport returns the reported String
Assert.assertEquals("After null report, CurrentReport String is null", null, r.getCurrentReport());
Assert.assertEquals("After null report, LastReport String is 'Something To Report'", "Something To Report", r.getLastReport());
}
use of jmri.Reporter in project JMRI by JMRI.
the class VSDecoderManager method registerReporterListener.
protected void registerReporterListener(String sysName) {
Reporter r = jmri.InstanceManager.getDefault(jmri.ReporterManager.class).getReporter(sysName);
if (r == null) {
return;
}
jmri.NamedBeanHandle<Reporter> h = nbhm.getNamedBeanHandle(sysName, r);
if (h == null) {
return;
}
// Make sure we aren't already registered.
java.beans.PropertyChangeListener[] ll = r.getPropertyChangeListenersByReference(h.getName());
if (ll.length == 0) {
r.addPropertyChangeListener(this, h.getName(), vsd_property_change_name);
}
}
use of jmri.Reporter in project JMRI by JMRI.
the class LnReporterManager method createNewReporter.
@Override
public Reporter createNewReporter(String systemName, String userName) {
Reporter t;
int addr = Integer.valueOf(systemName.substring(prefix.length() + 1)).intValue();
t = new LnReporter(addr, tc, prefix);
t.setUserName(userName);
t.addPropertyChangeListener(this);
return t;
}
use of jmri.Reporter in project JMRI by JMRI.
the class AbstractReporterManager method newReporter.
@Override
public Reporter newReporter(String systemName, String userName) {
if (log.isDebugEnabled()) {
log.debug("new Reporter:" + ((systemName == null) ? "null" : systemName) + ";" + ((userName == null) ? "null" : userName));
}
// return existing if there is one
Reporter r;
if ((userName != null) && ((r = getByUserName(userName)) != null)) {
if (getBySystemName(systemName) != r) {
log.error("inconsistent user (" + userName + ") and system name (" + systemName + ") results; userName related to (" + r.getSystemName() + ")");
}
return r;
}
if ((r = getBySystemName(systemName)) != null) {
if ((r.getUserName() == null) && (userName != null)) {
r.setUserName(userName);
} else if (userName != null) {
log.warn("Found reporter via system name (" + systemName + ") with non-null user name (" + userName + ")");
}
return r;
}
// doesn't exist, make a new one
r = createNewReporter(systemName, userName);
// save in the maps
register(r);
return r;
}
Aggregations