From 899d50492ce5c151a2a7f2cfdfdd82bd3fdde514 Mon Sep 17 00:00:00 2001 From: Zellweger Christof Ralf Date: Thu, 25 Jun 2015 12:36:43 +0200 Subject: [PATCH] ATEST-81: - correct build setup - add javadoc --- build.gradle | 1 - .../rest/controller/DaqRestController.java | 21 ++------ .../psi/daq/rest/queries/AbstractQuery.java | 53 ++++++++++++------- .../psi/daq/rest/queries/PulseRangeQuery.java | 33 +++++++++--- .../psi/daq/rest/queries/TimeRangeQuery.java | 46 ++++++++++------ 5 files changed, 92 insertions(+), 62 deletions(-) diff --git a/build.gradle b/build.gradle index 755793a..d10603e 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,6 @@ applicationDefaultJvmArgs = [ //} dependencies { - compile (project(':ch.psi.daq.cassandra')) compile (project(':ch.psi.daq.hazelcast')) compile 'org.springframework.boot:spring-boot-starter-web:1.2.4.RELEASE' compile 'com.google.code.gson:gson:2+' diff --git a/src/main/java/ch/psi/daq/rest/controller/DaqRestController.java b/src/main/java/ch/psi/daq/rest/controller/DaqRestController.java index a9ea4c8..99d34c6 100644 --- a/src/main/java/ch/psi/daq/rest/controller/DaqRestController.java +++ b/src/main/java/ch/psi/daq/rest/controller/DaqRestController.java @@ -38,12 +38,8 @@ public class DaqRestController { @Autowired private QueryProcessor queryProcessor; - /** - * - * @param query - * @param res - * @throws IOException - */ + + @RequestMapping(value = "/pulserange") public void pulseRange(@RequestBody PulseRangeQuery query, HttpServletResponse res) throws IOException { @@ -53,12 +49,6 @@ public class DaqRestController { } - /** - * - * @param query - * @param res - * @throws IOException - */ @RequestMapping(value = "/timerange") public void timeRange(@RequestBody TimeRangeQuery query, HttpServletResponse res) throws IOException { @@ -67,12 +57,7 @@ public class DaqRestController { executeQuery(query, res); } - /** - * - * @param query - * @param res - * @throws IOException - */ + private void executeQuery(AbstractQuery query, HttpServletResponse res) throws IOException { // all the magic happens here diff --git a/src/main/java/ch/psi/daq/rest/queries/AbstractQuery.java b/src/main/java/ch/psi/daq/rest/queries/AbstractQuery.java index 9bed2ea..bcf67c3 100644 --- a/src/main/java/ch/psi/daq/rest/queries/AbstractQuery.java +++ b/src/main/java/ch/psi/daq/rest/queries/AbstractQuery.java @@ -9,6 +9,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.Assert; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonSubTypes.Type; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + import ch.psi.daq.cassandra.reader.Ordering; import ch.psi.daq.hazelcast.query.Aggregation; import ch.psi.daq.hazelcast.query.AggregationType; @@ -17,12 +23,6 @@ import ch.psi.daq.hazelcast.query.bin.BinningStrategy; import ch.psi.daq.hazelcast.query.bin.BinningStrategyFactory; import ch.psi.daq.hazelcast.query.range.QueryRange; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonSubTypes.Type; -import com.fasterxml.jackson.annotation.JsonTypeInfo; - /** * * @author zellweger_c @@ -38,9 +38,9 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; @Type(value = TimeRangeQuery.class, name = "timerange"), }) public abstract class AbstractQuery implements Query { - + private static Logger logger = LoggerFactory.getLogger(AbstractQuery.class); - + private List channels; private LinkedHashSet fields; @@ -60,12 +60,23 @@ public abstract class AbstractQuery implements Query { private QueryRange queryRange; /** + * Constructor. * * @param ordering whether to add a 'orderBy' clause into the database query * @param channels all the channelIds (channel names) we want to query * @param fields the fields (who map to fields in the DB) we are interested in returning to the * client, needs to be in insertion order (hence the {@link LinkedHashSet} type) - * @param queryRange TODO + * @param binningStrategyEnum enum that maps the user's String to a concrete + * {@link BinningStrategy} implementation + * @param binLengthOrCount depending on the chosen binning strategy, this field defines either the + * count (how many pulse ids are to be put inside 1 bin) or the time frame for 1 bin + * @param aggregateChannels whether aggregation will include all channels, default is on a + * per-channel basis + * @param aggregationType defines whether aggregation takes place in an index- or value-based + * manner + * @param aggregations list of aggregations / statistics to calculate, e.g. min, max and average + * @param queryRange object containing the ranges for either pulse-based queries or time-based + * queries */ @JsonCreator public AbstractQuery( @@ -75,7 +86,7 @@ public abstract class AbstractQuery implements Query { @JsonProperty(value = "channels") List channels, @JsonProperty(value = "fields") LinkedHashSet fields, @JsonProperty(value = "binningStrategy") BinningStrategyEnum binningStrategyEnum, - @JsonProperty(value = "binDuration") long lengthOrCount, + @JsonProperty(value = "binDuration") long binLengthOrCount, @JsonProperty(value = "aggregateChannels") boolean aggregateChannels, @JsonProperty(value = "aggregationType") AggregationType aggregationType, @JsonProperty(value = "aggregations") List aggregations, @@ -93,23 +104,24 @@ public abstract class AbstractQuery implements Query { this.channels = channels; this.fields = fields; - this.binningStrategyEnum = binningStrategyEnum; // can be null: default then will be BinCountBinningStrategy - - + this.binningStrategyEnum = binningStrategyEnum; // can be null: default then will be + // BinCountBinningStrategy + + if (binningStrategyEnum != null) { switch (binningStrategyEnum) { case count: - this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), (int) lengthOrCount); + this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), (int) binLengthOrCount); break; case length: - this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), lengthOrCount); + this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), binLengthOrCount); break; default: logger.warn("No binning strategy has been set. Selecting BinningStrategyBinCount."); - this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), (int) lengthOrCount); + this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), (int) binLengthOrCount); } } else { - this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), (int) lengthOrCount); + this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), (int) binLengthOrCount); } } @@ -138,6 +150,7 @@ public abstract class AbstractQuery implements Query { } + @Override public boolean isAggregateChannels() { return aggregateChannels; } @@ -145,7 +158,7 @@ public abstract class AbstractQuery implements Query { public BinningStrategyEnum getBinningStrategyEnum() { return binningStrategyEnum; } - + @Override public BinningStrategy getBinningStrategy() { return binningStrategy; @@ -158,7 +171,7 @@ public abstract class AbstractQuery implements Query { public List getAggregations() { return aggregations; } - + /** * {@inheritDoc} */ @@ -166,7 +179,7 @@ public abstract class AbstractQuery implements Query { public QueryRange getQueryRange() { return queryRange; } - + public void setQueryRange(QueryRange queryRange) { this.queryRange = queryRange; } diff --git a/src/main/java/ch/psi/daq/rest/queries/PulseRangeQuery.java b/src/main/java/ch/psi/daq/rest/queries/PulseRangeQuery.java index ba8f9f1..0237c95 100644 --- a/src/main/java/ch/psi/daq/rest/queries/PulseRangeQuery.java +++ b/src/main/java/ch/psi/daq/rest/queries/PulseRangeQuery.java @@ -3,21 +3,42 @@ package ch.psi.daq.rest.queries; import java.util.LinkedHashSet; import java.util.List; -import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import ch.psi.daq.cassandra.reader.Ordering; import ch.psi.daq.hazelcast.query.Aggregation; import ch.psi.daq.hazelcast.query.AggregationType; +import ch.psi.daq.hazelcast.query.bin.BinningStrategy; import ch.psi.daq.hazelcast.query.range.QueryRange; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - /** * */ public class PulseRangeQuery extends AbstractQuery { + + /** + * Constructor. + * + * @param ordering whether to add a 'orderBy' clause into the database query + * @param channels all the channelIds (channel names) we want to query + * @param fields the fields (who map to fields in the DB) we are interested in returning to the + * client, needs to be in insertion order (hence the {@link LinkedHashSet} type) + * @param binningStrategyEnum enum that maps the user's String to a concrete + * {@link BinningStrategy} implementation + * @param binLengthOrCount depending on the chosen binning strategy, this field defines either the + * count (how many pulse ids are to be put inside 1 bin) or the time frame for 1 bin + * @param aggregateChannels whether aggregation will include all channels, default is on a + * per-channel basis + * @param aggregationType defines whether aggregation takes place in an index- or value-based + * manner + * @param aggregations list of aggregations / statistics to calculate, e.g. min, max and average + * @param queryRange object containing the ranges for either pulse-based queries or time-based + * queries + */ @JsonCreator public PulseRangeQuery( // note that those annotations are needed for the polymorphic @@ -26,13 +47,13 @@ public class PulseRangeQuery extends AbstractQuery { @JsonProperty(value = "channels") List channels, @JsonProperty(value = "fields") LinkedHashSet fields, @JsonProperty(value = "binningStrategy") BinningStrategyEnum binningStrategyEnum, - @JsonProperty(value = "binDuration") long binDurationOrBinCount, + @JsonProperty(value = "binDuration") long binLengthOrCount, @JsonProperty(value = "aggregateChannels") boolean aggregateChannels, @JsonProperty(value = "aggregationType") AggregationType aggregationType, @JsonProperty(value = "aggregations") List aggregations, @JsonProperty(value = "queryRange") QueryRange queryRange) { - super(ordering, channels, fields, binningStrategyEnum, binDurationOrBinCount, aggregateChannels, aggregationType, + super(ordering, channels, fields, binningStrategyEnum, binLengthOrCount, aggregateChannels, aggregationType, aggregations, queryRange); } diff --git a/src/main/java/ch/psi/daq/rest/queries/TimeRangeQuery.java b/src/main/java/ch/psi/daq/rest/queries/TimeRangeQuery.java index 45404bf..af4c1cc 100644 --- a/src/main/java/ch/psi/daq/rest/queries/TimeRangeQuery.java +++ b/src/main/java/ch/psi/daq/rest/queries/TimeRangeQuery.java @@ -6,18 +6,19 @@ import java.util.Date; import java.util.LinkedHashSet; import java.util.List; -import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + import ch.psi.daq.cassandra.reader.Ordering; import ch.psi.daq.hazelcast.query.Aggregation; import ch.psi.daq.hazelcast.query.AggregationType; +import ch.psi.daq.hazelcast.query.bin.BinningStrategy; import ch.psi.daq.hazelcast.query.range.QueryRange; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - public class TimeRangeQuery extends AbstractQuery { @@ -26,19 +27,28 @@ public class TimeRangeQuery extends AbstractQuery { private static Logger logger = LoggerFactory.getLogger(TimeRangeQuery.class); /** + * Constructor * * @param ordering whether to add a 'orderBy' clause into the database query - * @param channelIds all the sourceIds (channel names) we want to query + * @param channels all the channelIds (channel names) we want to query * @param fields the fields (who map to fields in the DB) we are interested in returning to the * client, needs to be in insertion order (hence the {@link LinkedHashSet} type) - * @param binningStrategyEnum - * @param binDurationOrBinCount - * @param aggregateChannels - * @param aggregationType - * @param aggregations - * @param queryRange - * @param startDateTime - * @param endDateTime + * @param binningStrategyEnum enum that maps the user's String to a concrete + * {@link BinningStrategy} implementation + * @param binLengthOrCount depending on the chosen binning strategy, this field defines either the + * count (how many pulse ids are to be put inside 1 bin) or the time frame for 1 bin + * @param aggregateChannels whether aggregation will include all channels, default is on a + * per-channel basis + * @param aggregationType defines whether aggregation takes place in an index- or value-based + * manner + * @param aggregations list of aggregations / statistics to calculate, e.g. min, max and average + * @param queryRange object containing the ranges for either pulse-based queries or time-based + * queries + * @param startDateTime if set, the date string (format is: + * {@link TimeRangeQuery#DATE_FORMAT_STRING} will be parsed and converted into + * milliseconds + * @param endDateTime set, the date string (format is: {@link TimeRangeQuery#DATE_FORMAT_STRING} + * will be parsed and converted into milliseconds */ @JsonCreator public TimeRangeQuery( @@ -48,7 +58,7 @@ public class TimeRangeQuery extends AbstractQuery { @JsonProperty(value = "channels") List channels, @JsonProperty(value = "fields") LinkedHashSet fields, @JsonProperty(value = "binningStrategy") BinningStrategyEnum binningStrategyEnum, - @JsonProperty(value = "binDuration") long binDurationOrBinCount, + @JsonProperty(value = "binDuration") long binLengthOrCount, @JsonProperty(value = "aggregateChannels") boolean aggregateChannels, @JsonProperty(value = "aggregationType") AggregationType aggregationType, @JsonProperty(value = "aggregations") List aggregations, @@ -56,15 +66,17 @@ public class TimeRangeQuery extends AbstractQuery { @JsonProperty(value = "startDateTime") String startDateTime, @JsonProperty(value = "endDateTime") String endDateTime) { - super(ordering, channels, fields, binningStrategyEnum, binDurationOrBinCount, aggregateChannels, aggregationType, aggregations, queryRange); - + super(ordering, channels, fields, binningStrategyEnum, binLengthOrCount, aggregateChannels, aggregationType, + aggregations, queryRange); + if (startDateTime != null && endDateTime != null) { logger.info("startDateTime and endDateTime specified. This takes precedence over the start / end fields."); try { Date startDate = DATE_FORMAT.parse(startDateTime); Date endDate = DATE_FORMAT.parse(endDateTime); - getQueryRange().setTimeRange(startDate.getTime(), queryRange.getStartNanos(), endDate.getTime(), queryRange.getEndNanos()); + getQueryRange().setTimeRange(startDate.getTime(), queryRange.getStartNanos(), endDate.getTime(), + queryRange.getEndNanos()); } catch (ParseException e) { logger.error("Parsing the start- and/or endDate was unsuccessful. " + "The format must be '" + DATE_FORMAT_STRING + "'", e);