|
15 | 15 | from ..models.models import File, Registration, SubmissionId |
16 | 16 | from ..models.submission import Rems, Submission, SubmissionMetadata, SubmissionWorkflow |
17 | 17 | from ..processors.xml.bigpicture import ( |
18 | | - BP_ANNOTATION_OBJECT_TYPE, |
19 | | - BP_DATASET_OBJECT_TYPE, |
20 | | - BP_IMAGE_OBJECT_TYPE, |
21 | | - BP_OBSERVATION_OBJECT_TYPE, |
22 | | - BP_OBSERVER_OBJECT_TYPE, |
23 | 18 | BP_POLICY_OBJECT_TYPE, |
24 | | - BP_SAMPLE_OBJECT_TYPES, |
25 | | - BP_STAINING_OBJECT_TYPE, |
26 | 19 | BP_XML_OBJECT_CONFIG, |
27 | 20 | ) |
28 | 21 | from ..processors.xml.processors import XmlObjectProcessor |
| 22 | +from ..services.bigpicture import upload_bp_metadata_xmls |
29 | 23 | from ..services.datacite import DataciteService |
30 | | -from ..services.file import S3InboxSDAService |
31 | 24 | from ..services.submission.bigpicture import is_clinical_policy |
32 | 25 | from .restapi import RESTAPIHandler |
33 | 26 | from .submission import SubmissionAPIHandler |
34 | 27 |
|
35 | | -BP_METADATA_FILES: tuple[tuple[str | tuple[str, ...], str], ...] = ( |
36 | | - (BP_DATASET_OBJECT_TYPE, "dataset.xml.c4gh"), |
37 | | - (BP_POLICY_OBJECT_TYPE, "policy.xml.c4gh"), |
38 | | - (BP_IMAGE_OBJECT_TYPE, "image.xml.c4gh"), |
39 | | - (BP_ANNOTATION_OBJECT_TYPE, "annotation.xml.c4gh"), |
40 | | - (BP_OBSERVATION_OBJECT_TYPE, "observation.xml.c4gh"), |
41 | | - (BP_OBSERVER_OBJECT_TYPE, "observer.xml.c4gh"), |
42 | | - (tuple(BP_SAMPLE_OBJECT_TYPES), "sample.xml.c4gh"), |
43 | | - (BP_STAINING_OBJECT_TYPE, "staining.xml.c4gh"), |
44 | | -) |
45 | | - |
46 | 28 |
|
47 | 29 | class PublishAPIHandler(RESTAPIHandler): |
48 | 30 | """Publish API handler.""" |
@@ -161,7 +143,7 @@ async def _publish_rems(self, submission: Submission, rems: Rems, registration: |
161 | 143 | # Create REMS resource. |
162 | 144 | if not registration.remsResourceId: |
163 | 145 | if submission.workflow == SubmissionWorkflow.BP: |
164 | | - # Use BigPicture dataset id as the REMS resource id. |
| 146 | + # Use Bigpicture dataset id as the REMS resource id. |
165 | 147 | resid = submission.submissionId |
166 | 148 | elif registration.doi is not None: |
167 | 149 | # Use DOI as the REMS resource id. |
@@ -331,7 +313,7 @@ async def publish_submission( |
331 | 313 | jwt = self._services.auth._get_bearer_token(headers) |
332 | 314 | if not jwt: |
333 | 315 | raise UserException("Missing OIDC access token in Authorization bearer header for SDA inbox upload.") |
334 | | - await self._upload_bp_metadata_xmls(submission_id, user.user_id, jwt) |
| 316 | + await upload_bp_metadata_xmls(self._services, submission_id, user.user_id, jwt) |
335 | 317 |
|
336 | 318 | # Update submission status to published. |
337 | 319 | await submission_service.publish(submission_id) |
@@ -406,32 +388,6 @@ async def _register_submission(self, submission: Submission, datacite: DataCiteM |
406 | 388 | if self._handlers.metax is not None: |
407 | 389 | await self._publish_metax(registration) |
408 | 390 |
|
409 | | - async def _upload_bp_metadata_xmls(self, submission_id: str, user_id: str, jwt: str) -> None: |
410 | | - """Upload encrypted Bigpicture metadata XML files to SDA inbox.""" |
411 | | - file_provider = self._services.file_provider |
412 | | - if not isinstance(file_provider, S3InboxSDAService): |
413 | | - raise SystemException("Bigpicture metadata upload requires SDA inbox file provider service.") |
414 | | - |
415 | | - bucket = user_id.replace("@", "_") # SDA inbox bucket name is the user id with @ replaced by underscore |
416 | | - prefix = f"DATASET_{submission_id}/METADATA" |
417 | | - for object_type, filename in BP_METADATA_FILES: |
418 | | - xml = None |
419 | | - async for xml_doc in self._services.object.get_xml_documents(submission_id, object_type): |
420 | | - xml = xml_doc |
421 | | - break |
422 | | - if xml is None: |
423 | | - continue |
424 | | - |
425 | | - object_key = f"{prefix}/{filename}" |
426 | | - await file_provider._add_file_to_bucket( |
427 | | - bucket_name=bucket, |
428 | | - object_key=object_key, |
429 | | - access_key=user_id, |
430 | | - secret_key=user_id, |
431 | | - session_token=jwt, |
432 | | - body=xml.encode("utf-8"), |
433 | | - ) |
434 | | - |
435 | 391 | @staticmethod |
436 | 392 | def _create_registration(submission_id: str, title: str, description: str, doi: str) -> Registration: |
437 | 393 | """Create submission registration. |
|
0 commit comments