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
196db88e
authored
Mar 08, 2017
by
Adi Amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
improve media files handling
parent
e3747d78
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
11 deletions
src/main/java/logic/GEManager.java
src/main/java/logic/GEManager.java
View file @
196db88e
...
@@ -11,6 +11,7 @@ import microservice.RequestContext;
...
@@ -11,6 +11,7 @@ import microservice.RequestContext;
import
microservice.io.iface.ILogger
;
import
microservice.io.iface.ILogger
;
import
microservice.types.BaseRestResponse
;
import
microservice.types.BaseRestResponse
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.output.StringBuilderWriter
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.CookieStore
;
import
org.apache.http.client.CookieStore
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpGet
;
...
@@ -169,15 +170,21 @@ public class GEManager {
...
@@ -169,15 +170,21 @@ public class GEManager {
resp
=
httpClient
.
processRequest
(
req
);
resp
=
httpClient
.
processRequest
(
req
);
if
(
resp
.
getStatusCode
()
==
200
)
{
if
(
resp
.
getStatusCode
()
==
200
)
{
ObjectNode
dataObj
=
mapper
.
createObjectNode
();
ObjectNode
dataObj
=
mapper
.
createObjectNode
();
// file name
// parse file url
String
filename
=
getImageFileName
(
url
);
// String[0]: cameraId
String
[]
fileNameTokens
=
filename
.
split
(
"\\."
);
// String[1]: timestamp
if
(
fileNameTokens
.
length
==
2
)
// String[2]: media type (IMAGE/VIDEO)
filename
=
fileNameTokens
[
0
]
+
".latest"
+
"."
+
fileNameTokens
[
1
];
// String[3]: fileName
else
String
[]
urlParts
=
getMediaFileName
(
url
,
"latest"
);
filename
=
fileNameTokens
[
0
]
+
".latest"
;
if
(
urlParts
==
null
)
{
dataObj
.
put
(
"fileName"
,
filename
);
String
err
=
"buildCameraResp() failed to parse file url: "
+
url
;
// data
logger
.
error
(
err
);
return
new
BaseRestResponse
(
false
,
err
);
}
dataObj
.
put
(
"cameraId"
,
urlParts
[
0
]);
dataObj
.
put
(
"timestamp"
,
Long
.
valueOf
(
urlParts
[
1
]));
dataObj
.
put
(
"mediaType"
,
urlParts
[
2
]);
dataObj
.
put
(
"fileName"
,
urlParts
[
3
]);
dataObj
.
put
(
"data"
,
resp
.
getContent
());
dataObj
.
put
(
"data"
,
resp
.
getContent
());
brr
.
objectNode
=
dataObj
;
brr
.
objectNode
=
dataObj
;
}
}
...
@@ -309,10 +316,60 @@ public class GEManager {
...
@@ -309,10 +316,60 @@ public class GEManager {
return
newArray
;
return
newArray
;
}
}
private
String
getImageFileName
(
String
link
)
{
// pioFile=https://ie-cities-media.run.asv-pr-pub.ice.predix.io:443/v2/file/CAMERA-STG-HYP1052-CAM-L_1488491909720_0_IMAGE.JPG
// returns:
// String[0]: cameraId
// String[1]: timestamp
// String[2]: media type (IMAGE/VIDEO)
// String[3]: fileName
private
String
[]
getMediaFileName
(
String
link
,
String
timeInd
)
{
String
result
[]
=
new
String
[
4
];
String
mediaType
=
null
;
String
fileType
=
null
;
String
cameraId
=
null
;
String
timestamp
=
null
;
String
fileName
=
""
;
String
[]
linkTokens
=
link
.
split
(
"/"
);
String
[]
linkTokens
=
link
.
split
(
"/"
);
if
(
linkTokens
.
length
>
1
)
{
if
(
linkTokens
.
length
>
1
)
{
return
linkTokens
[
linkTokens
.
length
-
1
];
String
pioFile
=
linkTokens
[
linkTokens
.
length
-
1
];
// file name
String
pioFileTokens
[]
=
pioFile
.
split
(
"\\."
);
String
pioFileName
=
pioFileTokens
[
0
];
// media type
String
fileNameTokens
[]
=
pioFileName
.
split
(
"_"
);
mediaType
=
fileNameTokens
[
fileNameTokens
.
length
-
1
];
// file type
if
(
pioFileTokens
.
length
==
2
)
fileType
=
pioFileTokens
[
1
];
else
{
if
(
mediaType
.
equals
((
"IMAGE"
)))
fileType
=
"JPG"
;
else
fileType
=
"MP4"
;
}
// camera id
cameraId
=
fileNameTokens
[
0
];
// time-stamp
timestamp
=
fileNameTokens
[
fileNameTokens
.
length
-
2
];
// fileName
if
(
timeInd
==
null
)
fileName
=
cameraId
+
"."
+
timestamp
+
"."
+
fileType
;
else
fileName
=
cameraId
+
"."
+
timeInd
+
"."
+
fileType
;
// build result
result
[
0
]
=
cameraId
;
result
[
1
]
=
timestamp
;
result
[
2
]
=
mediaType
;
result
[
3
]
=
fileName
;
return
result
;
}
}
else
else
return
null
;
return
null
;
...
@@ -355,4 +412,6 @@ public class GEManager {
...
@@ -355,4 +412,6 @@ public class GEManager {
return
null
;
return
null
;
}
}
}
}
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