Commit 61b50af3 by Adi Amir

inject viewDir from cameraList + add api for cameraGroup

parent 1cbca8c0
Showing with 64 additions and 0 deletions
......@@ -66,6 +66,9 @@ public class GEManager {
else if (apiIdAsParams.length == 3 && apiIdAsParams[0].equals("camera") && apiIdAsParams[2].equals("latestImage")) {
brr = getLatestMediaFile(apiIdAsParams[1] /*camId*/, "IMAGE", requestContext);
}
else if (apiIdAsParams.length == 3 && apiIdAsParams[0].equals("camera") && apiIdAsParams[2].equals("details")) {
brr = getCameraDetails(apiIdAsParams[1] /*camId*/, requestContext);
}
else {
String err = "executeRequest() failed. Unknown api: " + getApiIdString(apiIdAsParams);
return errorResponse(err);
......@@ -227,6 +230,67 @@ public class GEManager {
return brr;
}
private BaseRestResponse getCameraDetails(String cameraId, RequestContext requestContext) {
SimpleHttpRequest req = null;
SimpleHttpResponse httpResp = null;
BaseRestResponse brr = new BaseRestResponse(false,null);
logger.info("getCameraDetails() activated. camId=" + cameraId);
// execute the request ...
req = buildCameraDetailsHttpRequest(cameraId);
try {
httpResp = httpClient.processRequest(req);
if(httpResp.getStatusCode() == 200)
brr = buildCameraDetailsResp(httpResp);
else {
logHttpError("getCameraDetails", httpResp);
return errorHttpResponse(httpResp);
}
} catch (Exception e) {
String err = "getCameraDetails() failed with exception. e=" + e.toString();
logger.error(err);
return errorResponse(err);
}
logger.info("getCameraDetails() successfull. camId=" + cameraId);
return brr;
}
private SimpleHttpRequest buildCameraDetailsHttpRequest(String camId) {
SimpleHttpRequest request = new SimpleHttpRequest();
request.setProtocol("https");
request.setDomain(METADATA_URL);
request.setPort(443);
request.setMethod(SimpleHttpRequest.Method.GET);
String path = ASSETS_URL + "/" + camId;
request.setPath(path);
request.addHeader("Authorization", "Bearer " + TOKEN);
request.addHeader("Predix-Zone-Id", PARKING_ZONE_ID);
return request;
}
private BaseRestResponse buildCameraDetailsResp(SimpleHttpResponse resp) {
BaseRestResponse brr = new BaseRestResponse(true,null);
int size;
String content = resp.getContent();
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode contentObj = mapper.readTree(content);
String view = contentObj.at("/properties/VIEW").asText();
ObjectNode objectNode = mapper.createObjectNode();
objectNode.put("view", view);
brr.objectNode = objectNode;
} catch (IOException e) {
return new BaseRestResponse(false, e.toString());
}
return brr;
}
private boolean getNewAccessToken() {
SimpleHttpRequest req = null;
SimpleHttpResponse httpResp = null;
......
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