Commit 94a210b9 authored by akucera's avatar akucera
Browse files

commit just to move unfinished work to repository before the weekend

comes
parent 64b5b140
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
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.AggregationResponse;
import cz.muni.fi.lasaris.sbms.data.api.response.GroupedSnapshotResponse;
import cz.muni.fi.lasaris.sbms.data.api.response.SnapshotResponse;
import cz.muni.fi.lasaris.sbms.data.entities.Address;
import cz.muni.fi.lasaris.sbms.data.entities.AggregationFunction;
@@ -28,7 +27,7 @@ import cz.muni.fi.lasaris.sbms.data.entities.values.RawValue;
import cz.muni.fi.lasaris.sbms.data.logic.ProviderManager;
import cz.muni.fi.lasaris.sbms.data.logic.DataCollector;


//TODO http://stackoverflow.com/questions/14202257/design-restful-query-api-with-a-long-list-of-query-parameters

@Path("datapoints")
@PermitAll
@@ -89,7 +88,7 @@ public class DataPointsEndpoint {
	@GET
	@Path("/grouped")
	@Produces(MediaType.APPLICATION_JSON)
	public GroupedSnapshotResponse getGroupedDataPoints(
	public SnapshotResponse getGroupedDataPoints(
			@QueryParam("ids") String json,
			@QueryParam("cache") String cache
			) {
@@ -101,7 +100,7 @@ public class DataPointsEndpoint {
			logger.debug(readSpecs);
			return dc.getDataPointGroupedValues(readSpecs, allowCache(cache));
		} catch (IOException e) {
			return GroupedSnapshotResponse.getErrorResponse("Unable to parse query:" + e);
			return SnapshotResponse.getErrorResponse("Unable to parse query:" + e);
		}
	}
	
+5 −3
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
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.AggregationResponse;
import cz.muni.fi.lasaris.sbms.data.api.response.GroupedSnapshotResponse;
import cz.muni.fi.lasaris.sbms.data.api.response.SnapshotResponse;
import cz.muni.fi.lasaris.sbms.data.api.response.SnapshotResponse;
import cz.muni.fi.lasaris.sbms.data.entities.Address;
import cz.muni.fi.lasaris.sbms.data.entities.AggregationFunction;
@@ -50,6 +50,8 @@ public class TrendsEndpoint {
		m.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	}
	
	// TODO http://stackoverflow.com/questions/14202257/design-restful-query-api-with-a-long-list-of-query-parameters
	
	@RolesAllowed({"user","admin"})
	@GET
	@Produces(MediaType.APPLICATION_JSON)
@@ -102,7 +104,7 @@ public class TrendsEndpoint {
	@GET
	@Path("/grouped")
	@Produces(MediaType.APPLICATION_JSON)
	public GroupedSnapshotResponse getGroupedDataPoints(
	public SnapshotResponse getGroupedDataPoints(
			@QueryParam("json") String json
			) {
		ObjectMapper m = new ObjectMapper();
@@ -113,7 +115,7 @@ public class TrendsEndpoint {
			logger.debug(readSpecs);
			return dc.getDataPointGroupedValues(readSpecs);
		} catch (IOException e) {
			return GroupedSnapshotResponse.getErrorResponse("Unable to parse query:" + e);
			return SnapshotResponse.getErrorResponse("Unable to parse query:" + e);
		}
	}
	
+0 −36
Original line number Diff line number Diff line
package cz.muni.fi.lasaris.sbms.data.api.response;

import java.util.Map;

import cz.muni.fi.lasaris.sbms.data.entities.containers.Snapshot;

public class GroupedSnapshotResponse {
	private String error;
	private Map<String, Snapshot> results;
	
	public Map<String, Snapshot> getResults() {
		return this.results;
	}
	
	public static GroupedSnapshotResponse getErrorResponse(String error) {
		GroupedSnapshotResponse r = new GroupedSnapshotResponse();
		r.setError(error);
		return r;
	}
	
	private GroupedSnapshotResponse() {
		this.results = null;
	}
	
	public GroupedSnapshotResponse(Map<String, Snapshot> data) {
		this.results = data;
	}
	
	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}
}
+18 −16
Original line number Diff line number Diff line
package cz.muni.fi.lasaris.sbms.data.api.response;

import java.util.LinkedHashMap;
import java.util.Map;

import javax.xml.bind.annotation.XmlRootElement;

import com.fasterxml.jackson.annotation.JsonInclude;

import cz.muni.fi.lasaris.sbms.data.entities.Address;
import cz.muni.fi.lasaris.sbms.data.entities.containers.Snapshot;
import cz.muni.fi.lasaris.sbms.data.entities.values.RawValue;

@XmlRootElement
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SnapshotResponse {
	private String error;
	private Snapshot results;
	
	public Map<Address, RawValue> getResults() {
		if(this.results == null) return null;
	private static final String DEFAULT_GROUPING = "noGrouping";
	
	private String error;
	private Map<String, Snapshot> results;
	
		return this.results.getData();
	public Map<String, Snapshot> getResults() {
		return this.results;
	}
	
	public static SnapshotResponse getErrorResponse(String error) {
@@ -32,13 +28,19 @@ public class SnapshotResponse {
		this.results = null;
	}
	
	public SnapshotResponse(Address a, RawValue v) {
		this.results = new Snapshot();
		this.results.add(a, v);
	public SnapshotResponse(Map<String, Snapshot> data) {
		this.results = data;
	}
	
	public SnapshotResponse(Snapshot data) {
		this.results = new LinkedHashMap<String, Snapshot>();
		this.results.put(DEFAULT_GROUPING, data);
	}
	
	public SnapshotResponse(Snapshot s) {
		this.results = s;
	public SnapshotResponse(Address a, RawValue v) {
		this(new Snapshot());
		this.results.get(DEFAULT_GROUPING).add(a, v);
		
	}
	
	public String getError() {
+5 −6
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@ import org.apache.log4j.Logger;
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.AggregationResponse;
import cz.muni.fi.lasaris.sbms.data.api.response.GroupedSnapshotResponse;
import cz.muni.fi.lasaris.sbms.data.api.response.SnapshotResponse;
import cz.muni.fi.lasaris.sbms.data.entities.Address;
import cz.muni.fi.lasaris.sbms.data.entities.AggregationFunction;
@@ -97,9 +96,9 @@ NavigableMap<String, AddressRequest> protocols = readSpecs.getProtocols();
		
	}
	
	public GroupedSnapshotResponse getDataPointGroupedValues(GroupedAddressRequest readSpecs,
	public SnapshotResponse getDataPointGroupedValues(GroupedAddressRequest readSpecs,
			boolean allowCache) {
		return new GroupedSnapshotResponse(getDataPointGroupedValuesMap(readSpecs, allowCache));
		return new SnapshotResponse(getDataPointGroupedValuesMap(readSpecs, allowCache));
	}
	
	private Map<String, Snapshot> getDataPointGroupedValuesMap(GroupedAddressRequest readSpecs,
@@ -114,13 +113,13 @@ NavigableMap<String, AddressRequest> protocols = readSpecs.getProtocols();
		AtomicInteger counter = new AtomicInteger(0);
		int count = protocols.keySet().size();
		
		List<GroupedSnapshotResponse> results = Collections.synchronizedList(new LinkedList<GroupedSnapshotResponse>());
		List<SnapshotResponse> results = Collections.synchronizedList(new LinkedList<SnapshotResponse>());
		
		for(String protocol : protocols.keySet()) {
			new Thread(new Runnable() {
				@Override
				public void run() {
					GroupedSnapshotResponse rs = new GroupedSnapshotResponse(ProviderManager.getDataPointsProvider(protocol).getDataPointGroupedValues(protocols.get(protocol).getGroups(), allowCache)); 
					SnapshotResponse rs = new SnapshotResponse(ProviderManager.getDataPointsProvider(protocol).getDataPointGroupedValues(protocols.get(protocol).getGroups(), allowCache)); 
					synchronized(results) {
						results.add(rs);
						counter.incrementAndGet();
@@ -146,7 +145,7 @@ NavigableMap<String, AddressRequest> protocols = readSpecs.getProtocols();
		}
		
		synchronized(results) {
			for(GroupedSnapshotResponse r : results) {
			for(SnapshotResponse r : results) {
				for(String group : r.getResults().keySet()) {
					result.get(group).addAll(r.getResults().get(group).getData());
				}