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;
}
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;
}
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;
}
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));
}
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;
}
Aggregations