Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#371 Support dynamic measurement name in InfluxDBResultMapper #423

Merged
merged 2 commits into from
Apr 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions src/main/java/org/influxdb/impl/InfluxDBResultMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,51 @@ public class InfluxDBResultMapper {
* @param queryResult the InfluxDB result object
* @param clazz the Class that will be used to hold your measurement data
* @param <T> the target type
*
* @return a {@link List} of objects from the same Class passed as parameter and sorted on the
* same order as received from InfluxDB.
* same order as received from InfluxDB.
*
* @throws InfluxDBMapperException If {@link QueryResult} parameter contain errors,
* <tt>clazz</tt> parameter is not annotated with &#64;Measurement or it was not
* possible to define the values of your POJO (e.g. due to an unsupported field type).
* <tt>clazz</tt> parameter is not annotated with &#64;Measurement or it was not
* possible to define the values of your POJO (e.g. due to an unsupported field type).
*/
public <T> List<T> toPOJO(final QueryResult queryResult, final Class<T> clazz) throws InfluxDBMapperException {
throwExceptionIfMissingAnnotation(clazz);
String measurementName = getMeasurementName(clazz);
return this.toPOJO(queryResult, clazz, measurementName);
}

/**
* <p>
* Process a {@link QueryResult} object returned by the InfluxDB client inspecting the internal
* data structure and creating the respective object instances based on the Class passed as
* parameter.
* </p>
*
* @param queryResult the InfluxDB result object
* @param clazz the Class that will be used to hold your measurement data
* @param <T> the target type
* @param measurementName name of the Measurement
*
* @return a {@link List} of objects from the same Class passed as parameter and sorted on the
* same order as received from InfluxDB.
*
* @throws InfluxDBMapperException If {@link QueryResult} parameter contain errors,
* <tt>clazz</tt> parameter is not annotated with &#64;Measurement or it was not
* possible to define the values of your POJO (e.g. due to an unsupported field type).
*/
public <T> List<T> toPOJO(final QueryResult queryResult, final Class<T> clazz, final String measurementName)
throws InfluxDBMapperException {

Objects.requireNonNull(measurementName, "measurementName");
Objects.requireNonNull(queryResult, "queryResult");
Objects.requireNonNull(clazz, "clazz");

throwExceptionIfMissingAnnotation(clazz);
throwExceptionIfResultWithError(queryResult);
cacheMeasurementClass(clazz);

List<T> result = new LinkedList<T>();
String measurementName = getMeasurementName(clazz);

queryResult.getResults().stream()
.filter(internalResult -> Objects.nonNull(internalResult) && Objects.nonNull(internalResult.getSeries()))
.forEach(internalResult -> {
Expand All @@ -99,7 +128,7 @@ public <T> List<T> toPOJO(final QueryResult queryResult, final Class<T> clazz) t
.forEachOrdered(series -> {
parseSeriesAs(series, clazz, result);
});
});
});

return result;
}
Expand Down