101101
102102
103103class ServiceNowListTask (AbstractServiceNowTask ):
104+ OPERATOR_EQUALS = "="
105+ OPERATOR_NOT_EQUALS = "!="
106+ OPERATOR_STARTSWITH = "STARTSWITH"
107+ OPERATOR_ISEMPTY = "ISEMPTY"
108+ OPERATOR_EMPTYSTRING = "EMPTYSTRING"
104109
105110 @classmethod
106111 def all_configs (cls ) -> List [dict ]:
@@ -777,6 +782,9 @@ def validate(
777782 list_info = self ._extract_list_info (page )
778783 current_query = list_info ["query" ]
779784
785+ if not current_query :
786+ return 0 , False , "" , {"message" : "There are no filters yet." }
787+
780788 # Replace "new query" statements with the standard OR separator
781789 current_query = current_query .replace ("^NQ" , "^OR" )
782790
@@ -789,24 +797,74 @@ def validate(
789797 current_sep = "^"
790798
791799 if current_kind != self .filter_kind :
792- return 0 , False , "" , {"message" : "The kind of filter used is incorrect." }
800+ return (
801+ 0 ,
802+ False ,
803+ "" ,
804+ {"message" : f"The kind of filter used is incorrect: { current_query } ." },
805+ )
793806
794807 # Extract the query pieces for validation
795808 current_query = current_query .split (current_sep )
796809
797810 # Validate query length is ok
798811 if len (current_query ) != self .filter_len :
799- return 0 , False , "" , {"message" : "Incorrect number of filter conditions." }
812+ return (
813+ 0 ,
814+ False ,
815+ "" ,
816+ {"message" : f"Incorrect number of filter conditions: { current_query } ." },
817+ )
818+
819+ # Parse column names, operators, and values
820+ current_columns , current_operators , current_values = [], [], []
821+
822+ # Note that this is not exhaustive. If/when other operators are added, this will have to be updated.
823+ for predicate in current_query :
824+ if self .OPERATOR_EMPTYSTRING in predicate :
825+ current_columns .append (predicate .replace (self .OPERATOR_EMPTYSTRING , "" ).strip ())
826+ current_operators .append ("=" )
827+ current_values .append ("" )
828+ elif self .OPERATOR_ISEMPTY in predicate :
829+ current_columns .append (predicate .replace (self .OPERATOR_ISEMPTY , "" ).strip ())
830+ current_operators .append ("=" )
831+ current_values .append ("" )
832+ elif any (
833+ unsupported_operator in predicate
834+ for unsupported_operator in [self .OPERATOR_NOT_EQUALS , self .OPERATOR_STARTSWITH ]
835+ ):
836+ return (
837+ 0 ,
838+ False ,
839+ "" ,
840+ {"message" : f"Unexpected operator in filter condition: { current_query } ." },
841+ )
842+ elif self .OPERATOR_EQUALS in predicate :
843+ col , val = predicate .split (self .OPERATOR_EQUALS , 1 )
844+ current_columns .append (col .strip ())
845+ current_operators .append ("=" )
846+ current_values .append (val .strip ())
847+ else :
848+ return (
849+ 0 ,
850+ False ,
851+ "" ,
852+ {"message" : f"Unexpected operator in filter condition: { current_query } ." },
853+ )
800854
801- # Validate query columns are ok
802- current_columns = [x .split ("=" )[0 ] for x in current_query ]
803855 if set (current_columns ) != set (self .filter_columns ):
804- return 0 , False , "" , {"message" : "Incorrect filter columns." }
856+ return (
857+ 0 ,
858+ False ,
859+ "" ,
860+ {
861+ "message" : f"Incorrect filter columns: { set (current_columns )} . Expected: { set (self .filter_columns )} ."
862+ },
863+ )
805864
806865 # Validate query values are ok
807866 # This is the tricky part because we need to expand the values to their display values
808867 # We also need to handle the case where the value is a reference
809- current_values = [x .split ("=" )[1 ] for x in current_query ]
810868
811869 # Handle filtering across multiple rows
812870 if len (set (current_columns )) < len (current_columns ):
@@ -856,9 +914,21 @@ def validate(
856914
857915 # Validate the values
858916 if set (current_values ) != set (self .filter_values ):
859- return 0 , False , "" , {"message" : "Incorrect filter values." }
917+ return (
918+ 0 ,
919+ False ,
920+ "" ,
921+ {
922+ "message" : f"Incorrect filter values { set (current_values )} . Expected: { set (self .filter_values )} ."
923+ },
924+ )
860925
861- return 1 , True , "Nice work, thank you!" , {"message" : "Correct filter." }
926+ return (
927+ 1 ,
928+ True ,
929+ "Nice work, thank you!" ,
930+ {"message" : f"Correct filter: { list_info ['query' ]} ." },
931+ )
862932
863933
864934class ExtractListInfoTask (ServiceNowListTask ):
0 commit comments