Commit f25d9f84 by Adi Amir

change details api name to latestEvent

parent b18d9b3e
Showing with 11 additions and 13 deletions
...@@ -22,14 +22,12 @@ import org.apache.http.conn.scheme.SchemeRegistry; ...@@ -22,14 +22,12 @@ import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import web.App;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.util.Deque; import java.util.Deque;
import java.util.Map; import java.util.Map;
...@@ -96,8 +94,8 @@ public class GEManager { ...@@ -96,8 +94,8 @@ public class GEManager {
else if (apiIdAsParams.length == 1 && apiIdAsParams[0].equals("sensors")) { else if (apiIdAsParams.length == 1 && apiIdAsParams[0].equals("sensors")) {
brr = getSensorList(requestContext); brr = getSensorList(requestContext);
} }
else if (apiIdAsParams.length == 3 && apiIdAsParams[0].equals("sensor") && apiIdAsParams[2].equals("details")) { else if (apiIdAsParams.length == 3 && apiIdAsParams[0].equals("sensor") && apiIdAsParams[2].equals("latestEvent")) {
brr = getSensorDetails(apiIdAsParams[1]/*sensorId*/, requestContext); brr = getSensorLatestEvent(apiIdAsParams[1]/*sensorId*/, requestContext);
} }
else { else {
String err = "executeRequest() failed. Unknown api: " + getApiIdString(apiIdAsParams); String err = "executeRequest() failed. Unknown api: " + getApiIdString(apiIdAsParams);
...@@ -232,12 +230,12 @@ public class GEManager { ...@@ -232,12 +230,12 @@ public class GEManager {
logger.info("getCameraDetails() successfull. camId=" + cameraId); logger.info("getCameraDetails() successfull. camId=" + cameraId);
return brr; return brr;
} }
private BaseRestResponse getSensorDetails(String sensorId, RequestContext requestContext) { private BaseRestResponse getSensorLatestEvent(String sensorId, RequestContext requestContext) {
SimpleHttpRequest req = null; SimpleHttpRequest req = null;
SimpleHttpResponse httpResp = null; SimpleHttpResponse httpResp = null;
BaseRestResponse brr = new BaseRestResponse(false,null); BaseRestResponse brr = new BaseRestResponse(false,null);
logger.info("getSensorDetails() activated. camId=" + sensorId); logger.info("getSensorLatestEvent() activated. camId=" + sensorId);
// execute the request ... // execute the request ...
// envType // envType
...@@ -255,27 +253,27 @@ public class GEManager { ...@@ -255,27 +253,27 @@ public class GEManager {
return errorResponse("missing mandatory parameter: startTime"); return errorResponse("missing mandatory parameter: startTime");
Long tsStartTime = Long.parseLong(startTime); Long tsStartTime = Long.parseLong(startTime);
req = buildSensorDetailsRequest(sensorId, envType, tsStartTime, tsEndTime); req = buildSensorLatestEventRequest(sensorId, envType, tsStartTime, tsEndTime);
try { try {
httpResp = httpClient.processRequest(req); httpResp = httpClient.processRequest(req);
if(httpResp.getStatusCode() == 200) if(httpResp.getStatusCode() == 200)
brr = buildSensorDetailsResp(httpResp); brr = buildSensorLatestEventResp(httpResp);
else { else {
logHttpError("getSensorDetails", httpResp); logHttpError("getSensorLatestEvent", httpResp);
return errorHttpResponse(httpResp); return errorHttpResponse(httpResp);
} }
} catch (Exception e) { } catch (Exception e) {
String err = "getSensorDetails() failed with exception. e=" + e.toString(); String err = "getSensorLatestEvent() failed with exception. e=" + e.toString();
logger.error(err); logger.error(err);
return errorResponse(err); return errorResponse(err);
} }
logger.info("getSensorDetails() successfull. camId=" + sensorId); logger.info("getSensorLatestEvent() successfull. camId=" + sensorId);
return brr; return brr;
} }
private SimpleHttpRequest buildSensorDetailsRequest(String sensdorId, String envType, Long tsStartTime, Long tsEndTime) { private SimpleHttpRequest buildSensorLatestEventRequest(String sensdorId, String envType, Long tsStartTime, Long tsEndTime) {
SimpleHttpRequest request = new SimpleHttpRequest(); SimpleHttpRequest request = new SimpleHttpRequest();
request.setProtocol("https"); request.setProtocol("https");
request.setDomain(EVENT_URL); request.setDomain(EVENT_URL);
...@@ -296,7 +294,7 @@ public class GEManager { ...@@ -296,7 +294,7 @@ public class GEManager {
return request; return request;
} }
private BaseRestResponse buildSensorDetailsResp(SimpleHttpResponse resp) { private BaseRestResponse buildSensorLatestEventResp(SimpleHttpResponse resp) {
BaseRestResponse brr = new BaseRestResponse(true,null); BaseRestResponse brr = new BaseRestResponse(true,null);
int size; int size;
String content = resp.getContent(); String content = resp.getContent();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment