Commit 320b8ba5 by Gil Sade

added ge cameras

parent 652e9394
Showing with 101 additions and 7 deletions
package logic;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import http.simpleHttpClient.SimpleHttpClient;
import http.simpleHttpClient.SimpleHttpRequest;
import http.simpleHttpClient.SimpleHttpResponse;
import logic.adapter.BaseAdapter;
import logic.adapter.HttpAdapter.HttpAdapter;
import logic.adapter.HttpAdapter.RequestParams;
import logic.service.model.Action;
import logic.service.model.Api;
import microservice.RequestContext;
import microservice.io.iface.ILogger;
import microservice.types.BaseRestResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Map;
/**
* Created by adi on 01/03/17.
* Created by gil on 01/03/17.
*/
public class GEManager {
public static String baseUrl = "ie-cities-metadata.run.asv-pr-pub.ice.predix.io";
public static String assetListUrl = "v2/assets/search";
public static String token = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImxlZ2FjeS10b2tlbi1rZXkiLCJ0eXAiOiJKV1QifQ.eyJqdGkiOiJlOTc5MTUyNjE5MjE0NDBhOGE3NWQ5YzQ3NGM0ODNjYSIsInN1YiI6ImlwZ2FsbGVyeSIsInNjb3BlIjpbImllLWN1cnJlbnQuaWNzLUlFLVBVQkxJQy1TQUZFVFkuSUUtUFVCTElDLVNBRkVUWS5MSU1JVEVELkRFVkVMT1AiLCJ1YWEucmVzb3VyY2UiLCJpZS1jdXJyZW50Lmljcy1JRS1FTlZJUk9OTUVOVEFMLklFLUVOVklST05NRU5UQUwuRlJFRS5ERVZFTE9QIiwiaWUtY3VycmVudC5pY3MtSUUtUEFSS0lORy5JRS1QQVJLSU5HLkxJTUlURUQuREVWRUxPUCIsImllLWN1cnJlbnQuaWNzLUlFLVRSQUZGSUMuSUUtVFJBRkZJQy5MSU1JVEVELkRFVkVMT1Ai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27MdFTcNh0o-P0R5jAC4tsm9fQ1rFto8YBiK2Pk61UNP0SCQPyzKM-4tLI3WoidGl4yiqnI4tLocr1Wwkjjq0HrdNSWYlcr9Mf4ZCcdqTJBKmEusw2S-V45opmhA9fSFK1YH8F3hQq_WEG9w";
public static String parking_zone_id = "ics-IE-PARKING";
private SimpleHttpClient httpClient = null;
public GEManager() throws Exception {
httpClient = new SimpleHttpClient();
httpClient.Initialize(100);
}
public BaseRestResponse executeRequest(String serviceId, String[] apiIdAsParams, RequestContext requestContext, JsonNode content, boolean isMaintenanceRequest) {
return null;
SimpleHttpResponse resp = null;
SimpleHttpRequest req = null;
String error = null;
switch(apiIdAsParams[0]) {
case "cameras":
req = buildCameraHttpRequest(requestContext,content);
try {
resp = httpClient.processRequest(req);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
break;
default:
}
if(resp.getStatusCode() == 200)
return buildResp(resp);
else
return new BaseRestResponse(false,String.valueOf(resp.getStatusCode()));
}
private BaseRestResponse buildResp(SimpleHttpResponse resp) {
BaseRestResponse brr = new BaseRestResponse(true,null);
int size;
String content = resp.getContent();
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode contentObj = mapper.readTree(content);
size = contentObj.get("totalElements").asInt();
JsonNode arrNode = contentObj.get("content");
ArrayNode node = mapper.createArrayNode();
if (arrNode.isArray()) {
for (int i = 0; i < size; ++i) {
ObjectNode objectNode = mapper.createObjectNode();
objectNode.put("id",arrNode.get(i).get("assetUid"));
objectNode.put("mediaType",arrNode.get(i).get("mediaType"));
String[] latLon = arrNode.get(i).get("coordinates").asText().split(":");
double lat = Double.parseDouble(latLon[0]);
double lon = Double.parseDouble(latLon[1]);
objectNode.put("lat",lat);
objectNode.put("lon",lon);
ArrayNode linksArray = mapper.createArrayNode();
ObjectNode linksNode = mapper.createObjectNode();
linksNode.put("latestImage",(JsonNode)null);
linksArray.add(linksNode);
linksNode = mapper.createObjectNode();
linksNode.put("latestVideo",(JsonNode)null);
linksArray.add(linksNode);
objectNode.put("links",linksArray);
node.add(objectNode);
}
brr.objectNode = node;
}
} catch (IOException e) {
e.printStackTrace();
}
return brr;
}
private SimpleHttpRequest buildCameraHttpRequest(RequestContext requestContext,JsonNode content) {
SimpleHttpRequest request = new SimpleHttpRequest();
request.setProtocol("https");
request.setDomain(baseUrl);
request.setPort(443);
request.setMethod(SimpleHttpRequest.Method.GET);
request.setPath(assetListUrl);
request.addHeader("Authorization", "Bearer " + token);
request.addHeader("Predix-Zone-Id",parking_zone_id);
Map<String, Deque<String>> queryParams = requestContext.queryParameters;
if(queryParams != null && !queryParams.isEmpty()) {
String bbox = "bbox=" + queryParams.get("bbox").pop() + "&page=0&size=500&q=assetType:CAMERA";
request.setQueryString(bbox);
}
if(content != null)
request.setContent(content.toString());
return request;
}
}
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