@@ -2710,12 +2710,12 @@ def __init__(
27102710 self ,
27112711 annotation_classes : BaseManageableRepository ,
27122712 annotation_class : AnnotationClassEntity ,
2713- project_name : str ,
2713+ project : ProjectEntity ,
27142714 ):
27152715 super ().__init__ ()
27162716 self ._annotation_classes = annotation_classes
27172717 self ._annotation_class = annotation_class
2718- self ._project_name = project_name
2718+ self ._project = project
27192719
27202720 def validate_uniqueness (self ):
27212721 annotation_classes = self ._annotation_classes .get_all (
@@ -2730,11 +2730,20 @@ def validate_uniqueness(self):
27302730 ):
27312731 raise AppValidationException ("Annotation class already exits." )
27322732
2733+ def validate_project_type (self ):
2734+ if (
2735+ self ._project .project_type != ProjectType .VECTOR .value
2736+ and self ._annotation_class .type == "tag"
2737+ ):
2738+ raise AppException (
2739+ f"Predefined tagging functionality is not supported for projects of type { ProjectType .get_name (self ._project .project_type )} ."
2740+ )
2741+
27332742 def execute (self ):
27342743 if self .is_valid ():
27352744 logger .info (
27362745 "Creating annotation class in project %s with name %s" ,
2737- self ._project_name ,
2746+ self ._project . name ,
27382747 self ._annotation_class .name ,
27392748 )
27402749 created = self ._annotation_classes .insert (entity = self ._annotation_class )
@@ -2840,27 +2849,34 @@ def validate_annotation_classes(self):
28402849 if "attribute_groups" not in self ._annotation_classes :
28412850 raise AppValidationException ("Field attribute_groups is required." )
28422851
2852+ def validate_project_type (self ):
2853+ if self ._project .project_type != ProjectType .VECTOR .value and "tag" in [
2854+ i .type for i in self ._annotation_classes
2855+ ]:
2856+ raise AppException (
2857+ f"Predefined tagging functionality is not supported for projects of type { ProjectType .get_name (self ._project .project_type )} ."
2858+ )
2859+
28432860 def execute (self ):
2844- existing_annotation_classes = self ._annotation_classes_repo .get_all ()
2845- existing_classes_name = [i .name for i in existing_annotation_classes ]
2846- unique_annotation_classes = []
2847- for annotation_class in self ._annotation_classes :
2848- if annotation_class .name in existing_classes_name :
2849- logger .warning (
2850- "Annotation class %s already in project. Skipping." ,
2851- annotation_class .name ,
2861+ if self .is_valid ():
2862+ existing_annotation_classes = self ._annotation_classes_repo .get_all ()
2863+ existing_classes_name = [i .name for i in existing_annotation_classes ]
2864+ unique_annotation_classes = []
2865+ for annotation_class in self ._annotation_classes :
2866+ if annotation_class .name in existing_classes_name :
2867+ logger .warning (
2868+ "Annotation class %s already in project. Skipping." ,
2869+ annotation_class .name ,
2870+ )
2871+ continue
2872+ else :
2873+ unique_annotation_classes .append (annotation_class )
2874+ created = []
2875+ for i in range (len (unique_annotation_classes ) - self .CHUNK_SIZE , 0 , self .CHUNK_SIZE ):
2876+ created += self ._annotation_classes_repo .bulk_insert (
2877+ entities = unique_annotation_classes [i : i + self .CHUNK_SIZE ], # noqa: E203
28522878 )
2853- continue
2854- else :
2855- unique_annotation_classes .append (annotation_class )
2856-
2857- created = []
2858-
2859- for i in range (len (unique_annotation_classes ) - self .CHUNK_SIZE , 0 , self .CHUNK_SIZE ):
2860- created += self ._annotation_classes_repo .bulk_insert (
2861- entities = unique_annotation_classes [i : i + self .CHUNK_SIZE ], # noqa: E203
2862- )
2863- self ._response .data = created
2879+ self ._response .data = created
28642880 return self ._response
28652881
28662882
0 commit comments