Skip to content

Instantly share code, notes, and snippets.

@Romeh
Created November 17, 2017 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Romeh/0b5cc33aeef9e0ef7a2032c5729fe32b to your computer and use it in GitHub Desktop.
Save Romeh/0b5cc33aeef9e0ef7a2032c5729fe32b to your computer and use it in GitHub Desktop.
@Override
public List<AlertEntry> getAlertForServiceId(String serviceId) {
final String sql = "serviceId = ?";
// create the sql query object with entity type of the value part of the key value cache
SqlQuery<String, AlertEntry> query = new SqlQuery<>(AlertEntry.class, sql);
// set the query params
query.setArgs(serviceId);
//then execute it over the cache
return Optional.ofNullable(getAlertsCache().query(query).getAll().stream().map(stringAlertEntryEntry -> stringAlertEntryEntry.getValue()).collect(Collectors.toList()))
.orElseThrow(() -> new ResourceNotFoundException(String.format("Alert for %s not found", serviceId)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment