use of io.syndesis.server.dao.manager.operators.IdPrefixFilter in project syndesis by syndesisio.
the class JsonDbDao method fetchAll.
@Override
@SuppressWarnings({ "unchecked", "PMD.CyclomaticComplexity" })
public ListResult<T> fetchAll(Function<ListResult<T>, ListResult<T>>... operators) {
try {
GetOptions options = new GetOptions();
// Try to convert operators to equivalent DB queries.
if (operators != null) {
for (int i = 0; i < operators.length; i++) {
Function<ListResult<T>, ListResult<T>> operator = operators[i];
if (operator.getClass() == IdPrefixFilter.class) {
IdPrefixFilter<T> filter = (IdPrefixFilter<T>) operator;
options.startAt(":" + filter.getPrefix());
options.endAt(":" + filter.getPrefix());
// Take it out of the list.
operators[i] = null;
}
}
}
// get the data out..
byte[] json = jsondb.getAsByteArray(getCollectionPath(), options);
ListResult<T> result;
if (json != null && json.length > 0) {
// Lets use jackson to parse the map of keys to our model instances
ObjectReader reader = Json.reader();
TypeFactory typeFactory = reader.getTypeFactory();
MapType mapType = typeFactory.constructMapType(LinkedHashMap.class, String.class, getType());
LinkedHashMap<String, T> map = reader.forType(mapType).readValue(json);
result = ListResult.of(map.values());
} else {
result = ListResult.of(Collections.<T>emptyList());
}
if (operators == null) {
return result;
}
for (Function<ListResult<T>, ListResult<T>> operator : operators) {
if (operator != null) {
result = operator.apply(result);
}
}
return result;
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException | IOException e) {
throw SyndesisServerException.launderThrowable(e);
}
}
Aggregations