use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.
the class JsonNamedBeanHttpService method getNamedBean.
/**
* Create the JsonNode for a {@link jmri.NamedBean} object.
*
* @param bean the bean to create the node for
* @param name the name of the bean; used only if the bean is null
* @param type the JSON type of the bean
* @param locale the locale used for any error messages
* @return a JSON node
* @throws JsonException if the bean is null
*/
@Nonnull
protected ObjectNode getNamedBean(NamedBean bean, @Nonnull String name, @Nonnull String type, @Nonnull Locale locale) throws JsonException {
if (bean == null) {
throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", type, name));
}
ObjectNode root = mapper.createObjectNode();
root.put(JSON.TYPE, type);
ObjectNode data = root.putObject(JSON.DATA);
data.put(JSON.NAME, bean.getSystemName());
data.put(JSON.USERNAME, bean.getUserName());
data.put(JSON.COMMENT, bean.getComment());
ArrayNode properties = root.putArray(JSON.PROPERTIES);
bean.getPropertyKeys().stream().forEach((key) -> {
Object value = bean.getProperty(key);
if (value != null) {
properties.add(mapper.createObjectNode().put(key, value.toString()));
} else {
properties.add(mapper.createObjectNode().putNull(key));
}
});
return data;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.
the class JsonConsistHttpService method getConsist.
/**
* Get the JSON representation of a consist.
*
* The JSON representation is an object with the following data attributes:
* <ul>
* <li>address - integer address</li>
* <li>isLongAddress - boolean true if address is long, false if short</li>
* <li>type - integer, see {@link jmri.Consist#getConsistType() }</li>
* <li>id - string with consist Id</li>
* <li>sizeLimit - the maximum number of locomotives the consist can
* contain</li>
* <li>engines - array listing every locomotive in the consist. Each entry
* in the array contains the following attributes:
* <ul>
* <li>address - integer address</li>
* <li>isLongAddress - boolean true if address is long, false if short</li>
* <li>forward - boolean true if the locomotive running is forward in the
* consists</li>
* <li>position - integer locomotive's position in the consist</li>
* </ul>
* </ul>
*
* @param locale The locale to throw exceptions in.
* @param address The address of the consist to get.
* @return The JSON representation of the consist.
* @throws JsonException This exception has code 404 if the consist does not
* exist.
*/
public JsonNode getConsist(Locale locale, DccLocoAddress address) throws JsonException {
if (this.manager.getConsistList().contains(address)) {
ObjectNode root = mapper.createObjectNode();
root.put(TYPE, CONSIST);
ObjectNode data = root.putObject(DATA);
Consist consist = this.manager.getConsist(address);
data.put(ADDRESS, consist.getConsistAddress().getNumber());
data.put(IS_LONG_ADDRESS, consist.getConsistAddress().isLongAddress());
data.put(TYPE, consist.getConsistType());
ArrayNode engines = data.putArray(ENGINES);
consist.getConsistList().stream().forEach((locomotive) -> {
ObjectNode engine = mapper.createObjectNode();
engine.put(ADDRESS, locomotive.getNumber());
engine.put(IS_LONG_ADDRESS, locomotive.isLongAddress());
engine.put(FORWARD, consist.getLocoDirection(locomotive));
engine.put(POSITION, consist.getPosition(locomotive));
engines.add(engine);
});
data.put(ID, consist.getConsistID());
data.put(SIZE_LIMIT, consist.sizeLimit());
return root;
} else {
// NOI18N
throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", CONSIST, address.toString()));
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.
the class JsonOperationsHttpService method getCars.
public ArrayNode getCars(Locale locale) {
ArrayNode root = mapper.createArrayNode();
CarManager.instance().getByIdList().forEach((rs) -> {
root.add(this.utilities.getCar(locale, rs.getId()));
});
return root;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.
the class JsonOperationsHttpService method getEngines.
public ArrayNode getEngines(Locale locale) {
ArrayNode root = mapper.createArrayNode();
EngineManager.instance().getByIdList().forEach((rs) -> {
root.add(this.utilities.getEngine(locale, rs.getId()));
});
return root;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.
the class JsonRosterHttpService method getRoster.
public ArrayNode getRoster(@Nonnull Locale locale, @Nonnull JsonNode data) {
String group = (!data.path(GROUP).isMissingNode()) ? data.path(GROUP).asText() : null;
if (Roster.ALLENTRIES.equals(group) || Roster.AllEntries(locale).equals(group)) {
group = null;
}
String roadName = (!data.path(ROAD).isMissingNode()) ? data.path(ROAD).asText() : null;
String roadNumber = (!data.path(NUMBER).isMissingNode()) ? data.path(NUMBER).asText() : null;
String dccAddress = (!data.path(ADDRESS).isMissingNode()) ? data.path(ADDRESS).asText() : null;
String mfg = (!data.path(MFG).isMissingNode()) ? data.path(MFG).asText() : null;
String decoderModel = (!data.path(DECODER_MODEL).isMissingNode()) ? data.path(DECODER_MODEL).asText() : null;
String decoderFamily = (!data.path(DECODER_FAMILY).isMissingNode()) ? data.path(DECODER_FAMILY).asText() : null;
String id = (!data.path(NAME).isMissingNode()) ? data.path(NAME).asText() : null;
ArrayNode root = this.mapper.createArrayNode();
for (RosterEntry entry : Roster.getDefault().getEntriesMatchingCriteria(roadName, roadNumber, dccAddress, mfg, decoderModel, decoderFamily, id, group)) {
root.add(getRosterEntry(locale, entry));
}
return root;
}
Aggregations