Search in sources :

Example 1 with ReporterManager

use of jmri.ReporterManager in project JMRI by JMRI.

the class AbstractReporterManagerConfigXML method loadReporters.

/**
     * Utility method to load the individual Reporter objects. If there's no
     * additional info needed for a specific Reporter type, invoke this with the
     * parent of the set of Reporter elements.
     *
     * @param reporters Element containing the Reporter elements to load.
     * @return true if successful
     */
@SuppressWarnings("unchecked")
public boolean loadReporters(Element reporters) {
    boolean result = true;
    List<Element> reporterList = reporters.getChildren("reporter");
    if (log.isDebugEnabled()) {
        log.debug("Found " + reporterList.size() + " reporters");
    }
    ReporterManager tm = InstanceManager.getDefault(jmri.ReporterManager.class);
    for (int i = 0; i < reporterList.size(); i++) {
        String sysName = getSystemName(reporterList.get(i));
        if (sysName == null) {
            log.warn("unexpected null in systemName " + reporterList.get(i) + " " + reporterList.get(i).getAttributes());
            result = false;
            break;
        }
        String userName = getUserName(reporterList.get(i));
        if (log.isDebugEnabled()) {
            log.debug("create Reporter: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        Reporter r = tm.newReporter(sysName, userName);
        loadCommon(r, reporterList.get(i));
    }
    return result;
}
Also used : ReporterManager(jmri.ReporterManager) Element(org.jdom2.Element) Reporter(jmri.Reporter)

Example 2 with ReporterManager

use of jmri.ReporterManager in project JMRI by JMRI.

the class JsonReporterHttpServiceTest method testDoPut.

@Test
public void testDoPut() {
    ObjectMapper mapper = new ObjectMapper();
    JsonReporterHttpService service = new JsonReporterHttpService(mapper);
    ReporterManager manager = InstanceManager.getDefault(ReporterManager.class);
    JsonNode message;
    try {
        // add a reporter
        Assert.assertNull(manager.getReporter("IR1"));
        message = mapper.createObjectNode().put(JSON.NAME, "IR1").put(JsonReporter.REPORT, "close");
        service.doPut(REPORTER, "IR1", message, Locale.ENGLISH);
        Assert.assertNotNull(manager.getReporter("IR1"));
    } catch (JsonException ex) {
        Assert.fail(ex.getMessage());
    }
}
Also used : JsonException(jmri.server.json.JsonException) ReporterManager(jmri.ReporterManager) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with ReporterManager

use of jmri.ReporterManager in project JMRI by JMRI.

the class JsonReporterHttpServiceTest method testDoGet.

@Test
public void testDoGet() throws JmriException {
    JsonReporterHttpService service = new JsonReporterHttpService(new ObjectMapper());
    ReporterManager manager = InstanceManager.getDefault(ReporterManager.class);
    // no value
    Reporter reporter1 = manager.provideReporter("IR1");
    JsonNode result;
    try {
        result = service.doGet(REPORTER, "IR1", Locale.ENGLISH);
        Assert.assertNotNull(result);
        Assert.assertEquals(REPORTER, result.path(JSON.TYPE).asText());
        Assert.assertEquals("IR1", result.path(JSON.DATA).path(JSON.NAME).asText());
        // JSON node has the text "null" if reporter is null
        Assert.assertEquals("null", result.path(JSON.DATA).path(JsonReporter.REPORT).asText());
        reporter1.setReport("throw");
        result = service.doGet(REPORTER, "IR1", Locale.ENGLISH);
        Assert.assertNotNull(result);
        Assert.assertEquals("throw", result.path(JSON.DATA).path(JsonReporter.REPORT).asText());
        reporter1.setReport("close");
        result = service.doGet(REPORTER, "IR1", Locale.ENGLISH);
        Assert.assertNotNull(result);
        Assert.assertEquals("close", result.path(JSON.DATA).path(JsonReporter.REPORT).asText());
    } catch (JsonException ex) {
        Assert.fail(ex.getMessage());
    }
}
Also used : JsonException(jmri.server.json.JsonException) ReporterManager(jmri.ReporterManager) Reporter(jmri.Reporter) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with ReporterManager

use of jmri.ReporterManager in project JMRI by JMRI.

the class JsonReporterHttpServiceTest method testDoGetList.

@Test
public void testDoGetList() {
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonReporterHttpService service = new JsonReporterHttpService(mapper);
        ReporterManager manager = InstanceManager.getDefault(ReporterManager.class);
        JsonNode result;
        result = service.doGetList(REPORTER, Locale.ENGLISH);
        Assert.assertNotNull(result);
        Assert.assertEquals(0, result.size());
        manager.provideReporter("IR1");
        manager.provideReporter("IR2");
        result = service.doGetList(REPORTER, Locale.ENGLISH);
        Assert.assertNotNull(result);
        Assert.assertEquals(2, result.size());
    } catch (JsonException ex) {
        Assert.fail(ex.getMessage());
    }
}
Also used : JsonException(jmri.server.json.JsonException) ReporterManager(jmri.ReporterManager) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with ReporterManager

use of jmri.ReporterManager in project JMRI by JMRI.

the class ManageLocationsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (f == null || !f.isVisible()) {
        // Handle the Listener
        listenerLoc = VSDecoderManager.instance().getVSDecoderPreferences().getListenerPosition();
        // Handle Reporters
        ReporterManager rmgr = jmri.InstanceManager.getDefault(jmri.ReporterManager.class);
        String[] reporterNameArray = rmgr.getSystemNameArray();
        Object[][] reporterTable = new Object[reporterNameArray.length][6];
        reporterMap = new HashMap<String, PhysicalLocation>();
        int i = 0;
        for (String s : reporterNameArray) {
            Reporter r = rmgr.getByDisplayName(s);
            if (r instanceof PhysicalLocationReporter) {
                reporterMap.put(s, ((PhysicalLocationReporter) r).getPhysicalLocation());
                PhysicalLocation p = ((PhysicalLocationReporter) r).getPhysicalLocation();
                reporterTable[i][0] = s;
                reporterTable[i][1] = true;
                reporterTable[i][2] = p.getX();
                reporterTable[i][3] = p.getY();
                reporterTable[i][4] = p.getZ();
                reporterTable[i][5] = p.isTunnel();
            } else {
                reporterTable[i][0] = s;
                reporterTable[i][1] = false;
                reporterTable[i][2] = Float.valueOf(0.0f);
                reporterTable[i][3] = Float.valueOf(0.0f);
                reporterTable[i][4] = Float.valueOf(0.0f);
                reporterTable[i][5] = false;
            }
            i++;
        }
        // Handle Blocks
        BlockManager bmgr = jmri.InstanceManager.getDefault(jmri.BlockManager.class);
        String[] blockNameArray = bmgr.getSystemNameArray();
        Object[][] blockTable = new Object[blockNameArray.length][6];
        blockMap = new HashMap<String, PhysicalLocation>();
        i = 0;
        for (String s : blockNameArray) {
            Block b = bmgr.getByDisplayName(s);
            // NOTE: Unlike Reporters, all Blocks are (now) PhysicalLocationReporters, so no need to do a check here.
            // We'll keep the explicit cast for now, but it's not actually necessary.
            blockMap.put(s, ((PhysicalLocationReporter) b).getPhysicalLocation());
            PhysicalLocation p = ((PhysicalLocationReporter) b).getPhysicalLocation();
            blockTable[i][0] = s;
            blockTable[i][1] = true;
            blockTable[i][2] = p.getX();
            blockTable[i][3] = p.getY();
            blockTable[i][4] = p.getZ();
            blockTable[i][5] = p.isTunnel();
            i++;
        }
        // Handle Ops Locations
        LocationManager lmgr = LocationManager.instance();
        List<Location> locations = lmgr.getLocationsByIdList();
        opsMap = new HashMap<String, PhysicalLocation>();
        log.debug("TableSize : " + locations.size());
        Object[][] opsTable = new Object[locations.size()][6];
        i = 0;
        for (Location l : locations) {
            if (log.isDebugEnabled()) {
                log.debug("i = " + i + "MLA " + l.getId() + " Name: " + l.getName() + " table " + java.util.Arrays.toString(opsTable[i]));
            }
            PhysicalLocation p = l.getPhysicalLocation();
            Boolean use = false;
            if (p == PhysicalLocation.Origin) {
                use = false;
            } else {
                use = true;
            }
            opsTable[i][0] = l.getName();
            opsTable[i][1] = use;
            opsTable[i][2] = p.getX();
            opsTable[i][3] = p.getY();
            opsTable[i][4] = p.getZ();
            opsTable[i][5] = p.isTunnel();
            opsMap.put(l.getName(), l.getPhysicalLocation());
            i++;
        }
        f = new ManageLocationsFrame(listenerLoc, reporterTable, opsTable, blockTable);
    }
    f.setExtendedState(Frame.NORMAL);
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) ReporterManager(jmri.ReporterManager) PhysicalLocationReporter(jmri.PhysicalLocationReporter) Reporter(jmri.Reporter) BlockManager(jmri.BlockManager) Block(jmri.Block) PhysicalLocationReporter(jmri.PhysicalLocationReporter) PhysicalLocation(jmri.util.PhysicalLocation) PhysicalLocation(jmri.util.PhysicalLocation) Location(jmri.jmrit.operations.locations.Location)

Aggregations

ReporterManager (jmri.ReporterManager)12 Reporter (jmri.Reporter)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 JsonException (jmri.server.json.JsonException)6 Test (org.junit.Test)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IOException (java.io.IOException)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Block (jmri.Block)2 BlockManager (jmri.BlockManager)2 DccLocoAddress (jmri.DccLocoAddress)2 IdTag (jmri.IdTag)2 JmriException (jmri.JmriException)2 Location (jmri.jmrit.operations.locations.Location)2 LocationManager (jmri.jmrit.operations.locations.LocationManager)2 JsonMockConnection (jmri.server.json.JsonMockConnection)2 PhysicalLocation (jmri.util.PhysicalLocation)2 Element (org.jdom2.Element)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1