Commit d6e7ebcf authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Refactor out restful flask

parent 3b6c773e
......@@ -13,13 +13,14 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask_restful import Resource, request
from flask import request
from flask.views import MethodView
from import_api_app.app import app
from import_api_app.helpers.delete_service import DeleteService
class DeleteInstitution(Resource):
class DeleteInstitution(MethodView):
def __init__(self):
self.delete_service = DeleteService(app.logger, app.config['NAMESPACE'], app.root_path)
......
......@@ -13,13 +13,14 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask_restful import Resource, request
from flask.views import MethodView
from flask import request
from import_api_app.app import app
from import_api_app.helpers.delete_service import DeleteService
class DeleteRecord(Resource):
class DeleteRecord(MethodView):
def __init__(self):
self.delete_service = DeleteService(app.logger, app.config['NAMESPACE'], app.root_path)
......
......@@ -13,13 +13,14 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask_restful import Resource, request
from flask.views import MethodView
from flask import request
from import_api_app.app import app
from import_api_app.helpers.delete_service import DeleteService
class DeleteRecordset(Resource):
class DeleteRecordset(MethodView):
def __init__(self):
self.delete_service = DeleteService(app.logger, app.config['NAMESPACE'], app.root_path)
......
......@@ -13,13 +13,13 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask_restful import Resource
from import_api_app.app import app
from flask.views import MethodView
from import_api_app.app import app
from import_api_app.helpers.mapping import MappingFileHandler
class FetchMappingFile(Resource):
class FetchMappingFile(MethodView):
def __init__(self):
self.host = app.config["sftp_host"]
......
......@@ -17,14 +17,15 @@ import hashlib
import os
from flasgger import swag_from
from flask_restful import Resource, reqparse
from import_api_app.app import app
from flask import request
from flask.views import MethodView
from import_api_app.app import app
from import_api_app.helm import Helm
from import_api_app.helpers.mapping import MappingFileHandler
class ImportProcessStart(Resource):
class ImportProcessStart(MethodView):
def __init__(self):
self.host = app.config["sftp_host"]
......@@ -49,12 +50,8 @@ class ImportProcessStart(Resource):
@swag_from('ImportProcessStart.yml')
def post(self, institution_id, record_set_id):
# get parameters of request-body
parser = reqparse.RequestParser()
parser.add_argument('job-parameters', type=dict)
args = parser.parse_args()
job_parameters = args['job-parameters']
job_parameters['institutionId'] = institution_id
job_parameters['recordSetId'] = record_set_id
request_data = request.json
job_parameters = request_data['job-parameters']
if job_parameters is None:
job_parameters = {}
......@@ -81,9 +78,9 @@ class ImportProcessStart(Resource):
:10]
body = {'drupalJobUuid': job_parameters['drupalJobUuid'],
'drupalJobLogResultUuid': job_parameters['drupalJobLogResultUuid'],
'recordSetId': job_parameters['recordSetId'],
'recordSetId': record_set_id,
'sessionId': job_parameters['sessionId'], 'shortSessionId': short_session_id,
'institutionId': job_parameters['institutionId'],
'institutionId': institution_id,
'isPublished': job_parameters['isPublished'],
'kafkaConfigs': app.config['tfv-kafka-configs'],
'sftpConfigs': app.config['tfv-sftp-configs'],
......
......@@ -13,17 +13,18 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import uuid
import json
import uuid
import requests
from requests.auth import HTTPBasicAuth
from flask.views import MethodView
from kafka import KafkaProducer
from flask_restful import Resource
from requests.auth import HTTPBasicAuth
from import_api_app.app import app
class UpdateInstitution(Resource):
class UpdateInstitution(MethodView):
def __init__(self):
self.producer = KafkaProducer(bootstrap_servers=app.config['kafka-broker-url'],
......
......@@ -13,19 +13,19 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import json
import uuid
from flask_restful import Resource
from import_api_app.app import app
from kafka import KafkaProducer
import requests
import json
from flask.views import MethodView
from kafka import KafkaProducer
from kafka.errors import KafkaTimeoutError
from requests.auth import HTTPBasicAuth
from import_api_app.app import app
class UpdateRecordSet(Resource):
class UpdateRecordSet(MethodView):
def __init__(self):
self.producer = KafkaProducer(bootstrap_servers=app.config['kafka-broker-url'],
......
......@@ -17,13 +17,14 @@ import json
from datetime import datetime
import requests
from flask_restful import Resource, request
from flask.views import MethodView
from flask import request
from import_api_app.app import app
from import_api_app.helpers.error import ImportApiError
from requests.auth import HTTPBasicAuth
class WriteJobResultToDrupal(Resource):
class WriteJobResultToDrupal(MethodView):
def __init__(self):
self.logger = None
......
......@@ -13,15 +13,18 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import requests
import json
from flask_restful import Resource, request
import requests
from flask.views import MethodView
from flask import request
from requests.auth import HTTPBasicAuth
from import_api_app.app import app
from import_api_app.helpers.error import ImportApiError
from requests.auth import HTTPBasicAuth
class WriteTypeReportToDrupal(Resource):
class WriteTypeReportToDrupal(MethodView):
def __init__(self):
self.base_url = app.config["drupal-api-url"]
......@@ -72,7 +75,6 @@ class WriteTypeReportToDrupal(Resource):
500:
description: There was a problem
"""
try:
node_type = request.json['node_type']
identifier = request.json['id']
......
......@@ -98,35 +98,32 @@ def favicon():
mimetype='image/vnd.microsoft.icon')
api.add_resource(
ImportProcessStart,
'/v1/importprocess/<institution_id>/<record_set_id>/start'
)
api.add_resource(
FetchMappingFile,
'/v1/FetchMappingFile/<recordset_id>/<session_id>'
)
api.add_resource(WriteJobResultToDrupal, '/v1/drupal/<job_drupal_uuid>/<job_log_drupal_uuid>')
api.add_resource(WriteTypeReportToDrupal, '/v1/drupal/WriteElementReport')
api.add_resource(UpdateInstitution, '/v1/drupal/institution/<institution_drupal_uuid>')
api.add_resource(UpdateRecordSet, '/v1/drupal/recordset/<record_set_drupal_uuid>')
api.add_resource(
DeleteRecord,
'/v1/drupal/delete/record/<session_id>',
'/v1/drupal/delete/record/<session_id>/<dryrun>'
)
api.add_resource(
DeleteRecordset,
'/v1/drupal/delete/recordset/<session_id>',
'/v1/drupal/delete/recordset/<session_id>/<dryrun>'
)
api.add_resource(
DeleteInstitution,
'/v1/drupal/delete/institution/<session_id>',
'/v1/drupal/delete/institution/<session_id>/<dryrun>'
)
api.add_resource(ClearCache, )
app.add_url_rule('/v1/importprocess/<institution_id>/<record_set_id>/start',
view_func=ImportProcessStart.as_view('start_import_process'))
app.add_url_rule('/v1/FetchMappingFile/<recordset_id>/<session_id>',
view_func=FetchMappingFile.as_view('load_mapping_files'))
app.add_url_rule('/v1/drupal/<job_drupal_uuid>/<job_log_drupal_uuid>',
view_func=WriteJobResultToDrupal.as_view('write_import_process_report'))
app.add_url_rule('/v1/drupal/WriteElementReport',
view_func=WriteTypeReportToDrupal.as_view('write_group_pipeline_report'))
app.add_url_rule('/v1/drupal/institution/<institution_drupal_uuid>',
view_func=UpdateInstitution.as_view('update_institution'))
app.add_url_rule('/v1/drupal/recordset/<record_set_drupal_uuid>',
view_func=UpdateRecordSet.as_view('update_record_set'))
app.add_url_rule('/v1/drupal/delete/record/<session_id>/<dryrun>',
view_func=DeleteRecord.as_view('delete_record'))
app.add_url_rule('/v1/drupal/delete/recordset/<session_id>/<dryrun>',
view_func=DeleteRecordset.as_view('delete_recordset'))
app.add_url_rule('/v1/drupal/delete/recordset/<session_id>/<dryrun>',
view_func=DeleteInstitution.as_view('delete_institution'))
app.add_url_rule('/v1/drupal/clearcache',
view_func=ClearCache.as_view('clearcache'))
......
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 to comment