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

Refactor out restful flask

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