2121from lib .core .serviceproviders import SuerannotateServiceProvider
2222from lib .core .usecases .base import BaseReportableUseCae
2323from lib .core .usecases .base import BaseUseCase
24+ from requests .exceptions import RequestException
2425
2526logger = logging .getLogger ("root" )
2627
@@ -418,7 +419,9 @@ def validate_project_name(self):
418419 def get_annotation_classes_repo (self , project : ProjectEntity ):
419420 return self ._annotation_classes_repo (self ._backend_service , project )
420421
421- def _copy_annotation_classes (self , annotation_classes_entity_mapping : dict , project : ProjectEntity ):
422+ def _copy_annotation_classes (
423+ self , annotation_classes_entity_mapping : dict , project : ProjectEntity
424+ ):
422425 annotation_classes = self .annotation_classes .get_all ()
423426 for annotation_class in annotation_classes :
424427 annotation_class_copy = copy .copy (annotation_class )
@@ -448,42 +451,49 @@ def _copy_settings(self, to_project: ProjectEntity):
448451 setting_copy .project_id = to_project .uuid
449452 new_settings .update (setting_copy )
450453
451- def _copy_workflow (self , annotation_classes_entity_mapping : dict , to_project : ProjectEntity ):
454+ def _copy_workflow (
455+ self , annotation_classes_entity_mapping : dict , to_project : ProjectEntity
456+ ):
452457 new_workflows = self ._workflows_repo (self ._backend_service , to_project )
453458 for workflow in self .workflows .get_all ():
454- existing_workflow_ids = list (
455- map (lambda i : i .uuid , new_workflows .get_all ())
456- )
459+ existing_workflow_ids = list (map (lambda i : i .uuid , new_workflows .get_all ()))
457460 workflow_data = copy .copy (workflow )
458461 workflow_data .project_id = to_project .uuid
459- workflow_data .class_id = annotation_classes_entity_mapping [workflow .class_id ].uuid
462+ workflow_data .class_id = annotation_classes_entity_mapping [
463+ workflow .class_id
464+ ].uuid
460465 new_workflows .insert (workflow_data )
461466 workflows = new_workflows .get_all ()
462- new_workflow = next ((
463- work_flow
464- for work_flow in workflows
465- if work_flow .uuid not in existing_workflow_ids
466- ), None )
467+ new_workflow = next (
468+ (
469+ work_flow
470+ for work_flow in workflows
471+ if work_flow .uuid not in existing_workflow_ids
472+ ),
473+ None ,
474+ )
467475 workflow_attributes = []
468476 for attribute in workflow_data .attribute :
469477 for annotation_attribute in annotation_classes_entity_mapping [
470478 workflow .class_id
471479 ].attribute_groups :
472480 if (
473- attribute ["attribute" ]["attribute_group" ]["name" ]
474- == annotation_attribute ["name" ]
481+ attribute ["attribute" ]["attribute_group" ]["name" ]
482+ == annotation_attribute ["name" ]
475483 ):
476484 for annotation_attribute_value in annotation_attribute [
477485 "attributes"
478486 ]:
479487 if (
480- annotation_attribute_value ["name" ]
481- == attribute ["attribute" ]["name" ]
488+ annotation_attribute_value ["name" ]
489+ == attribute ["attribute" ]["name" ]
482490 ):
483491 workflow_attributes .append (
484492 {
485493 "workflow_id" : new_workflow .uuid ,
486- "attribute_id" : annotation_attribute_value ["id" ]
494+ "attribute_id" : annotation_attribute_value [
495+ "id"
496+ ],
487497 }
488498 )
489499 break
@@ -501,42 +511,70 @@ def execute(self):
501511 f" { constances .ProjectType .get_name (self ._project_to_create .project_type )} ."
502512 )
503513 project = self ._projects .insert (self ._project_to_create )
504-
505514 annotation_classes_entity_mapping = defaultdict (AnnotationClassEntity )
515+ annotation_classes_created = False
506516 if self ._include_annotation_classes :
507517 self .reporter .log_info (
508518 f"Cloning annotation classes from { self ._project .name } to { self ._project_to_create .name } ."
509519 )
510- self ._copy_annotation_classes (annotation_classes_entity_mapping , project )
520+ try :
521+ self ._copy_annotation_classes (
522+ annotation_classes_entity_mapping , project
523+ )
524+ annotation_classes_created = True
525+ except (AppException , RequestException ) as e :
526+ self .reporter .log_warning (
527+ f"Failed to clone annotation classes from { self ._project .name } to { self ._project_to_create .name } ."
528+ )
529+ self .reporter .log_debug (str (e ), exc_info = True )
511530
512531 if self ._include_settings :
513532 self .reporter .log_info (
514533 f"Cloning settings from { self ._project .name } to { self ._project_to_create .name } ."
515534 )
516- self ._copy_settings (project )
517- if (
518- self ._include_workflow
519- and self ._project .upload_state != constances .UploadState .EXTERNAL .value
520- and self ._include_annotation_classes
521- and self ._project .project_type not in (
522- constances .ProjectType .DOCUMENT .value , constances .ProjectType .VIDEO .value
535+ try :
536+ self ._copy_settings (project )
537+ except (AppException , RequestException ) as e :
538+ self .reporter .log_warning (
539+ f"Failed to clone settings from { self ._project .name } to { self ._project_to_create .name } ."
523540 )
524- ):
525- self .reporter .log_info (
526- f"Cloning workflow from { self ._project .name } to { self ._project_to_create .name } ."
527- )
528- self ._copy_workflow (annotation_classes_entity_mapping , project )
529- elif self ._include_workflow :
530- self .reporter .log_warning (
531- "Workflow copy is deprecated for "
532- f"{ constances .ProjectType .get_name (self ._project_to_create .project_type )} projects."
533- )
541+ self .reporter .log_debug (str (e ), exc_info = True )
542+
543+ if self ._include_workflow and self ._include_annotation_classes :
544+ if self ._project .project_type in (
545+ constances .ProjectType .DOCUMENT .value ,
546+ constances .ProjectType .VIDEO .value ,
547+ ):
548+ self .reporter .log_warning (
549+ "Workflow copy is deprecated for "
550+ f"{ constances .ProjectType .get_name (self ._project_to_create .project_type )} projects."
551+ )
552+ elif not annotation_classes_created :
553+ self .reporter .log_info (
554+ f"Skipping the workflow clone from { self ._project .name } to { self ._project_to_create .name } ."
555+ )
556+ else :
557+ self .reporter .log_info (
558+ f"Cloning workflow from { self ._project .name } to { self ._project_to_create .name } ."
559+ )
560+ try :
561+ self ._copy_workflow (annotation_classes_entity_mapping , project )
562+ except (AppException , RequestException ) as e :
563+ self .reporter .log_warning (
564+ f"Failed to workflow from { self ._project .name } to { self ._project_to_create .name } ."
565+ )
566+ self .reporter .log_debug (str (e ), exc_info = True )
534567 if self ._include_contributors :
535568 self .reporter .log_info (
536569 f"Cloning contributors from { self ._project .name } to { self ._project_to_create .name } ."
537570 )
538- self ._copy_include_contributors (project )
539-
571+ try :
572+ self ._copy_include_contributors (project )
573+ except (AppException , RequestException ) as e :
574+ self .reporter .log_warning (
575+ f"Failed to clone contributors from { self ._project .name } to { self ._project_to_create .name } ."
576+ )
577+ self .reporter .log_debug (str (e ), exc_info = True )
540578 self ._response .data = self ._projects .get_one (
541579 uuid = project .uuid , team_id = project .team_id
542580 )
@@ -688,10 +726,12 @@ def validate_image_quality(self):
688726 def validate_project_type (self ):
689727 project = self ._projects .get_one (uuid = self ._project_id , team_id = self ._team_id )
690728 for attribute in self ._to_update :
691- if (
692- attribute .get ("attribute" , "" ) == "ImageQuality"
693- and project .project_type in [constances .ProjectType .VIDEO .value , constances .ProjectType .DOCUMENT .value ]
694- ):
729+ if attribute .get (
730+ "attribute" , ""
731+ ) == "ImageQuality" and project .project_type in [
732+ constances .ProjectType .VIDEO .value ,
733+ constances .ProjectType .DOCUMENT .value ,
734+ ]:
695735 raise AppValidationException (
696736 constances .DEPRICATED_DOCUMENT_VIDEO_MESSAGE
697737 )
0 commit comments