Loading DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/DataPointsEndpoint.java +3 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import cz.muni.fi.lasaris.sbms.data.api.request.GroupedAddressRequest; import cz.muni.fi.lasaris.sbms.data.api.request.AddressRequest; import cz.muni.fi.lasaris.sbms.data.api.response.AggregateResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SnapshotResponse; import cz.muni.fi.lasaris.sbms.data.api.response.ValueResponse; import cz.muni.fi.lasaris.sbms.data.entities.Address; import cz.muni.fi.lasaris.sbms.data.entities.AggregationFunction; import cz.muni.fi.lasaris.sbms.data.entities.values.RawValue; Loading Loading @@ -131,12 +132,12 @@ public class DataPointsEndpoint { @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) public SnapshotResponse getDataPoint( public ValueResponse getDataPoint( @PathParam("id") String idP, @QueryParam("cache") String cache) { Address a = new Address(idP); RawValue v = ProviderManager.getDataPointsProvider(a.getProtocol()).getDataPointValue(a, allowCache(cache)); return new SnapshotResponse(a, v); return new ValueResponse(v); } private boolean allowCache(String cache) { Loading DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/TrendsEndpoint.java +395 −58 Original line number Diff line number Diff line Loading @@ -4,14 +4,11 @@ import java.io.IOException; import java.time.Duration; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalUnit; import java.util.Arrays; import java.util.Map; import javax.annotation.security.RolesAllowed; import javax.ws.rs.DefaultValue; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; Loading @@ -27,14 +24,24 @@ import cz.muni.fi.lasaris.sbms.data.api.request.GroupedAddressRequest; import cz.muni.fi.lasaris.sbms.data.api.request.TrendsRequest; import cz.muni.fi.lasaris.sbms.data.api.request.AddressRequest; import cz.muni.fi.lasaris.sbms.data.api.response.AggregateResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SetOfSeriesOfValuesResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SeriesOfSlicesResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SetOfAggregatesResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SetOfTrendsResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SliceResponse; import cz.muni.fi.lasaris.sbms.data.api.response.TrendResponse; import cz.muni.fi.lasaris.sbms.data.api.response.ValueResponse; import cz.muni.fi.lasaris.sbms.data.entities.Address; import cz.muni.fi.lasaris.sbms.data.entities.AddressGroup; import cz.muni.fi.lasaris.sbms.data.entities.AggregationFunction; import cz.muni.fi.lasaris.sbms.data.entities.AggregationWindow; import cz.muni.fi.lasaris.sbms.data.entities.Interpolation; import cz.muni.fi.lasaris.sbms.data.entities.SeriesSpecs; import cz.muni.fi.lasaris.sbms.data.entities.containers.Aggregation; import cz.muni.fi.lasaris.sbms.data.entities.containers.Series; import cz.muni.fi.lasaris.sbms.data.entities.containers.Slice; import cz.muni.fi.lasaris.sbms.data.entities.containers.Trend; import cz.muni.fi.lasaris.sbms.data.entities.values.AggregatedValue; import cz.muni.fi.lasaris.sbms.data.entities.values.InterpolatedValue; import cz.muni.fi.lasaris.sbms.data.logic.TrendsDataCollector; public class TrendsEndpoint { Loading @@ -53,50 +60,296 @@ public class TrendsEndpoint { // http://stackoverflow.com/questions/14202257/design-restful-query-api-with-a-long-list-of-query-parameters /* // Methods 4, 6 // Method 4 @RolesAllowed({"user","admin"}) @GET @Path("/serie/{id}") @POST @Path("/si") @Produces(MediaType.APPLICATION_JSON) public SeriesOfValuesResponse getFunc( public TrendResponse getSI( @QueryParam("id") String id, @QueryParam("start") String start, @QueryParam("end") String end ) { try { TrendsRequest r = getReadSpecsSingle(id, start, end, null, null, null, null, null); Trend v = dc.getTrend(r); return new TrendResponse(v); } catch (Exception e) { return TrendResponse.getErrorResponse(e.getMessage()); } } // Method 5 @RolesAllowed({"user","admin"}) @POST @Path("/sts") @Produces(MediaType.APPLICATION_JSON) public ValueResponse getSTS( @QueryParam("id") String id, @QueryParam("timestamp") String timestamp, @QueryParam("sampling.cron") String samplingCron, @QueryParam("sampling.duration") Long samplingDur, @QueryParam("sampling.interpolation") Interpolation interpolation ) { try { TrendsRequest r = getReadSpecsSingle(id, timestamp, timestamp, samplingCron, samplingDur, interpolation, null, null); InterpolatedValue v = dc.getValue(r); return new ValueResponse(v); } catch (Exception e) { return ValueResponse.getErrorResponse(e.getMessage()); } } // Method 6 @RolesAllowed({"user","admin"}) @POST @Path("/sis") @Produces(MediaType.APPLICATION_JSON) public TrendResponse getSIS( @QueryParam("id") String id, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("sampling.cron") String samplingCron, @QueryParam("sampling.duration") Long samplingDur, @QueryParam("sampling.interpolation") Interpolation interpolation, @QueryParam("aggregation.function") String aggregation, @QueryParam("aggregation.window") String window, @QueryParam("sampling.interpolation") Interpolation interpolation ) { Address a = new Address(id); Trend v = ProviderManager.getTrendsProvider(a.getProtocol()).getTrend(a, getSeriesSpecs(start, end, samplingCron, samplingDur, interpolation)); return new SeriesOfValuesResponse(a, v); try { TrendsRequest r = getReadSpecsSingle(id, start, end, samplingCron, samplingDur, interpolation, null, null); Trend v = dc.getTrend(r); return new TrendResponse(v); } catch (Exception e) { return TrendResponse.getErrorResponse(e.getMessage()); } } */ // Method 4 // Method 7 @RolesAllowed({"user","admin"}) @POST @Path("/si") @Path("/sas") @Produces(MediaType.APPLICATION_JSON) public SetOfSeriesOfValuesResponse getSI( public ValueResponse getSAS( @QueryParam("id") String id, @QueryParam("start") String start, @QueryParam("end") String end @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation ) { try { TrendsRequest r = getReadSpecsSingle(id, start, end, null, null, null, aggregation, null); AggregatedValue v = dc.getAggregate(r); return new ValueResponse(v); } catch (Exception e) { return ValueResponse.getErrorResponse(e.getMessage()); } } TrendsRequest r = getReadSpecsSingle(id, start, end, null, null, null, null, null); // Method 8 @RolesAllowed({"user","admin"}) @POST @Path("/siw") @Produces(MediaType.APPLICATION_JSON) public TrendResponse getSIW( @QueryParam("id") String id, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation, @QueryParam("aggregation.window") AggregationWindow window ) { try { TrendsRequest r = getReadSpecsSingle(id, start, end, null, null, null, aggregation, window); Trend v = dc.getTrend(r); return new SetOfSeriesOfValuesResponse(r.getAddress(), v); return new TrendResponse(v); } catch (Exception e) { return TrendResponse.getErrorResponse(e.getMessage()); } } // Method 9 @RolesAllowed({"user","admin"}) @POST @Path("/mt") @Produces(MediaType.APPLICATION_JSON) public SliceResponse getMT( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("timestamp") String timestamp ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, timestamp, timestamp, null, null, null, null, null); Slice v = dc.getSlice(r); return new SliceResponse(v); } catch (Exception e) { return SliceResponse.getErrorResponse(e.getMessage()); } } // Method 10 @RolesAllowed({"user","admin"}) @POST @Path("/mta") @Produces(MediaType.APPLICATION_JSON) public AggregateResponse getMTA( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("timestamp") String timestamp, @QueryParam("aggregation.function") AggregationFunction aggregation ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, timestamp, timestamp, null, null, null, null, null); if(grouping) { Aggregation<AddressGroup> v = dc.getGroupedAggregatesForSlice(r); return new AggregateResponse(v); } else { AggregatedValue v = dc.getAggregateForSlice(r); return new AggregateResponse(v); } } catch (Exception e) { return AggregateResponse.getErrorResponse(e.getMessage()); } } // Method 11 @RolesAllowed({"user","admin"}) @POST @Path("/mi") @Produces(MediaType.APPLICATION_JSON) public SetOfTrendsResponse getMI( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, null, null, null, null, null); if(grouping) { Map<String, Map<Address, Trend>> v = dc.getGroupedTrends(r); return new SetOfTrendsResponse(v, true); } else { Map<Address, Trend> v = dc.getTrends(r); return new SetOfTrendsResponse(v); } } catch (Exception e) { return SetOfTrendsResponse.getErrorResponse(e.getMessage()); } } // Method 12 @RolesAllowed({"user","admin"}) @POST @Path("/mia") @Produces(MediaType.APPLICATION_JSON) public SetOfAggregatesResponse getMIA( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, null, null, null, aggregation, null); if(grouping) { Map<String, Aggregation<Address>> v = dc.getGroupedAggregates(r); return new SetOfAggregatesResponse(v); } else { Aggregation<Address> v = dc.getAggregates(r); return new SetOfAggregatesResponse(v); } } catch (Exception e) { return SetOfAggregatesResponse.getErrorResponse(e.getMessage()); } } // Method 13 @RolesAllowed({"user","admin"}) @POST @Path("/miaa") @Produces(MediaType.APPLICATION_JSON) public AggregateResponse getMIAA( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, null, null, null, aggregation, null); if(grouping) { Aggregation<AddressGroup> v = dc.getGroupedTrendsAggregate(r); return new AggregateResponse(v); } else { AggregatedValue v = dc.getTrendsAggregate(r); return new AggregateResponse(v); } } catch (Exception e) { return AggregateResponse.getErrorResponse(e.getMessage()); } } // Method 14 @RolesAllowed({"user","admin"}) @POST @Path("/misss") @Produces(MediaType.APPLICATION_JSON) public SetOfTrendsResponse getMISSS( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("sampling.cron") String samplingCron, @QueryParam("sampling.duration") Long samplingDur, @QueryParam("sampling.interpolation") Interpolation interpolation ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, samplingCron, samplingDur, interpolation, null, null); if(grouping) { Map<String, Map<Address, Trend>> v = dc.getGroupedTrends(r); return new SetOfTrendsResponse(v, true); } else { Map<Address, Trend> v = dc.getTrends(r); return new SetOfTrendsResponse(v); } } catch (Exception e) { return SetOfTrendsResponse.getErrorResponse(e.getMessage()); } } // Method 15 @RolesAllowed({"user","admin"}) @POST @Path("/missl") @Produces(MediaType.APPLICATION_JSON) public SeriesOfSlicesResponse getMISSL( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("sampling.cron") String samplingCron, @QueryParam("sampling.duration") Long samplingDur, @QueryParam("sampling.interpolation") Interpolation interpolation ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, samplingCron, samplingDur, interpolation, null, null); if(grouping) { Map<String, Series<Slice>> v = dc.getGroupedSeriesOfSlices(r); return new SeriesOfSlicesResponse(v); } else { Series<Slice> v = dc.getSeriesOfSlices(r); return new SeriesOfSlicesResponse(v); } } catch (Exception e) { return SeriesOfSlicesResponse.getErrorResponse(e.getMessage()); } } // Method 16 @RolesAllowed({"user","admin"}) @POST @Path("/mias") @Produces(MediaType.APPLICATION_JSON) public SetOfSeriesOfValuesResponse getMIAS( public TrendResponse getMIAS( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, Loading @@ -108,13 +361,97 @@ public class TrendsEndpoint { ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, samplingCron, samplingDur, interpolation, aggregation, null); Trend v = dc.getTrend(r); return new SetOfSeriesOfValuesResponse(r.getAddress(), v); if(grouping) { Map<String, Trend> v = dc.getGroupedSeriesOfAggregates(r); return new TrendResponse(v); } else { Trend v = dc.getSeriesOfAggregates(r); return new TrendResponse(v); } } catch(Exception e) { return TrendResponse.getErrorResponse(e.getMessage()); } } // Method 17 @RolesAllowed({"user","admin"}) @POST @Path("/miw") @Produces(MediaType.APPLICATION_JSON) public SetOfTrendsResponse getMIW( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation, @QueryParam("aggregation.window") AggregationWindow window ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, null, null, null, aggregation, window); if(grouping) { Map<String, Map<Address, Trend>> v = dc.getGroupedTrends(r); return new SetOfTrendsResponse(v, true); } else { Map<Address, Trend> v = dc.getTrends(r); return new SetOfTrendsResponse(v); } } catch(Exception e) { return SetOfTrendsResponse.getErrorResponse(e.getMessage()); } } // Method 18 @RolesAllowed({"user","admin"}) @POST @Path("/miwa") @Produces(MediaType.APPLICATION_JSON) public TrendResponse getMIWA( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation, @QueryParam("aggregation.window") AggregationWindow window ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, null, null, null, aggregation, window); if(grouping) { Map<String, Trend> v = dc.getGroupedWindowedTrendsAggregate(r); return new TrendResponse(v); } else { Trend v = dc.getWindowedTrendsAggregate(r); return new TrendResponse(v); } } catch(Exception e) { return SetOfSeriesOfValuesResponse.getErrorResponse(e.getMessage()); return TrendResponse.getErrorResponse(e.getMessage()); } } /* TEMPLATE @RolesAllowed({"user","admin"}) @GET @Path("/serie/{id}") @Produces(MediaType.APPLICATION_JSON) public SeriesOfValuesResponse getFunc( @QueryParam("id") String id, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("sampling.cron") String samplingCron, @QueryParam("sampling.duration") Long samplingDur, @QueryParam("sampling.interpolation") Interpolation interpolation, @QueryParam("aggregation.function") AggregationFunction aggregation, @QueryParam("aggregation.window") AggregationWindow window, ) { Address a = new Address(id); Trend v = ProviderManager.getTrendsProvider(a.getProtocol()).getTrend(a, getSeriesSpecs(start, end, samplingCron, samplingDur, interpolation)); return new SeriesOfValuesResponse(a, v); } */ private TrendsRequest getReadSpecsSingle(String id, String start, String end, String samplingCron, Long samplingDur, Interpolation interpolation, AggregationFunction aggregation, AggregationWindow window) { Loading DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/response/SeriesOfSlicesResponse.java +0 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ import java.util.Map; import cz.muni.fi.lasaris.sbms.data.entities.containers.Series; import cz.muni.fi.lasaris.sbms.data.entities.containers.Slice; import cz.muni.fi.lasaris.sbms.data.entities.values.Value; public class SeriesOfSlicesResponse { private static final String DEFAULT_GROUPING = "noGrouping"; Loading DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/response/SetOfAggregatesResponse.java +8 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package cz.muni.fi.lasaris.sbms.data.api.response; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import cz.muni.fi.lasaris.sbms.data.entities.Address; import cz.muni.fi.lasaris.sbms.data.entities.containers.Aggregation; Loading @@ -27,8 +28,13 @@ private static final String DEFAULT_GROUPING = "noGrouping"; this.results = null; } public SetOfAggregatesResponse(Map<String, Map<Address, AggregatedValue>> data) { this.results = data; public SetOfAggregatesResponse(Map<String, Aggregation<Address>> data) { this.results = new LinkedHashMap<String, Map<Address, AggregatedValue>>(); for(Entry<String, Aggregation<Address>> e : data.entrySet()) { Map<Address, AggregatedValue> a = new LinkedHashMap<Address, AggregatedValue>(); e.getValue().forEach((k,v) -> a.put(k, v)); this.results.put(e.getKey(), a); } } public SetOfAggregatesResponse(Address a, AggregatedValue v) { Loading DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/response/SetOfSeriesOfValuesResponse.java→DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/response/SetOfTrendsResponse.java +52 −0 Original line number Diff line number Diff line Loading @@ -4,42 +4,41 @@ import java.util.LinkedHashMap; import java.util.Map; import cz.muni.fi.lasaris.sbms.data.entities.Address; import cz.muni.fi.lasaris.sbms.data.entities.containers.Series; import cz.muni.fi.lasaris.sbms.data.entities.values.Value; import cz.muni.fi.lasaris.sbms.data.entities.containers.Trend; public class SetOfSeriesOfValuesResponse { public class SetOfTrendsResponse { private static final String DEFAULT_GROUPING = "noGrouping"; private String error; private Map<String, Map<Address, Series<? extends Value>>> results; private Map<String, Map<Address, Trend>> results; public Map<String, Map<Address, Series<? extends Value>>> getResults() { public Map<String, Map<Address, Trend>> getResults() { return this.results; } public static SetOfSeriesOfValuesResponse getErrorResponse(String error) { SetOfSeriesOfValuesResponse r = new SetOfSeriesOfValuesResponse(); public static SetOfTrendsResponse getErrorResponse(String error) { SetOfTrendsResponse r = new SetOfTrendsResponse(); r.setError(error); return r; } private SetOfSeriesOfValuesResponse() { private SetOfTrendsResponse() { this.results = null; } public SetOfSeriesOfValuesResponse(Map<String, Map<Address, Series<? extends Value>>> data, boolean groups) { public SetOfTrendsResponse(Map<String, Map<Address, Trend>> data, boolean groups) { this.results = data; } public SetOfSeriesOfValuesResponse(Map<Address, Series<? extends Value>> data) { this.results = new LinkedHashMap<String, Map<Address, Series<? extends Value>>>(); public SetOfTrendsResponse(Map<Address, Trend> data) { this.results = new LinkedHashMap<String, Map<Address, Trend>>(); this.results.put(DEFAULT_GROUPING, data); } public SetOfSeriesOfValuesResponse(Address a, Series<? extends Value> v) { this(new LinkedHashMap<String, Map<Address, Series<? extends Value>>>(), true); this.results.put(DEFAULT_GROUPING, new LinkedHashMap<Address, Series<? extends Value>>()); public SetOfTrendsResponse(Address a, Trend v) { this(new LinkedHashMap<String, Map<Address, Trend>>(), true); this.results.put(DEFAULT_GROUPING, new LinkedHashMap<Address, Trend>()); this.results.get(DEFAULT_GROUPING).put(a, v); } Loading Loading
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/DataPointsEndpoint.java +3 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import cz.muni.fi.lasaris.sbms.data.api.request.GroupedAddressRequest; import cz.muni.fi.lasaris.sbms.data.api.request.AddressRequest; import cz.muni.fi.lasaris.sbms.data.api.response.AggregateResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SnapshotResponse; import cz.muni.fi.lasaris.sbms.data.api.response.ValueResponse; import cz.muni.fi.lasaris.sbms.data.entities.Address; import cz.muni.fi.lasaris.sbms.data.entities.AggregationFunction; import cz.muni.fi.lasaris.sbms.data.entities.values.RawValue; Loading Loading @@ -131,12 +132,12 @@ public class DataPointsEndpoint { @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) public SnapshotResponse getDataPoint( public ValueResponse getDataPoint( @PathParam("id") String idP, @QueryParam("cache") String cache) { Address a = new Address(idP); RawValue v = ProviderManager.getDataPointsProvider(a.getProtocol()).getDataPointValue(a, allowCache(cache)); return new SnapshotResponse(a, v); return new ValueResponse(v); } private boolean allowCache(String cache) { Loading
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/TrendsEndpoint.java +395 −58 Original line number Diff line number Diff line Loading @@ -4,14 +4,11 @@ import java.io.IOException; import java.time.Duration; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalUnit; import java.util.Arrays; import java.util.Map; import javax.annotation.security.RolesAllowed; import javax.ws.rs.DefaultValue; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; Loading @@ -27,14 +24,24 @@ import cz.muni.fi.lasaris.sbms.data.api.request.GroupedAddressRequest; import cz.muni.fi.lasaris.sbms.data.api.request.TrendsRequest; import cz.muni.fi.lasaris.sbms.data.api.request.AddressRequest; import cz.muni.fi.lasaris.sbms.data.api.response.AggregateResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SetOfSeriesOfValuesResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SeriesOfSlicesResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SetOfAggregatesResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SetOfTrendsResponse; import cz.muni.fi.lasaris.sbms.data.api.response.SliceResponse; import cz.muni.fi.lasaris.sbms.data.api.response.TrendResponse; import cz.muni.fi.lasaris.sbms.data.api.response.ValueResponse; import cz.muni.fi.lasaris.sbms.data.entities.Address; import cz.muni.fi.lasaris.sbms.data.entities.AddressGroup; import cz.muni.fi.lasaris.sbms.data.entities.AggregationFunction; import cz.muni.fi.lasaris.sbms.data.entities.AggregationWindow; import cz.muni.fi.lasaris.sbms.data.entities.Interpolation; import cz.muni.fi.lasaris.sbms.data.entities.SeriesSpecs; import cz.muni.fi.lasaris.sbms.data.entities.containers.Aggregation; import cz.muni.fi.lasaris.sbms.data.entities.containers.Series; import cz.muni.fi.lasaris.sbms.data.entities.containers.Slice; import cz.muni.fi.lasaris.sbms.data.entities.containers.Trend; import cz.muni.fi.lasaris.sbms.data.entities.values.AggregatedValue; import cz.muni.fi.lasaris.sbms.data.entities.values.InterpolatedValue; import cz.muni.fi.lasaris.sbms.data.logic.TrendsDataCollector; public class TrendsEndpoint { Loading @@ -53,50 +60,296 @@ public class TrendsEndpoint { // http://stackoverflow.com/questions/14202257/design-restful-query-api-with-a-long-list-of-query-parameters /* // Methods 4, 6 // Method 4 @RolesAllowed({"user","admin"}) @GET @Path("/serie/{id}") @POST @Path("/si") @Produces(MediaType.APPLICATION_JSON) public SeriesOfValuesResponse getFunc( public TrendResponse getSI( @QueryParam("id") String id, @QueryParam("start") String start, @QueryParam("end") String end ) { try { TrendsRequest r = getReadSpecsSingle(id, start, end, null, null, null, null, null); Trend v = dc.getTrend(r); return new TrendResponse(v); } catch (Exception e) { return TrendResponse.getErrorResponse(e.getMessage()); } } // Method 5 @RolesAllowed({"user","admin"}) @POST @Path("/sts") @Produces(MediaType.APPLICATION_JSON) public ValueResponse getSTS( @QueryParam("id") String id, @QueryParam("timestamp") String timestamp, @QueryParam("sampling.cron") String samplingCron, @QueryParam("sampling.duration") Long samplingDur, @QueryParam("sampling.interpolation") Interpolation interpolation ) { try { TrendsRequest r = getReadSpecsSingle(id, timestamp, timestamp, samplingCron, samplingDur, interpolation, null, null); InterpolatedValue v = dc.getValue(r); return new ValueResponse(v); } catch (Exception e) { return ValueResponse.getErrorResponse(e.getMessage()); } } // Method 6 @RolesAllowed({"user","admin"}) @POST @Path("/sis") @Produces(MediaType.APPLICATION_JSON) public TrendResponse getSIS( @QueryParam("id") String id, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("sampling.cron") String samplingCron, @QueryParam("sampling.duration") Long samplingDur, @QueryParam("sampling.interpolation") Interpolation interpolation, @QueryParam("aggregation.function") String aggregation, @QueryParam("aggregation.window") String window, @QueryParam("sampling.interpolation") Interpolation interpolation ) { Address a = new Address(id); Trend v = ProviderManager.getTrendsProvider(a.getProtocol()).getTrend(a, getSeriesSpecs(start, end, samplingCron, samplingDur, interpolation)); return new SeriesOfValuesResponse(a, v); try { TrendsRequest r = getReadSpecsSingle(id, start, end, samplingCron, samplingDur, interpolation, null, null); Trend v = dc.getTrend(r); return new TrendResponse(v); } catch (Exception e) { return TrendResponse.getErrorResponse(e.getMessage()); } } */ // Method 4 // Method 7 @RolesAllowed({"user","admin"}) @POST @Path("/si") @Path("/sas") @Produces(MediaType.APPLICATION_JSON) public SetOfSeriesOfValuesResponse getSI( public ValueResponse getSAS( @QueryParam("id") String id, @QueryParam("start") String start, @QueryParam("end") String end @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation ) { try { TrendsRequest r = getReadSpecsSingle(id, start, end, null, null, null, aggregation, null); AggregatedValue v = dc.getAggregate(r); return new ValueResponse(v); } catch (Exception e) { return ValueResponse.getErrorResponse(e.getMessage()); } } TrendsRequest r = getReadSpecsSingle(id, start, end, null, null, null, null, null); // Method 8 @RolesAllowed({"user","admin"}) @POST @Path("/siw") @Produces(MediaType.APPLICATION_JSON) public TrendResponse getSIW( @QueryParam("id") String id, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation, @QueryParam("aggregation.window") AggregationWindow window ) { try { TrendsRequest r = getReadSpecsSingle(id, start, end, null, null, null, aggregation, window); Trend v = dc.getTrend(r); return new SetOfSeriesOfValuesResponse(r.getAddress(), v); return new TrendResponse(v); } catch (Exception e) { return TrendResponse.getErrorResponse(e.getMessage()); } } // Method 9 @RolesAllowed({"user","admin"}) @POST @Path("/mt") @Produces(MediaType.APPLICATION_JSON) public SliceResponse getMT( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("timestamp") String timestamp ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, timestamp, timestamp, null, null, null, null, null); Slice v = dc.getSlice(r); return new SliceResponse(v); } catch (Exception e) { return SliceResponse.getErrorResponse(e.getMessage()); } } // Method 10 @RolesAllowed({"user","admin"}) @POST @Path("/mta") @Produces(MediaType.APPLICATION_JSON) public AggregateResponse getMTA( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("timestamp") String timestamp, @QueryParam("aggregation.function") AggregationFunction aggregation ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, timestamp, timestamp, null, null, null, null, null); if(grouping) { Aggregation<AddressGroup> v = dc.getGroupedAggregatesForSlice(r); return new AggregateResponse(v); } else { AggregatedValue v = dc.getAggregateForSlice(r); return new AggregateResponse(v); } } catch (Exception e) { return AggregateResponse.getErrorResponse(e.getMessage()); } } // Method 11 @RolesAllowed({"user","admin"}) @POST @Path("/mi") @Produces(MediaType.APPLICATION_JSON) public SetOfTrendsResponse getMI( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, null, null, null, null, null); if(grouping) { Map<String, Map<Address, Trend>> v = dc.getGroupedTrends(r); return new SetOfTrendsResponse(v, true); } else { Map<Address, Trend> v = dc.getTrends(r); return new SetOfTrendsResponse(v); } } catch (Exception e) { return SetOfTrendsResponse.getErrorResponse(e.getMessage()); } } // Method 12 @RolesAllowed({"user","admin"}) @POST @Path("/mia") @Produces(MediaType.APPLICATION_JSON) public SetOfAggregatesResponse getMIA( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, null, null, null, aggregation, null); if(grouping) { Map<String, Aggregation<Address>> v = dc.getGroupedAggregates(r); return new SetOfAggregatesResponse(v); } else { Aggregation<Address> v = dc.getAggregates(r); return new SetOfAggregatesResponse(v); } } catch (Exception e) { return SetOfAggregatesResponse.getErrorResponse(e.getMessage()); } } // Method 13 @RolesAllowed({"user","admin"}) @POST @Path("/miaa") @Produces(MediaType.APPLICATION_JSON) public AggregateResponse getMIAA( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, null, null, null, aggregation, null); if(grouping) { Aggregation<AddressGroup> v = dc.getGroupedTrendsAggregate(r); return new AggregateResponse(v); } else { AggregatedValue v = dc.getTrendsAggregate(r); return new AggregateResponse(v); } } catch (Exception e) { return AggregateResponse.getErrorResponse(e.getMessage()); } } // Method 14 @RolesAllowed({"user","admin"}) @POST @Path("/misss") @Produces(MediaType.APPLICATION_JSON) public SetOfTrendsResponse getMISSS( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("sampling.cron") String samplingCron, @QueryParam("sampling.duration") Long samplingDur, @QueryParam("sampling.interpolation") Interpolation interpolation ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, samplingCron, samplingDur, interpolation, null, null); if(grouping) { Map<String, Map<Address, Trend>> v = dc.getGroupedTrends(r); return new SetOfTrendsResponse(v, true); } else { Map<Address, Trend> v = dc.getTrends(r); return new SetOfTrendsResponse(v); } } catch (Exception e) { return SetOfTrendsResponse.getErrorResponse(e.getMessage()); } } // Method 15 @RolesAllowed({"user","admin"}) @POST @Path("/missl") @Produces(MediaType.APPLICATION_JSON) public SeriesOfSlicesResponse getMISSL( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("sampling.cron") String samplingCron, @QueryParam("sampling.duration") Long samplingDur, @QueryParam("sampling.interpolation") Interpolation interpolation ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, samplingCron, samplingDur, interpolation, null, null); if(grouping) { Map<String, Series<Slice>> v = dc.getGroupedSeriesOfSlices(r); return new SeriesOfSlicesResponse(v); } else { Series<Slice> v = dc.getSeriesOfSlices(r); return new SeriesOfSlicesResponse(v); } } catch (Exception e) { return SeriesOfSlicesResponse.getErrorResponse(e.getMessage()); } } // Method 16 @RolesAllowed({"user","admin"}) @POST @Path("/mias") @Produces(MediaType.APPLICATION_JSON) public SetOfSeriesOfValuesResponse getMIAS( public TrendResponse getMIAS( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, Loading @@ -108,13 +361,97 @@ public class TrendsEndpoint { ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, samplingCron, samplingDur, interpolation, aggregation, null); Trend v = dc.getTrend(r); return new SetOfSeriesOfValuesResponse(r.getAddress(), v); if(grouping) { Map<String, Trend> v = dc.getGroupedSeriesOfAggregates(r); return new TrendResponse(v); } else { Trend v = dc.getSeriesOfAggregates(r); return new TrendResponse(v); } } catch(Exception e) { return TrendResponse.getErrorResponse(e.getMessage()); } } // Method 17 @RolesAllowed({"user","admin"}) @POST @Path("/miw") @Produces(MediaType.APPLICATION_JSON) public SetOfTrendsResponse getMIW( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation, @QueryParam("aggregation.window") AggregationWindow window ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, null, null, null, aggregation, window); if(grouping) { Map<String, Map<Address, Trend>> v = dc.getGroupedTrends(r); return new SetOfTrendsResponse(v, true); } else { Map<Address, Trend> v = dc.getTrends(r); return new SetOfTrendsResponse(v); } } catch(Exception e) { return SetOfTrendsResponse.getErrorResponse(e.getMessage()); } } // Method 18 @RolesAllowed({"user","admin"}) @POST @Path("/miwa") @Produces(MediaType.APPLICATION_JSON) public TrendResponse getMIWA( @QueryParam("ids") String ids, @QueryParam("grouping") boolean grouping, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("aggregation.function") AggregationFunction aggregation, @QueryParam("aggregation.window") AggregationWindow window ) { try { TrendsRequest r = getReadSpecsMulti(ids, grouping, start, end, null, null, null, aggregation, window); if(grouping) { Map<String, Trend> v = dc.getGroupedWindowedTrendsAggregate(r); return new TrendResponse(v); } else { Trend v = dc.getWindowedTrendsAggregate(r); return new TrendResponse(v); } } catch(Exception e) { return SetOfSeriesOfValuesResponse.getErrorResponse(e.getMessage()); return TrendResponse.getErrorResponse(e.getMessage()); } } /* TEMPLATE @RolesAllowed({"user","admin"}) @GET @Path("/serie/{id}") @Produces(MediaType.APPLICATION_JSON) public SeriesOfValuesResponse getFunc( @QueryParam("id") String id, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("sampling.cron") String samplingCron, @QueryParam("sampling.duration") Long samplingDur, @QueryParam("sampling.interpolation") Interpolation interpolation, @QueryParam("aggregation.function") AggregationFunction aggregation, @QueryParam("aggregation.window") AggregationWindow window, ) { Address a = new Address(id); Trend v = ProviderManager.getTrendsProvider(a.getProtocol()).getTrend(a, getSeriesSpecs(start, end, samplingCron, samplingDur, interpolation)); return new SeriesOfValuesResponse(a, v); } */ private TrendsRequest getReadSpecsSingle(String id, String start, String end, String samplingCron, Long samplingDur, Interpolation interpolation, AggregationFunction aggregation, AggregationWindow window) { Loading
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/response/SeriesOfSlicesResponse.java +0 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ import java.util.Map; import cz.muni.fi.lasaris.sbms.data.entities.containers.Series; import cz.muni.fi.lasaris.sbms.data.entities.containers.Slice; import cz.muni.fi.lasaris.sbms.data.entities.values.Value; public class SeriesOfSlicesResponse { private static final String DEFAULT_GROUPING = "noGrouping"; Loading
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/response/SetOfAggregatesResponse.java +8 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package cz.muni.fi.lasaris.sbms.data.api.response; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import cz.muni.fi.lasaris.sbms.data.entities.Address; import cz.muni.fi.lasaris.sbms.data.entities.containers.Aggregation; Loading @@ -27,8 +28,13 @@ private static final String DEFAULT_GROUPING = "noGrouping"; this.results = null; } public SetOfAggregatesResponse(Map<String, Map<Address, AggregatedValue>> data) { this.results = data; public SetOfAggregatesResponse(Map<String, Aggregation<Address>> data) { this.results = new LinkedHashMap<String, Map<Address, AggregatedValue>>(); for(Entry<String, Aggregation<Address>> e : data.entrySet()) { Map<Address, AggregatedValue> a = new LinkedHashMap<Address, AggregatedValue>(); e.getValue().forEach((k,v) -> a.put(k, v)); this.results.put(e.getKey(), a); } } public SetOfAggregatesResponse(Address a, AggregatedValue v) { Loading
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/response/SetOfSeriesOfValuesResponse.java→DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/response/SetOfTrendsResponse.java +52 −0 Original line number Diff line number Diff line Loading @@ -4,42 +4,41 @@ import java.util.LinkedHashMap; import java.util.Map; import cz.muni.fi.lasaris.sbms.data.entities.Address; import cz.muni.fi.lasaris.sbms.data.entities.containers.Series; import cz.muni.fi.lasaris.sbms.data.entities.values.Value; import cz.muni.fi.lasaris.sbms.data.entities.containers.Trend; public class SetOfSeriesOfValuesResponse { public class SetOfTrendsResponse { private static final String DEFAULT_GROUPING = "noGrouping"; private String error; private Map<String, Map<Address, Series<? extends Value>>> results; private Map<String, Map<Address, Trend>> results; public Map<String, Map<Address, Series<? extends Value>>> getResults() { public Map<String, Map<Address, Trend>> getResults() { return this.results; } public static SetOfSeriesOfValuesResponse getErrorResponse(String error) { SetOfSeriesOfValuesResponse r = new SetOfSeriesOfValuesResponse(); public static SetOfTrendsResponse getErrorResponse(String error) { SetOfTrendsResponse r = new SetOfTrendsResponse(); r.setError(error); return r; } private SetOfSeriesOfValuesResponse() { private SetOfTrendsResponse() { this.results = null; } public SetOfSeriesOfValuesResponse(Map<String, Map<Address, Series<? extends Value>>> data, boolean groups) { public SetOfTrendsResponse(Map<String, Map<Address, Trend>> data, boolean groups) { this.results = data; } public SetOfSeriesOfValuesResponse(Map<Address, Series<? extends Value>> data) { this.results = new LinkedHashMap<String, Map<Address, Series<? extends Value>>>(); public SetOfTrendsResponse(Map<Address, Trend> data) { this.results = new LinkedHashMap<String, Map<Address, Trend>>(); this.results.put(DEFAULT_GROUPING, data); } public SetOfSeriesOfValuesResponse(Address a, Series<? extends Value> v) { this(new LinkedHashMap<String, Map<Address, Series<? extends Value>>>(), true); this.results.put(DEFAULT_GROUPING, new LinkedHashMap<Address, Series<? extends Value>>()); public SetOfTrendsResponse(Address a, Trend v) { this(new LinkedHashMap<String, Map<Address, Trend>>(), true); this.results.put(DEFAULT_GROUPING, new LinkedHashMap<Address, Trend>()); this.results.get(DEFAULT_GROUPING).put(a, v); } Loading