All files / src/json zcl_abapgit_ajson_filter_lib.clas.locals_imp.abap

96.52% Statements 139/144
80% Branches 8/10
0% Functions 0/1
96.52% Lines 139/144

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 1451x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 11x 3x 3x 3x 11x 11x 29x 29x 29x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 3x 3x 3x       3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
**********************************************************************
*  FILTER EMPTY VALUES
**********************************************************************
 
CLASS lcl_empty_filter DEFINITION FINAL.
  PUBLIC SECTION.
    INTERFACES zif_abapgit_ajson_filter.
ENDCLASS.
 
CLASS lcl_empty_filter IMPLEMENTATION.
  METHOD zif_abapgit_ajson_filter~keep_node.
 
    rv_keep = boolc(
      ( iv_visit = zif_abapgit_ajson_filter=>visit_type-value AND is_node-value IS NOT INITIAL ) OR
      ( iv_visit <> zif_abapgit_ajson_filter=>visit_type-value AND is_node-children > 0 ) ).
    " children = 0 on open for initially empty nodes and on close for filtered ones
 
  ENDMETHOD.
ENDCLASS.
 
**********************************************************************
*  FILTER PREDEFINED PATHS
**********************************************************************
 
CLASS lcl_paths_filter DEFINITION FINAL.
  PUBLIC SECTION.
    INTERFACES zif_abapgit_ajson_filter.
    METHODS constructor
      IMPORTING
        it_skip_paths     TYPE string_table OPTIONAL
        iv_skip_paths     TYPE string OPTIONAL
        iv_pattern_search TYPE abap_bool
      RAISING
        zcx_abapgit_ajson_error.
  PRIVATE SECTION.
    DATA mt_skip_paths TYPE HASHED TABLE OF string WITH UNIQUE KEY table_line.
    DATA mv_pattern_search TYPE abap_bool.
ENDCLASS.
 
CLASS lcl_paths_filter IMPLEMENTATION.
 
  METHOD zif_abapgit_ajson_filter~keep_node.
 
    DATA lv_full_path TYPE string.
    FIELD-SYMBOLS <p> LIKE LINE OF mt_skip_paths.
 
    lv_full_path = is_node-path && is_node-name.
 
    IF mv_pattern_search = abap_true.
      rv_keep = abap_true.
      LOOP AT mt_skip_paths ASSIGNING <p>.
        IF lv_full_path CP <p>.
          rv_keep = abap_false.
          EXIT.
        ENDIF.
      ENDLOOP.
    ELSE.
      READ TABLE mt_skip_paths WITH KEY table_line = lv_full_path TRANSPORTING NO FIELDS.
      rv_keep = boolc( sy-subrc <> 0 ).
    ENDIF.
 
  ENDMETHOD.
 
  METHOD constructor.
 
    DATA lv_s TYPE string.
    DATA lt_tab TYPE string_table.
    FIELD-SYMBOLS <s> TYPE string.
 
    IF boolc( iv_skip_paths IS INITIAL ) = boolc( it_skip_paths IS INITIAL ). " XOR
      zcx_abapgit_ajson_error=>raise( 'no filter path specified' ).
    ENDIF.
 
    LOOP AT it_skip_paths INTO lv_s.
      lv_s = to_lower( lv_s ).
      APPEND lv_s TO lt_tab.
    ENDLOOP.
 
    IF iv_skip_paths IS NOT INITIAL.
      SPLIT iv_skip_paths AT ',' INTO TABLE lt_tab.
      LOOP AT lt_tab ASSIGNING <s>.
        IF <s> IS INITIAL.
          DELETE lt_tab INDEX sy-tabix.
          CONTINUE.
        ENDIF.
        <s> = condense( to_lower( <s> ) ).
      ENDLOOP.
    ENDIF.
 
    SORT lt_tab BY table_line.
    DELETE ADJACENT DUPLICATES FROM lt_tab.
 
    mt_skip_paths = lt_tab.
    mv_pattern_search = iv_pattern_search.
 
  ENDMETHOD.
 
ENDCLASS.
 
**********************************************************************
* MULTI FILTER
**********************************************************************
 
CLASS lcl_and_filter DEFINITION FINAL.
  PUBLIC SECTION.
    INTERFACES zif_abapgit_ajson_filter.
    METHODS constructor
      IMPORTING
        it_filters TYPE zif_abapgit_ajson_filter=>ty_filter_tab
      RAISING
        zcx_abapgit_ajson_error.
  PRIVATE SECTION.
    DATA mt_filters TYPE zif_abapgit_ajson_filter=>ty_filter_tab.
ENDCLASS.
 
CLASS lcl_and_filter IMPLEMENTATION.
 
  METHOD zif_abapgit_ajson_filter~keep_node.
 
    DATA li_filter LIKE LINE OF mt_filters.
 
    rv_keep = abap_true.
    LOOP AT mt_filters INTO li_filter.
      rv_keep = li_filter->keep_node(
        is_node  = is_node
        iv_visit = iv_visit ).
      IF rv_keep = abap_false.
        RETURN.
      ENDIF.
    ENDLOOP.
 
  ENDMETHOD.
 
  METHOD constructor.
 
    DATA li_filter LIKE LINE OF it_filters.
 
    LOOP AT it_filters INTO li_filter WHERE table_line IS BOUND.
      APPEND li_filter TO mt_filters.
    ENDLOOP.
 
  ENDMETHOD.
 
ENDCLASS.