@@ -20,25 +20,15 @@ class DocumentManifestZipService:
2020 def __init__ (self , zip_trace : DocumentManifestZipTrace ):
2121 self .s3_service = S3Service ()
2222 self .dynamo_service = DynamoDBService ()
23- # self.temp_output_dir = tempfile.mkdtemp()
24- # self.temp_downloads_dir = tempfile.mkdtemp()
2523 self .zip_trace_object = zip_trace
2624 self .zip_output_bucket = os .environ ["ZIPPED_STORE_BUCKET_NAME" ]
2725 self .zip_trace_table = os .environ ["ZIPPED_STORE_DYNAMODB_NAME" ]
2826 self .zip_file_name = f"patient-record-{ zip_trace .job_id } .zip"
29- # self.zip_file_path = os.path.join(self.temp_output_dir, self.zip_file_name)
3027
3128 def handle_zip_request (self ):
3229 self .update_processing_status ()
33- # self.download_documents_to_be_zipped()
34- # Stream and zip the documents in memory
3530 zip_buffer = self .stream_zip_documents ()
36- # Upload the zip file to S3
3731 self .upload_zip_file (zip_buffer )
38-
39- # self.zip_files()
40- # self.upload_zip_file()
41- # self.cleanup_temp_files()
4232 self .update_dynamo_with_fields ({"job_status" , "zip_file_location" })
4333
4434 def stream_zip_documents (self ) -> io .BytesIO :
@@ -87,27 +77,6 @@ def stream_zip_documents(self) -> io.BytesIO:
8777 status_code = 500 , error = LambdaError .ZipCreationError
8878 )
8979
90- # def download_documents_to_be_zipped(self):
91- # logger.info("Downloading documents to be zipped")
92- # documents = self.zip_trace_object.files_to_download
93- # for document_location, document_name in documents.items():
94- # self.download_file_from_s3(document_name, document_location)
95- #
96- # def download_file_from_s3(self, document_name: str, document_location: str):
97- # download_path = os.path.join(self.temp_downloads_dir, document_name)
98- # file_bucket, file_key = self.get_file_bucket_and_key(document_location)
99- # try:
100- # self.s3_service.download_file(file_bucket, file_key, download_path)
101- # except ClientError as e:
102- # self.update_failed_status()
103- # msg = f"{file_key} may reference missing file in s3 bucket: {file_bucket}"
104- # logger.error(
105- # f"{LambdaError.ZipServiceClientError.to_str()} {msg + str(e)}",
106- # {"Result": "Failed to create document manifest"},
107- # )
108- # raise GenerateManifestZipException(
109- # status_code=500, error=LambdaError.ZipServiceClientError
110-
11180 def get_file_bucket_and_key (self , file_location : str ):
11281 try :
11382 file_bucket , file_key = file_location .replace ("s3://" , "" ).split ("/" , 1 )
@@ -140,36 +109,6 @@ def upload_zip_file(self, zip_buffer: io.BytesIO):
140109
141110 self .zip_trace_object .job_status = TraceStatus .COMPLETED
142111
143- # def upload_zip_file(self):
144- # logger.info("Uploading zip file to s3")
145- # self.zip_trace_object.zip_file_location = (
146- # f"s3://{self.zip_output_bucket}/{self.zip_file_name}"
147- # )
148- #
149- # try:
150- # self.s3_service.upload_file(
151- # file_name=self.zip_file_path,
152- # s3_bucket_name=self.zip_output_bucket,
153- # file_key=f"{self.zip_file_name}",
154- # )
155- # except ClientError as e:
156- # self.update_failed_status()
157- # logger.error(e, {"Result": "Failed to create document manifest"})
158- # raise GenerateManifestZipException(
159- # status_code=500, error=LambdaError.ZipServiceClientError
160- # )
161- #
162- # self.zip_trace_object.job_status = TraceStatus.COMPLETED
163-
164- # def zip_files(self):
165- # logger.info("Creating zip from files")
166- # with zipfile.ZipFile(self.zip_file_path, "w", zipfile.ZIP_DEFLATED) as zipf:
167- # for root, _, files in os.walk(self.temp_downloads_dir):
168- # for file in files:
169- # file_path = os.path.join(root, file)
170- # arc_name = os.path.relpath(file_path, self.temp_downloads_dir)
171- # zipf.write(file_path, arc_name)
172-
173112 def update_dynamo_with_fields (self , fields : set ):
174113 logger .info ("Writing zip trace to db" )
175114 self .dynamo_service .update_item (
@@ -187,7 +126,3 @@ def update_processing_status(self):
187126 def update_failed_status (self ):
188127 self .zip_trace_object .job_status = TraceStatus .FAILED
189128 self .update_dynamo_with_fields ({"job_status" })
190-
191- # def cleanup_temp_files(self):
192- # shutil.rmtree(self.temp_downloads_dir)
193- # shutil.rmtree(self.temp_output_dir)
0 commit comments