use of org.openmuc.framework.dataaccess.DataLoggerNotAvailableException 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.DataLoggerNotAvailableException in project OpenMUC by isc-konstanz.
the class DataManager method getDataLogger.
DataLoggerService getDataLogger(String loggerId) throws DataLoggerNotAvailableException {
DataLoggerService dataLogger;
if (loggerId == null || loggerId.isEmpty()) {
dataLogger = activeDataLoggers.peekFirst();
} else {
dataLogger = activeDataLoggers.stream().filter(activeLogger -> activeLogger.getId().equals(loggerId)).findFirst().orElseThrow(() -> {
logger.warn("DataLogger with id " + loggerId + " not found for reading logs!");
return new DataLoggerNotAvailableException();
});
}
logger.debug("Accessing logged values using {}", dataLogger.getId());
return dataLogger;
}
Aggregations