Search in sources :

Example 71 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.

the class JsonUtil method getEnginesForTrain.

private ArrayNode getEnginesForTrain(Locale locale, Train train) {
    ArrayNode elan = mapper.createArrayNode();
    EngineManager engineManager = EngineManager.instance();
    List<Engine> engineList = engineManager.getByTrainBlockingList(train);
    engineList.forEach((engine) -> {
        //add each engine's data to the engineList array
        elan.add(getEngine(locale, engine.getId()).get(DATA));
    });
    //return array of engine data
    return elan;
}
Also used : EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Engine(jmri.jmrit.operations.rollingstock.engines.Engine)

Example 72 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.

the class JsonUtil method getRouteLocationsForTrain.

private ArrayNode getRouteLocationsForTrain(Locale locale, Train train) throws JsonException {
    ArrayNode rlan = mapper.createArrayNode();
    List<RouteLocation> routeList = train.getRoute().getLocationsBySequenceList();
    for (RouteLocation route : routeList) {
        ObjectNode rln = mapper.createObjectNode();
        RouteLocation rl = route;
        rln.put(ID, rl.getId());
        rln.put(NAME, rl.getName());
        rln.put(DIRECTION, rl.getTrainDirectionString());
        rln.put(COMMENT, rl.getComment());
        rln.put(SEQUENCE, rl.getSequenceId());
        rln.put(EXPECTED_ARRIVAL, train.getExpectedArrivalTime(rl));
        rln.put(EXPECTED_DEPARTURE, train.getExpectedDepartureTime(rl));
        rln.put(LOCATION, getLocation(locale, rl.getLocation().getId()).get(DATA));
        //add this routeLocation to the routeLocation array
        rlan.add(rln);
    }
    //return array of routeLocations
    return rlan;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 73 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.

the class JsonUtil method getCarsForTrain.

private ArrayNode getCarsForTrain(Locale locale, Train train) {
    ArrayNode clan = mapper.createArrayNode();
    CarManager carManager = CarManager.instance();
    List<Car> carList = carManager.getByTrainDestinationList(train);
    carList.forEach((car) -> {
        //add each car's data to the carList array
        clan.add(getCar(locale, car.getId()).get(DATA));
    });
    //return array of car data
    return clan;
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 74 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.

the class WebAppServlet method processAbout.

private void processAbout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType(UTF8_APPLICATION_JSON);
    Profile profile = ProfileManager.getDefault().getActiveProfile();
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode about = mapper.createObjectNode();
    // NOI18N
    about.put("additionalInfo", "TRADEMARKS AND LICENSE GO HERE");
    // NOI18N
    about.put("copyright", Version.getCopyright());
    // NOI18N
    about.put("title", WebServerPreferences.getDefault().getRailRoadName());
    // NOI18N
    about.put("imgAlt", Application.getApplicationName());
    // assuming Application.getLogo() is relative to program:
    // NOI18N
    about.put("imgSrc", "/" + Application.getLogo());
    // NOI18N
    ArrayNode productInfo = about.putArray("productInfo");
    productInfo.add(mapper.createObjectNode().put(NAME, Application.getApplicationName()).put(VALUE, Version.name()));
    // NOI18N
    productInfo.add(mapper.createObjectNode().put(NAME, Bundle.getMessage(request.getLocale(), "ActiveProfile")).put(VALUE, profile.getName()));
    productInfo.add(mapper.createObjectNode().put(NAME, // NOI18N
    "Java").put(VALUE, Bundle.getMessage(request.getLocale(), "JavaVersion", // NOI18N
    System.getProperty("java.version", Bundle.getMessage(request.getLocale(), "Unknown")), // NOI18N
    System.getProperty("java.vm.name", Bundle.getMessage(request.getLocale(), "Unknown")), // NOI18N
    System.getProperty("java.vm.version", ""), // NOI18N
    System.getProperty("java.vendor", Bundle.getMessage(request.getLocale(), "Unknown")))));
    productInfo.add(mapper.createObjectNode().put(NAME, Bundle.getMessage(request.getLocale(), "Runtime")).put(VALUE, Bundle.getMessage(request.getLocale(), "RuntimeVersion", // NOI18N
    System.getProperty("java.runtime.name", Bundle.getMessage(request.getLocale(), "Unknown")), // NOI18N
    System.getProperty("java.runtime.version", ""))));
    for (ConnectionConfig conn : InstanceManager.getDefault(ConnectionConfigManager.class)) {
        if (!conn.getDisabled()) {
            productInfo.add(mapper.createObjectNode().put(NAME, Bundle.getMessage(request.getLocale(), "ConnectionName", conn.getConnectionName())).put(VALUE, Bundle.getMessage(request.getLocale(), "ConnectionValue", conn.name(), conn.getInfo())));
        }
    }
    response.getWriter().print(mapper.writeValueAsString(about));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Profile(jmri.profile.Profile) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConnectionConfig(jmri.jmrix.ConnectionConfig)

Example 75 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.

the class JsonUtilHttpService method getSystemConnections.

/**
     *
     * @param locale the client's Locale.
     * @return the JSON systemConnections message.
     */
public ArrayNode getSystemConnections(Locale locale) {
    ArrayNode root = mapper.createArrayNode();
    ArrayList<String> prefixes = new ArrayList<>();
    for (ConnectionConfig config : InstanceManager.getDefault(ConnectionConfigManager.class)) {
        if (!config.getDisabled()) {
            ObjectNode connection = mapper.createObjectNode().put(JSON.TYPE, JSON.SYSTEM_CONNECTION);
            ObjectNode data = connection.putObject(JSON.DATA);
            data.put(JSON.NAME, config.getConnectionName());
            data.put(JSON.MFG, config.getManufacturer());
            data.put(JSON.PREFIX, config.getAdapter().getSystemConnectionMemo().getSystemPrefix());
            data.put(JSON.DESCRIPTION, Bundle.getMessage(locale, "ConnectionSucceeded", config.getConnectionName(), config.name(), config.getInfo()));
            prefixes.add(config.getAdapter().getSystemConnectionMemo().getSystemPrefix());
            root.add(connection);
        }
    }
    InstanceManager.getList(SystemConnectionMemo.class).stream().map((instance) -> instance).filter((memo) -> (!memo.getDisabled() && !prefixes.contains(memo.getSystemPrefix()))).forEach((memo) -> {
        ObjectNode connection = mapper.createObjectNode().put(JSON.TYPE, JSON.SYSTEM_CONNECTION);
        ObjectNode data = connection.putObject(JSON.DATA);
        data.put(JSON.NAME, memo.getUserName());
        data.put(JSON.PREFIX, memo.getSystemPrefix());
        data.putNull(JSON.MFG);
        data.putNull(JSON.DESCRIPTION);
        prefixes.add(memo.getSystemPrefix());
        root.add(connection);
    });
    // Following is required because despite there being a SystemConnectionMemo
    // for the default internal connection, it is not used for the default internal
    // connection. This allows a client to map the server's internal objects.
    String prefix = "I";
    if (!prefixes.contains(prefix)) {
        ObjectNode connection = mapper.createObjectNode().put(JSON.TYPE, JSON.SYSTEM_CONNECTION);
        ObjectNode data = connection.putObject(JSON.DATA);
        data.put(JSON.NAME, ConnectionNameFromSystemName.getConnectionName(prefix));
        data.put(JSON.PREFIX, prefix);
        data.putNull(JSON.MFG);
        data.putNull(JSON.DESCRIPTION);
        root.add(connection);
    }
    return root;
}
Also used : ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) ConnectionConfig(jmri.jmrix.ConnectionConfig) URL(jmri.server.json.JSON.URL) ProfileManager(jmri.profile.ProfileManager) DccLocoAddress(jmri.DccLocoAddress) JmriJFrame(jmri.util.JmriJFrame) PANEL(jmri.server.json.JSON.PANEL) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Editor(jmri.jmrit.display.Editor) JsonException(jmri.server.json.JsonException) SWITCHBOARD_PANEL(jmri.server.json.JSON.SWITCHBOARD_PANEL) ArrayList(java.util.ArrayList) TYPE(jmri.server.json.JSON.TYPE) JsonServerPreferences(jmri.jmris.json.JsonServerPreferences) ConnectionConfigManager(jmri.jmrix.ConnectionConfigManager) Locale(java.util.Locale) Profile(jmri.profile.Profile) SwitchboardEditor(jmri.jmrit.display.switchboardEditor.SwitchboardEditor) PanelEditor(jmri.jmrit.display.panelEditor.PanelEditor) JsonNode(com.fasterxml.jackson.databind.JsonNode) NAME(jmri.server.json.JSON.NAME) InstanceManager(jmri.InstanceManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonHttpService(jmri.server.json.JsonHttpService) Metadata(jmri.Metadata) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) WebServerPreferences(jmri.web.server.WebServerPreferences) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) CONTROL_PANEL(jmri.server.json.JSON.CONTROL_PANEL) ConnectionNameFromSystemName(jmri.util.ConnectionNameFromSystemName) DATA(jmri.server.json.JSON.DATA) USERNAME(jmri.server.json.JSON.USERNAME) JSON(jmri.server.json.JSON) NodeIdentity(jmri.util.node.NodeIdentity) ZeroConfService(jmri.util.zeroconf.ZeroConfService) LAYOUT_PANEL(jmri.server.json.JSON.LAYOUT_PANEL) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ConnectionConfig(jmri.jmrix.ConnectionConfig)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)979 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)542 JsonNode (com.fasterxml.jackson.databind.JsonNode)402 Test (org.junit.Test)140 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)125 ArrayList (java.util.ArrayList)110 IOException (java.io.IOException)93 Map (java.util.Map)74 HashMap (java.util.HashMap)68 List (java.util.List)50 TextNode (com.fasterxml.jackson.databind.node.TextNode)38 Test (org.testng.annotations.Test)35 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)30 HashSet (java.util.HashSet)30 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)25 Deployment (org.activiti.engine.test.Deployment)23 File (java.io.File)22 InputStream (java.io.InputStream)20 Iterator (java.util.Iterator)20 StringEntity (org.apache.http.entity.StringEntity)20