Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
services
Import Process
Import API
Commits
4ba0723d
Commit
4ba0723d
authored
Jun 28, 2021
by
Jonas Waeber
Browse files
Fix write report.
parent
5e9b664c
Pipeline
#28650
passed with stages
in 2 minutes
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
import_api_app/resources/WriteTypeReportToDrupal.py
View file @
4ba0723d
...
...
@@ -69,8 +69,8 @@ class WriteTypeReportToDrupal(Resource):
'message'
:
f
'Missing a element in input body:
{
er
}
'
},
400
try
:
node_id
=
self
.
get_drupal_uuid
(
identifier
,
node_type
)
return
self
.
write_results
(
node_type
,
node_id
,
status
,
report
)
node_id
,
lang_code
=
self
.
get_drupal_uuid
(
identifier
,
node_type
)
return
self
.
write_results
(
node_type
,
node_id
,
lang_code
,
status
,
report
)
except
ImportApiError
as
e
:
current_app
.
logger
.
error
(
f
"Could not write report to
{
node_type
}
/
{
identifier
}
:
{
e
.
message
}
"
)
...
...
@@ -83,7 +83,8 @@ class WriteTypeReportToDrupal(Resource):
response
=
requests
.
get
(
url
,
headers
=
self
.
headers
,
auth
=
self
.
auth
)
if
response
.
ok
:
try
:
return
response
.
json
()[
'data'
][
0
][
'id'
]
result
=
response
.
json
()[
'data'
][
0
]
return
result
[
'id'
],
result
[
'attributes'
][
'langcode'
]
except
KeyError
as
er
:
current_app
.
logger
.
error
(
f
"Could not find the key
{
er
}
in data:
{
response
.
text
}
."
)
raise
ImportApiError
(
f
"Could not find the key
{
er
}
in data (url=
{
url
}
): "
...
...
@@ -97,19 +98,19 @@ class WriteTypeReportToDrupal(Resource):
current_app
.
logger
.
error
(
"Could not find element: "
+
url
)
raise
ImportApiError
(
f
"Could not find element for report:
{
response
.
text
}
."
)
def
write_results
(
self
,
node_type
,
identifier
,
status
,
report
):
current_app
.
logger
.
debug
(
"writing: "
+
node_type
+
"/"
+
str
(
identifier
)
+
"/"
+
str
(
status
)
+
"/"
+
report
)
def
write_results
(
self
,
node_type
,
identifier
,
lang_code
,
status
,
report
):
current_app
.
logger
.
debug
(
f
"writing:
{
lang_code
}
/
{
node_type
}
/
{
str
(
identifier
)
}
"
f
"/
{
str
(
status
)
}
/
{
report
}
"
)
drupal_type
=
''
url
=
f
'
{
self
.
base_url
}
/jsonapi/node/'
url
=
f
'
{
self
.
base_url
}
/
{
lang_code
}
/
jsonapi/node/'
if
node_type
==
'institution'
:
drupal_type
=
'node--institution'
url
+=
'institution/'
elif
node_type
==
'record_set'
:
drupal_type
=
'node--record_set'
url
+=
'record_set/'
url
=
f
'
{
url
}{
identifier
}
'
url
=
f
'
{
url
}{
identifier
}
'
data
=
{
"data"
:
{
...
...
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