use of org.openmuc.framework.dataaccess.Channel in project OpenMUC by isc-konstanz.
the class ChannelResourceServlet method doGetHistory.
private void doGetHistory(ToJson json, String channelId, String fromParameter, String untilParameter, HttpServletResponse response) {
long fromTimeStamp = 0;
long untilTimeStamp = 0;
List<String> channelIds = dataAccess.getAllIds();
List<Record> records = null;
if (channelIds.contains(channelId)) {
Channel channel = dataAccess.getChannel(channelId);
try {
fromTimeStamp = Long.parseLong(fromParameter);
untilTimeStamp = Long.parseLong(untilParameter);
} catch (NumberFormatException ex) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_BAD_REQUEST, logger, "From/To value is not a long number.");
}
try {
records = channel.getLoggedRecords(fromTimeStamp, untilTimeStamp);
} catch (DataLoggerNotAvailableException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, logger, e.getMessage());
} catch (IOException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, e.getMessage());
}
json.addRecordList(records, channel.getValueType());
}
}
use of org.openmuc.framework.dataaccess.Channel in project OpenMUC by isc-konstanz.
the class ToJson method addRecordList.
public void addRecordList(List<Channel> channels) throws ClassCastException {
JsonArray jsa = new JsonArray();
for (Channel channel : channels) {
JsonObject jso = new JsonObject();
jso.addProperty(Const.ID, channel.getId());
jso.addProperty(Const.VALUE_TYPE, channel.getValueType().toString());
jso.add(Const.RECORD, getRecordAsJsonElement(channel.getLatestRecord(), channel.getValueType()));
jsa.add(jso);
}
jsonObject.add(Const.RECORDS, jsa);
}
use of org.openmuc.framework.dataaccess.Channel in project OpenMUC by isc-konstanz.
the class ToJson method addChannelStateList.
public void addChannelStateList(List<Channel> channelList) {
JsonArray jsa = new JsonArray();
for (Channel channel : channelList) {
JsonObject jso = new JsonObject();
jso.addProperty(Const.ID, channel.getId());
jso.addProperty(Const.STATE, channel.getChannelState().name());
jsa.add(jso);
}
jsonObject.add(Const.STATES, jsa);
}
use of org.openmuc.framework.dataaccess.Channel in project OpenMUC by isc-konstanz.
the class MqttDriverConnection method startListening.
@Override
public void startListening(List<ChannelRecordContainer> containers, RecordsReceivedListener listener) throws UnsupportedOperationException, ConnectionException {
List<String> topics = new ArrayList<>();
for (ChannelRecordContainer container : containers) {
String topic = Stream.of(container.getChannelAddress().split(";")).findFirst().orElse(ChannelConfig.ADDRESS_DEFAULT);
topics.add(topic);
}
if (topics.isEmpty()) {
return;
}
mqttReader.listen(topics, (topic, message) -> {
if (!topics.contains(topic)) {
logger.warn("Unable to find received topic \"{}\" in subscribed list", topic);
return;
}
for (ChannelRecordContainer container : containers) {
if (!Stream.of(container.getChannelAddress().split(";")).findFirst().orElse(ChannelConfig.ADDRESS_DEFAULT).equals(topic)) {
continue;
}
Channel channel = container.getChannel();
Record record = getRecord(message, container);
if (recordIsOld(channel.getId(), record)) {
continue;
}
addMessageToContainerList(record, container);
}
if (recordContainerList.size() >= Integer.parseInt(settings.getProperty("recordCollectionSize", "1"))) {
notifyListenerAndPurgeList(listener);
}
});
}
use of org.openmuc.framework.dataaccess.Channel in project OpenMUC by isc-konstanz.
the class DeviceResourceServlet method getChannelList.
private List<Channel> getChannelList(String deviceId) {
List<Channel> channels = new ArrayList<>();
Collection<ChannelConfig> channelConfigs = rootConfig.getDevice(deviceId).getChannels();
for (ChannelConfig channelConfig : channelConfigs) {
channels.add(dataAccess.getChannel(channelConfig.getId()));
}
return channels;
}
Aggregations