Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery
/
mde
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
805e0383
authored
Aug 29, 2017
by
Adi Amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
support getTrafficLanes from cisco
parent
911b4d87
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
4 deletions
doc/sample-cisco-parking.json
src/main/java/logic/CiscoManager.java
doc/sample-cisco-parking.json
0 → 100644
View file @
805e0383
This diff is collapsed.
Click to expand it.
src/main/java/logic/CiscoManager.java
View file @
805e0383
...
...
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.NullNode;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.google.gdata.util.common.base.PercentEscaper
;
import
com.google.gdata.util.common.util.Base64
;
import
com.google.gson.JsonNull
;
import
http.simpleHttpClient.SimpleHttpClient
;
import
http.simpleHttpClient.SimpleHttpRequest
;
import
http.simpleHttpClient.SimpleHttpResponse
;
...
...
@@ -227,13 +228,35 @@ public class CiscoManager {
private
BaseRestResponse
reLogin
(
LoginInfo
loginInfo
)
{
return
null
;
}
private
BaseRestResponse
getTrafficLanes
()
{
return
null
;
SimpleHttpRequest
req
=
null
;
SimpleHttpResponse
httpResp
=
null
;
BaseRestResponse
brr
=
new
BaseRestResponse
(
true
,
null
);
logger
.
info
(
"cisco.getTrafficLanes() activated"
);
try
{
// get parking
req
=
buildTrafficLanesRequest
();
httpResp
=
httpClient
.
processRequest
(
req
);
if
(
httpResp
.
getStatusCode
()
==
200
)
brr
=
parseTrafficLanesResp
(
httpResp
);
else
{
logHttpError
(
"getTrafficLanes"
,
httpResp
);
return
errorHttpResponse
(
httpResp
);
}
}
catch
(
Exception
e
)
{
String
err
=
CISCO
+
".getTrafficLanes() failed with exception. e="
+
e
.
toString
();
logger
.
error
(
err
);
return
errorResponse
(
err
);
}
return
brr
;
}
...
...
@@ -416,6 +439,103 @@ public class CiscoManager {
}
}
private
SimpleHttpRequest
buildTrafficLanesRequest
()
{
SimpleHttpRequest
request
=
new
SimpleHttpRequest
();
request
.
setProtocol
(
"https"
);
request
.
setDomain
(
CISCO_DOMAIN
);
request
.
setProtocol
(
"http"
);
request
.
setPort
(
80
);
request
.
setMethod
(
SimpleHttpRequest
.
Method
.
POST
);
// path
String
path
=
API_URI
+
"devices/traffic"
;
request
.
setPath
(
path
);
// query string
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"UserKey="
).
append
(
loginInfo
.
userId
).
append
(
"&"
)
.
append
(
"SensorCustomerKey="
).
append
(
loginInfo
.
parentUserId
).
append
(
"&"
)
.
append
(
"AppKey=CDP-App"
);
String
queryString
=
sb
.
toString
();
request
.
setQueryString
(
queryString
);
// content
String
content
=
"{\"Query\":{\"Find\": {\"RoadSegment\": {}}}}"
;
request
.
setContent
(
content
);
// headers
// WSO2-Authorization
String
WSO2_Authorization
=
"oAuth Bearer "
+
loginInfo
.
appAccessToken
;
request
.
addHeader
(
"WSO2-Authorization"
,
WSO2_Authorization
);
// Authorization
String
Authorization
=
"Bearer "
+
loginInfo
.
apiAccessToken
;
request
.
addHeader
(
"Authorization"
,
Authorization
);
// accept
String
Accept
=
"application/json"
;
request
.
addHeader
(
"Accept"
,
Accept
);
// Content-Type
String
Content_Type
=
"application/json"
;
request
.
addHeader
(
"Content-Type"
,
Content_Type
);
return
request
;
}
private
BaseRestResponse
parseTrafficLanesResp
(
SimpleHttpResponse
httpResp
)
{
try
{
JsonNode
contentObj
=
objMapper
.
readTree
(
httpResp
.
getContent
());
ArrayNode
csTrafficLanes
=
(
ArrayNode
)
contentObj
.
at
(
"/Find/Result"
);
ArrayNode
trafficLanesResult
=
objMapper
.
createArrayNode
();
for
(
JsonNode
csTrafficLane:
csTrafficLanes
)
{
ObjectNode
objTrafficLane
=
objMapper
.
createObjectNode
();
// location uid
objTrafficLane
.
put
(
"location-uid"
,
csTrafficLane
.
at
(
"/RoadSegment/sid"
).
asText
());
// coordinates
JsonNode
csCoordinates
=
csTrafficLane
.
at
(
"/ParkingSpot/geocoordinates"
);
String
p1Loc
=
"0"
+
","
+
"0"
;
ObjectNode
p1
=
objMapper
.
createObjectNode
();
p1
.
put
(
"P1"
,
p1Loc
);
objTrafficLane
.
put
(
"coordinates"
,
p1
);
// properties
ObjectNode
properties
=
objMapper
.
createObjectNode
();
// vehicleType
properties
.
putNull
(
"vehicleType"
);
// measures
ArrayNode
arrayMeasures
=
objMapper
.
createArrayNode
();
// measure/speed
ObjectNode
measureSpeed
=
objMapper
.
createObjectNode
();
measureSpeed
.
put
(
"tag"
,
"speed"
);
measureSpeed
.
put
(
"value"
,
csTrafficLane
.
at
(
"/RoadSegment/refSpeed"
).
asDouble
());
measureSpeed
.
put
(
"unit"
,
"MPS"
);
arrayMeasures
.
add
(
measureSpeed
);
// measure/vehicleCount
ObjectNode
measureVehicleCount
=
objMapper
.
createObjectNode
();
measureVehicleCount
.
put
(
"tag"
,
"vehicleCount"
);
measureVehicleCount
.
put
(
"value"
,
20
);
measureVehicleCount
.
put
(
"unit"
,
""
);
arrayMeasures
.
add
(
measureVehicleCount
);
properties
.
set
(
"measures"
,
arrayMeasures
);
// timestamp
properties
.
put
(
"timestamp"
,
0
);
// mde-key
properties
.
put
(
"mde-key"
,
csTrafficLane
.
at
(
"/RoadSegment/sid"
).
asText
());
objTrafficLane
.
set
(
"properties"
,
properties
);
trafficLanesResult
.
add
(
objTrafficLane
);
}
logger
.
info
(
"parseTrafficLanesResp() - found "
+
trafficLanesResult
.
size
()
+
" traffic lanes. tenant="
+
CISCO
);
return
successResponse
(
trafficLanesResult
);
}
catch
(
Exception
e
)
{
String
err
=
"parseUserInfoResp failed with exception. e: "
+
e
.
toString
();
return
errorResponse
(
err
);
}
}
private
Boolean
parseLoginRequestParameters
(
RequestContext
requestContext
)
{
...
...
@@ -492,8 +612,9 @@ public class CiscoManager {
private
Boolean
isAccessDenied
(
BaseRestResponse
brr
)
{
if
(
brr
.
success
==
false
)
{
int
statusCode
=
brr
.
objectNode
.
get
(
"statusCode"
).
asInt
();
Boolean
bAccessDenied
=
(
statusCode
==
403
||
statusCode
==
401
);
//int statusCode = brr.objectNode.get("statusCode").asInt();
//Boolean bAccessDenied = (statusCode == 403 ||statusCode == 401);
Boolean
bAccessDenied
=
true
;
return
bAccessDenied
;
}
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment