Search in sources :

Example 46 with Reporter

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;
}
Also used : JsonException(jmri.server.json.JsonException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ReporterManager(jmri.ReporterManager) Reporter(jmri.Reporter)

Example 47 with Reporter

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());
}
Also used : Reporter(jmri.Reporter)

Example 48 with Reporter

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);
    }
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) PhysicalLocationReporter(jmri.PhysicalLocationReporter) Reporter(jmri.Reporter)

Example 49 with Reporter

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;
}
Also used : Reporter(jmri.Reporter)

Example 50 with Reporter

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;
}
Also used : Reporter(jmri.Reporter)

Aggregations

Reporter (jmri.Reporter)55 Test (org.junit.Test)18 ReporterManager (jmri.ReporterManager)10 Block (jmri.Block)6 Element (org.jdom2.Element)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 IOException (java.io.IOException)4 BlockManager (jmri.BlockManager)4 JsonException (jmri.server.json.JsonException)4 Date (java.util.Date)3 JmriException (jmri.JmriException)3 Sensor (jmri.Sensor)3 OBlock (jmri.jmrit.logix.OBlock)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ParseException (java.text.ParseException)2 PhysicalLocationReporter (jmri.PhysicalLocationReporter)2 Location (jmri.jmrit.operations.locations.Location)2 JsonMockConnection (jmri.server.json.JsonMockConnection)2 GuiLafPreferencesManager (apps.gui.GuiLafPreferencesManager)1