FlexiBean out = createSearchResultData(pr, identifier, dataSource, dataProvider, dataField, observationTime, name, uriInfo);
return getFreemarker().build(JSON_DIR + "alltimeseries.ftl", out);
}
private FlexiBean createSearchResultData(PagingRequest pr, String identifier, String dataSource, String dataProvider, String dataField, String observationTime, String name, UriInfo uriInfo) {
FlexiBean out = createRootData();
HistoricalTimeSeriesInfoSearchRequest searchRequest = new HistoricalTimeSeriesInfoSearchRequest();
searchRequest.setPagingRequest(pr);
searchRequest.setExternalIdValue(StringUtils.trimToNull(identifier));
searchRequest.setDataSource(StringUtils.trimToNull(dataSource));
searchRequest.setDataProvider(StringUtils.trimToNull(dataProvider));
searchRequest.setDataField(StringUtils.trimToNull(dataField));
searchRequest.setObservationTime(StringUtils.trimToNull(observationTime));
searchRequest.setName(StringUtils.trimToNull(name));
MultivaluedMap<String, String> query = uriInfo.getQueryParameters();
for (int i = 0; query.containsKey("idscheme." + i) && query.containsKey("idvalue." + i); i++) {
ExternalId id = ExternalId.of(query.getFirst("idscheme." + i), query.getFirst("idvalue." + i));
searchRequest.addExternalId(id);
}
out.put("searchRequest", searchRequest);
if (data().getUriInfo().getQueryParameters().size() > 0) {
ExternalIdWithDatesDisplayComparator comparator = ExternalIdWithDatesDisplayComparatorUtils.getComparator(data().getConfigSource(), ExternalIdDisplayComparatorUtils.DEFAULT_CONFIG_NAME);
HistoricalTimeSeriesInfoSearchResult searchResult = data().getHistoricalTimeSeriesMaster().search(searchRequest);
for (HistoricalTimeSeriesInfoDocument doc : searchResult.getDocuments()) {
// replace ids with one's sorted the way we want.
ExternalIdBundleWithDates withCustomIdOrdering = doc.getInfo().getExternalIdBundle().withCustomIdOrdering(comparator);
doc.getInfo().setExternalIdBundle(withCustomIdOrdering);
}
out.put("searchResult", searchResult);
out.put("paging", new WebPaging(searchResult.getPaging(), data().getUriInfo()));
}
return out;
}