@@ -19,14 +19,18 @@ def publish_notice(notice: Notice, publisher: SFTPPublisherABC = None,
1919 """
2020 This function publishes the METS manifestation for a Notice in Cellar.
2121 """
22- publisher = publisher if publisher else SFTPPublisher ()
23- remote_folder_path = remote_folder_path if remote_folder_path else config .SFTP_PUBLISH_PATH
22+ publisher = publisher or SFTPPublisher ()
23+ remote_folder_path = remote_folder_path or config .SFTP_PUBLISH_PATH
2424 mets_manifestation = notice .mets_manifestation
2525 if not mets_manifestation or not mets_manifestation .object_data :
2626 raise ValueError ("Notice does not have a METS manifestation to be published." )
2727
28+ package_name = mets_manifestation .package_name
29+ if not package_name :
30+ raise ValueError ("METS manifestation does not have a package name for publishing." )
31+
2832 package_content = base64 .b64decode (bytes (mets_manifestation .object_data , encoding = 'utf-8' ), validate = True )
29- remote_notice_path = f"{ remote_folder_path } /{ notice . ted_id } { DEFAULT_NOTICE_PACKAGE_EXTENSION } "
33+ remote_notice_path = f"{ remote_folder_path } /{ package_name } "
3034 source_file = tempfile .NamedTemporaryFile ()
3135 source_file .write (package_content )
3236 try :
@@ -62,15 +66,19 @@ def publish_notice_into_s3(notice: Notice, s3_publisher: S3Publisher = None,
6266 :param bucket_name:
6367 :return:
6468 """
65- s3_publisher = s3_publisher if s3_publisher else S3Publisher ()
69+ s3_publisher = s3_publisher or S3Publisher ()
6670 bucket_name = bucket_name or config .S3_PUBLISH_NOTICE_BUCKET
6771 mets_manifestation = notice .mets_manifestation
6872 if not mets_manifestation or not mets_manifestation .object_data :
6973 raise ValueError ("Notice does not have a METS manifestation to be published." )
7074
75+ package_name = mets_manifestation .package_name
76+ if not package_name :
77+ raise ValueError ("METS manifestation does not have a package name for publishing." )
78+
7179 package_content = base64 .b64decode (bytes (mets_manifestation .object_data , encoding = 'utf-8' ), validate = True )
7280 result : S3PublishResult = s3_publisher .publish (bucket_name = bucket_name ,
73- object_name = f"{ notice . ted_id } { DEFAULT_NOTICE_PACKAGE_EXTENSION } " ,
81+ object_name = f"{ package_name } " ,
7482 data = package_content )
7583 return result is not None
7684
@@ -86,7 +94,7 @@ def publish_notice_into_s3_by_id(notice_id: str, notice_repository: NoticeReposi
8694 :param bucket_name:
8795 :return:
8896 """
89- s3_publisher = s3_publisher if s3_publisher else S3Publisher ()
97+ s3_publisher = s3_publisher or S3Publisher ()
9098 bucket_name = bucket_name or config .S3_PUBLISH_NOTICE_BUCKET
9199 notice = notice_repository .get (reference = notice_id )
92100 result = publish_notice_into_s3 (notice = notice , bucket_name = bucket_name , s3_publisher = s3_publisher )
@@ -102,7 +110,7 @@ def publish_notice_rdf_into_s3(notice: Notice, s3_publisher: S3Publisher = None,
102110 :param bucket_name:
103111 :return:
104112 """
105- s3_publisher = s3_publisher if s3_publisher else S3Publisher ()
113+ s3_publisher = s3_publisher or S3Publisher ()
106114 bucket_name = bucket_name or config .S3_PUBLISH_NOTICE_RDF_BUCKET
107115 rdf_manifestation : RDFManifestation = notice .distilled_rdf_manifestation
108116 result : bool = publish_notice_rdf_content_into_s3 (
@@ -125,7 +133,7 @@ def publish_notice_rdf_into_s3_by_id(notice_id: str, notice_repository: NoticeRe
125133 :param bucket_name:
126134 :return:
127135 """
128- s3_publisher = s3_publisher if s3_publisher else S3Publisher ()
136+ s3_publisher = s3_publisher or S3Publisher ()
129137 bucket_name = bucket_name or config .S3_PUBLISH_NOTICE_RDF_BUCKET
130138 notice = notice_repository .get (reference = notice_id )
131139 return publish_notice_rdf_into_s3 (notice = notice , bucket_name = bucket_name , s3_publisher = s3_publisher )
@@ -143,7 +151,7 @@ def publish_notice_rdf_content_into_s3(rdf_manifestation: RDFManifestation,
143151 :param bucket_name:
144152 :return:
145153 """
146- s3_publisher = s3_publisher if s3_publisher else S3Publisher ()
154+ s3_publisher = s3_publisher or S3Publisher ()
147155 if not rdf_manifestation or not rdf_manifestation .object_data :
148156 raise ValueError ("Notice does not have a RDF manifestation to be published." )
149157
0 commit comments