Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
network manager
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
innovation-that-excites
network manager
Commits
9808adcf
Commit
9808adcf
authored
Jun 10, 2019
by
Luciano Cauzzi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added existence check function
parent
044f7d31
Pipeline
#62
failed with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
2 deletions
+31
-2
network_manager/pyramid_manager.py
network_manager/pyramid_manager.py
+31
-2
No files found.
network_manager/pyramid_manager.py
View file @
9808adcf
...
...
@@ -33,7 +33,7 @@ class AppPyramidManager:
self
.
__app_token__
=
app_token_from_dict
(
json_repr
)
return
self
.
__app_token__
except
Exception
as
e
:
logger
.
error
(
"
\n
[NETWORK]: Error while fetching police report list:
{}
\n
"
.
format
(
e
))
logger
.
error
(
"
Error while authenticating into pyramid
{}
\n
"
.
format
(
e
))
return
None
def
save
(
self
,
doc
)
->
bool
:
...
...
@@ -55,7 +55,36 @@ class AppPyramidManager:
if
response
.
status_code
!=
200
:
return
False
except
Exception
as
e
:
logger
.
error
(
"Error while uploading
injunctions to server
"
)
logger
.
error
(
"Error while uploading
document to pyramid
"
)
logger
.
exception
(
e
)
return
False
return
True
def
exists_injunction
(
self
,
inj
)
->
Optional
[
str
]:
try
:
url
=
"{}/{}/_search"
.
format
(
self
.
__base_url__
,
self
.
__res_url__
)
headers
=
{
'AUTHORIZATION'
:
self
.
__app_token__
.
token
,
'Content-Type'
:
"application/json"
}
payload
=
"{
\n\t\"
_source
\"
: {
\n
"
\
"
\"
includes
\"
:
\"
*
\"
,
\n
"
\
"
\"
excludes
\"
:
\"
attachments
\"\n
"
\
"},
\n
\"
query
\"
: {
\n
\"
terms
\"
: {
\n
\"
numero_cronologico
\"
: [
\"
"
\
+
inj
.
progressive_number
+
"
\"
]
\n
}
\n
}
\n
}"
s
=
self
.
__network_manager__
.
get_session
()
response
=
s
.
get
(
url
,
data
=
payload
,
headers
=
headers
,
timeout
=
AppPyramidManager
.
TIMEOUT
)
json_obj
=
json
.
loads
(
response
.
text
)
attachments
=
json_obj
[
"hits"
][
"hits"
]
if
len
(
attachments
)
>
0
:
doc_id
=
json_obj
[
"hits"
][
"hits"
][
0
][
"_id"
]
return
doc_id
else
:
return
None
except
Exception
as
e
:
logger
.
error
(
"Error while checking document's existence"
)
logger
.
exception
(
e
)
return
None
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