Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
author update: generic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Aug 9, 2024
1 parent ee49892 commit 4110599
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
24 changes: 24 additions & 0 deletions backoffice/backoffice/workflows/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@ def create(self, request):
workflow.data,
)

@extend_schema(
summary="Updates an Author",
description="Updates an author, launches the required airflow dag.",
request=serializer_class,
)
@action(detail=False, methods=["post"])
def updates(self, request):
logger.info("Creating workflow with data: %s", request.data)
serializer = self.serializer_class(data=request.data)
if serializer.is_valid(raise_exception=True):
workflow = Workflow.objects.create(
data=serializer.validated_data["data"],
)
logger.info(
"Trigger Airflow DAG: %s for %s",
WORKFLOW_DAGS[workflow.workflow_type].initialize,
workflow.id,
)
return airflow_utils.trigger_airflow_dag(
WORKFLOW_DAGS[workflow.workflow_type].initialize,
str(workflow.id),
workflow.data,
)

@extend_schema(
summary="Partially Updates Author",
description="Updates specific fields of the author.",
Expand Down
4 changes: 3 additions & 1 deletion workflows/dags/author/author_update/author_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def set_author_update_workflow_status_to_running(**context):

@task()
def create_ticket_on_author_update(**context):
endpoint = "/tickets/create-with-template"
endpoint = "/api/tickets/create"
request_data = {
"functional_category": "Author updates",
"template": "curator_update_author",
Expand All @@ -76,6 +76,8 @@ def update_author_on_inspire(**context):
workflow_data = workflow_management_hook.get_workflow(
workflow_id=context["params"]["workflow_id"]
)
print("workflow data is")
print(workflow_data["data"])
control_number = workflow_data["data"]["control_number"]
record_data = inspire_http_record_management_hook.get_record(
pid_type="authors", control_number=control_number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ def __init__(self, *args, **kwargs):
def update_record(
self, data: dict, pid_type: str, control_number: int, revision_id: str
) -> Response:
print("wawawewa")
print(revision_id)
update_headers = {**self.headers, "If-Match": f'"{revision_id - 1}"'}
return self.run_with_advanced_retry(
_retry_args=self.tenacity_retry_kwargs,
method="PUT",
headers=update_headers,
json=data,
endpoint=f"{pid_type}/{control_number}",
data=data,
endpoint=f"/api/{pid_type}/{control_number}",
)

def get_record(self, pid_type: str, control_number: int) -> Response:
response = self.run_with_advanced_retry(
_retry_args=self.tenacity_retry_kwargs,
method="GET",
headers=self.headers,
endpoint=f"/{pid_type}/{control_number}",
endpoint=f"/api/{pid_type}/{control_number}",
)
return response.json()

Expand All @@ -32,7 +34,7 @@ def get_record_revision_id(self, pid_type: str, control_number: int) -> int:
_retry_args=self.tenacity_retry_kwargs,
method="GET",
headers=self.headers,
endpoint=f"/{pid_type}/{control_number}",
endpoint=f"/api/{pid_type}/{control_number}",
)
response.raise_for_status()
return response.json()["revision_id"]
Expand Down

0 comments on commit 4110599

Please sign in to comment.