@Path("{timeseriesId}")
public WebHistoricalTimeSeriesResource findSeries(@Subscribe @PathParam("timeseriesId") String idStr) {
data().setUriHistoricalTimeSeriesId(idStr);
UniqueId oid = UniqueId.parse(idStr);
HistoricalTimeSeriesInfoDocument info;
ManageableHistoricalTimeSeries series;
try {
// Try to fetch HTS info
info = data().getHistoricalTimeSeriesMaster().get(UniqueId.parse(idStr));
} catch (DataNotFoundException ex) {
// If not there, try fetching a deleted one from history
HistoricalTimeSeriesInfoHistoryRequest historyRequest = new HistoricalTimeSeriesInfoHistoryRequest(oid);
historyRequest.setPagingRequest(PagingRequest.ONE);
HistoricalTimeSeriesInfoHistoryResult historyResult = data().getHistoricalTimeSeriesMaster().history(historyRequest);
if (historyResult.getDocuments().size() == 0) {
// None found in history either; just return
return null;
}
info = historyResult.getFirstDocument();
}
data().setInfo(info);
try {
// Try to fetch the data-points
series = data().getHistoricalTimeSeriesMaster().getTimeSeries(
info.getInfo().getTimeSeriesObjectId(), VersionCorrection.LATEST);
} catch (DataNotFoundException ex) {
// If not there, return an empty collection of data-points
series = new ManageableHistoricalTimeSeries();
series.setTimeSeries(ImmutableLocalDateDoubleTimeSeries.EMPTY_SERIES);
}