@@ -515,21 +515,27 @@ def __init__(
515515 folder : FolderEntity ,
516516 image_name : str ,
517517 images : BaseReadOnlyRepository ,
518+ service : SuerannotateServiceProvider ,
518519 ):
519520 super ().__init__ ()
520521 self ._project = project
521522 self ._folder = folder
522523 self ._images = images
523524 self ._image_name = image_name
525+ self ._service = service
524526
525527 def execute (self ):
526- condition = (
527- Condition ("team_id" , self ._project .team_id , EQ )
528- & Condition ("project_id" , self ._project .uuid , EQ )
529- & Condition ("folder_id" , self ._folder .uuid , EQ )
530- & Condition ("name" , self ._image_name , EQ )
528+ images = (
529+ GetBulkImages (
530+ service = self ._service ,
531+ project_id = self ._project .uuid ,
532+ team_id = self ._project .team_id ,
533+ folder_id = self ._folder .uuid ,
534+ images = [self ._image_name ],
535+ )
536+ .execute ()
537+ .data
531538 )
532- images = self ._images .get_all (condition )
533539 if images :
534540 self ._response .data = images [0 ]
535541 else :
@@ -731,7 +737,7 @@ def execute(self):
731737 "height" : image .meta .height ,
732738 }
733739
734- uploaded = self ._backend_service .attach_files (
740+ backend_response = self ._backend_service .attach_files (
735741 project_id = self ._project .uuid ,
736742 folder_id = self ._folder .uuid ,
737743 team_id = self ._project .team_id ,
@@ -740,8 +746,10 @@ def execute(self):
740746 upload_state_code = self .upload_state_code ,
741747 meta = meta ,
742748 )
743-
744- self ._response .data = uploaded , duplications
749+ if isinstance (backend_response , dict ) and "error" in backend_response :
750+ self ._response .errors = AppException (backend_response ["error" ])
751+ else :
752+ self ._response .data = backend_response , duplications
745753 return self ._response
746754
747755
@@ -1634,13 +1642,17 @@ def execute(self):
16341642 image .name for image in self ._images_repo .get_all (condition )
16351643 ]
16361644 for i in range (0 , len (self ._image_names ), self .CHUNK_SIZE ):
1637- self ._response .data = self ._service .set_images_statuses_bulk (
1638- image_names = self ._image_names ,
1645+ status_changed = self ._service .set_images_statuses_bulk (
1646+ image_names = self ._image_names [
1647+ i : i + self .CHUNK_SIZE
1648+ ], # noqa: E203
16391649 team_id = self ._team_id ,
16401650 project_id = self ._project_id ,
16411651 folder_id = self ._folder_id ,
16421652 annotation_status = self ._annotation_status ,
16431653 )
1654+ if not status_changed :
1655+ self ._response .errors = AppException ("Failed to change status." )
16441656 return self ._response
16451657
16461658
@@ -1994,6 +2006,7 @@ def image_use_case(self):
19942006 folder = self ._folder ,
19952007 image_name = self ._image_name ,
19962008 images = self ._images ,
2009+ service = self ._service ,
19972010 )
19982011 return use_case
19992012
@@ -2092,6 +2105,7 @@ def image_use_case(self):
20922105 folder = self ._folder ,
20932106 image_name = self ._image_name ,
20942107 images = self ._images ,
2108+ service = self ._service ,
20952109 )
20962110
20972111 def validate_project_type (self ):
@@ -2162,6 +2176,7 @@ def __init__(
21622176 @property
21632177 def image_use_case (self ):
21642178 return GetImageUseCase (
2179+ service = self ._service ,
21652180 project = self ._project ,
21662181 folder = self ._folder ,
21672182 image_name = self ._image_name ,
@@ -2254,6 +2269,7 @@ def image_use_case(self):
22542269 folder = self ._folder ,
22552270 image_name = self ._image_name ,
22562271 images = self ._images ,
2272+ service = self ._service ,
22572273 )
22582274
22592275 def execute (self ):
@@ -4406,9 +4422,18 @@ def images_to_upload(self):
44064422 x not in Path (path ).name for x in self .exclude_file_patterns
44074423 ]
44084424 non_in_service_list = [x not in Path (path ).name for x in image_names ]
4409- if all (not_in_exclude_list ) and all (non_in_service_list ):
4425+ if (
4426+ all (not_in_exclude_list )
4427+ and all (non_in_service_list )
4428+ and not any (
4429+ Path (path ).name in filtered_path
4430+ for filtered_path in filtered_paths
4431+ )
4432+ ):
44104433 filtered_paths .append (path )
4411- if not all (non_in_service_list ):
4434+ elif not all (non_in_service_list ) or any (
4435+ Path (path ).name in filtered_path for filtered_path in filtered_paths
4436+ ):
44124437 duplicated_paths .append (path )
44134438
44144439 self ._images_to_upload = list (set (filtered_paths )), duplicated_paths
@@ -4447,7 +4472,9 @@ def execute(self):
44474472 ],
44484473 annotation_status = self ._annotation_status ,
44494474 ).execute ()
4450-
4475+ if response .errors :
4476+ logger .error (response .errors )
4477+ continue
44514478 attachments , attach_duplications = response .data
44524479 uploaded .extend (attachments )
44534480 duplications .extend (attach_duplications )
@@ -4554,24 +4581,6 @@ def execute(self):
45544581 folder_id = self ._folder_id ,
45554582 images = self ._images [i : i + self ._chunk_size ],
45564583 )
4557- res += [
4558- ImageEntity (
4559- uuid = image ["id" ],
4560- name = image ["name" ],
4561- path = image ["name" ],
4562- project_id = image ["project_id" ],
4563- team_id = image ["team_id" ],
4564- annotation_status_code = image ["annotation_status" ],
4565- folder_id = image ["folder_id" ],
4566- annotator_id = image ["annotator_id" ],
4567- annotator_name = image ["annotator_name" ],
4568- qa_id = image ["qa_id" ],
4569- qa_name = image ["qa_name" ],
4570- entropy_value = image ["entropy_value" ],
4571- approval_status = image ["approval_status" ],
4572- is_pinned = image ["is_pinned" ],
4573- )
4574- for image in images
4575- ]
4584+ res += [ImageEntity .from_dict (** image ) for image in images ]
45764585 self ._response .data = res
45774586 return self ._response
0 commit comments