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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | 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 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 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 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 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 | CLASS zcl_abapgit_data_deserializer DEFINITION PUBLIC CREATE PRIVATE GLOBAL FRIENDS zcl_abapgit_data_factory . PUBLIC SECTION. INTERFACES zif_abapgit_data_deserializer . PROTECTED SECTION. PRIVATE SECTION. METHODS convert_json_to_itab IMPORTING !is_file TYPE zif_abapgit_git_definitions=>ty_file !ir_data TYPE REF TO data RAISING zcx_abapgit_exception . METHODS preview_database_changes IMPORTING !iv_name TYPE tadir-obj_name !ir_lc_data TYPE REF TO data !ir_db_data TYPE REF TO data RETURNING VALUE(rs_result) TYPE zif_abapgit_data_deserializer=>ty_result RAISING zcx_abapgit_exception. METHODS write_database_table IMPORTING !iv_name TYPE tadir-obj_name !ir_del TYPE REF TO data !ir_ins TYPE REF TO data !ir_upd TYPE REF TO data RAISING zcx_abapgit_exception . METHODS read_database_table IMPORTING !iv_name TYPE tadir-obj_name !it_where TYPE string_table RETURNING VALUE(rr_data) TYPE REF TO data RAISING zcx_abapgit_exception . METHODS determine_transport_request IMPORTING io_repo TYPE REF TO zcl_abapgit_repo iv_transport_type TYPE zif_abapgit_definitions=>ty_transport_type RETURNING VALUE(rv_transport_request) TYPE trkorr. METHODS is_table_allowed_to_edit IMPORTING !is_result TYPE zif_abapgit_data_deserializer=>ty_result RETURNING VALUE(rv_allowed_to_edit) TYPE abap_bool . ENDCLASS. CLASS zcl_abapgit_data_deserializer IMPLEMENTATION. METHOD convert_json_to_itab. DATA lo_ajson TYPE REF TO zcl_abapgit_ajson. DATA lx_ajson TYPE REF TO zcx_abapgit_ajson_error. FIELD-SYMBOLS <lg_tab> TYPE ANY TABLE. ASSIGN ir_data->* TO <lg_tab>. TRY. lo_ajson = zcl_abapgit_ajson=>parse( zcl_abapgit_convert=>xstring_to_string_utf8( is_file-data ) ). lo_ajson->zif_abapgit_ajson~to_abap( IMPORTING ev_container = <lg_tab> ). CATCH zcx_abapgit_ajson_error INTO lx_ajson. zcx_abapgit_exception=>raise( lx_ajson->get_text( ) ). ENDTRY. ENDMETHOD. METHOD determine_transport_request. DATA li_exit TYPE REF TO zif_abapgit_exit. li_exit = zcl_abapgit_exit=>get_instance( ). " Use transport from repo settings if maintained, or determine via user exit. " If transport keeps empty here, it'll requested later via popup. rv_transport_request = io_repo->get_local_settings( )-customizing_request. li_exit->determine_transport_request( EXPORTING io_repo = io_repo iv_transport_type = iv_transport_type CHANGING cv_transport_request = rv_transport_request ). ENDMETHOD. METHOD is_table_allowed_to_edit. " Is the object supported (by default or based on exit)? rv_allowed_to_edit = zcl_abapgit_data_factory=>get_supporter( )->is_object_supported( iv_type = is_result-type iv_name = is_result-name ). ENDMETHOD. METHOD preview_database_changes. * method currently distinguishes between records be deleted and inserted (comparison of complete record) FIELD-SYMBOLS <lg_old> TYPE ANY TABLE. FIELD-SYMBOLS <lg_new> TYPE ANY TABLE. FIELD-SYMBOLS <ls_del> TYPE any. FIELD-SYMBOLS <ls_ins> TYPE any. FIELD-SYMBOLS <lg_del> TYPE ANY TABLE. FIELD-SYMBOLS <lg_ins> TYPE ANY TABLE. FIELD-SYMBOLS <lg_upd> TYPE ANY TABLE. ASSIGN ir_db_data->* TO <lg_old>. ASSIGN ir_lc_data->* TO <lg_new>. rs_result-type = zif_abapgit_data_config=>c_data_type-tabu. rs_result-name = iv_name. rs_result-deletes = zcl_abapgit_data_utils=>build_table_itab( iv_name ). rs_result-inserts = zcl_abapgit_data_utils=>build_table_itab( iv_name ). rs_result-updates = zcl_abapgit_data_utils=>build_table_itab( iv_name ). ASSIGN rs_result-deletes->* TO <lg_del>. ASSIGN rs_result-inserts->* TO <lg_ins>. ASSIGN rs_result-updates->* TO <lg_upd>. <lg_del> = <lg_old>. <lg_ins> = <lg_new>. " Remove identical records LOOP AT <lg_del> ASSIGNING <ls_del>. READ TABLE <lg_ins> ASSIGNING <ls_ins> FROM <ls_del>. IF sy-subrc = 0. IF <ls_del> <> <ls_ins>. " Identical key but not identical component values INSERT <ls_ins> INTO TABLE <lg_upd>. ENDIF. DELETE TABLE <lg_del> FROM <ls_del>. DELETE TABLE <lg_ins> FROM <ls_ins>. ENDIF. ENDLOOP. ENDMETHOD. METHOD read_database_table. DATA lv_where LIKE LINE OF it_where. FIELD-SYMBOLS <lg_tab> TYPE ANY TABLE. rr_data = zcl_abapgit_data_utils=>build_table_itab( iv_name ). ASSIGN rr_data->* TO <lg_tab>. LOOP AT it_where INTO lv_where. SELECT * FROM (iv_name) APPENDING TABLE <lg_tab> WHERE (lv_where) ORDER BY PRIMARY KEY. ENDLOOP. IF lines( it_where ) = 0. SELECT * FROM (iv_name) INTO TABLE <lg_tab> ORDER BY PRIMARY KEY. ENDIF. ENDMETHOD. METHOD write_database_table. FIELD-SYMBOLS <lg_del> TYPE ANY TABLE. FIELD-SYMBOLS <lg_ins> TYPE ANY TABLE. FIELD-SYMBOLS <lg_upd> TYPE ANY TABLE. IF zcl_abapgit_data_utils=>does_table_exist( iv_name ) = abap_false. zcx_abapgit_exception=>raise( |Table { iv_name } not found for data deserialization| ). ENDIF. ASSIGN ir_del->* TO <lg_del>. ASSIGN ir_ins->* TO <lg_ins>. ASSIGN ir_upd->* TO <lg_upd>. IF lines( <lg_del> ) > 0. DELETE (iv_name) FROM TABLE <lg_del>. IF sy-subrc <> 0. zcx_abapgit_exception=>raise( |Error deleting { lines( <lg_del> ) } records from table { iv_name }| ). ENDIF. ENDIF. IF lines( <lg_ins> ) > 0. INSERT (iv_name) FROM TABLE <lg_ins>. IF sy-subrc <> 0. zcx_abapgit_exception=>raise( |Error inserting { lines( <lg_ins> ) } records into table { iv_name }| ). ENDIF. ENDIF. IF lines( <lg_upd> ) > 0. UPDATE (iv_name) FROM TABLE <lg_upd>. IF sy-subrc <> 0. zcx_abapgit_exception=>raise( |Error updating { lines( <lg_upd> ) } records into table { iv_name }| ). ENDIF. ENDIF. ENDMETHOD. METHOD zif_abapgit_data_deserializer~actualize. * this method updates the database DATA ls_result LIKE LINE OF it_result. DATA li_cts_api TYPE REF TO zif_abapgit_cts_api. FIELD-SYMBOLS: <lt_ins> TYPE ANY TABLE, <lt_del> TYPE ANY TABLE, <lt_upd> TYPE ANY TABLE. LOOP AT it_result INTO ls_result. ASSERT ls_result-type = zif_abapgit_data_config=>c_data_type-tabu. " todo ASSERT ls_result-name IS NOT INITIAL. " Did the user flagged this object for update? READ TABLE is_checks-overwrite TRANSPORTING NO FIELDS WITH KEY object_type_and_name COMPONENTS obj_type = ls_result-type obj_name = ls_result-name decision = zif_abapgit_definitions=>c_yes. IF sy-subrc <> 0. CONTINUE. ENDIF. IF is_table_allowed_to_edit( ls_result ) = abap_false. zcx_abapgit_exception=>raise( |Table { ls_result-name } not supported for updating data| ). ENDIF. write_database_table( iv_name = ls_result-name ir_del = ls_result-deletes ir_ins = ls_result-inserts ir_upd = ls_result-updates ). ASSIGN ls_result-inserts->* TO <lt_ins>. ASSIGN ls_result-deletes->* TO <lt_del>. ASSIGN ls_result-updates->* TO <lt_upd>. IF zcl_abapgit_data_utils=>is_customizing_table( ls_result-name ) = abap_true. IF li_cts_api IS INITIAL. li_cts_api = zcl_abapgit_factory=>get_cts_api( ). ENDIF. li_cts_api->create_transport_entries( iv_transport = is_checks-customizing-transport it_table_ins = <lt_ins> it_table_upd = <lt_upd> it_table_del = <lt_del> iv_tabname = |{ ls_result-name }| ). ENDIF. INSERT ls_result-file INTO TABLE rt_accessed_files. " data file INSERT ls_result-config INTO TABLE rt_accessed_files. " config file ENDLOOP. ENDMETHOD. METHOD zif_abapgit_data_deserializer~deserialize. * this method does not persist any changes to the database DATA lt_configs TYPE zif_abapgit_data_config=>ty_config_tt. DATA ls_config LIKE LINE OF lt_configs. DATA lr_lc_data TYPE REF TO data. DATA lr_db_data TYPE REF TO data. DATA ls_file LIKE LINE OF it_files. DATA ls_result LIKE LINE OF rt_result. lt_configs = ii_config->get_configs( ). LOOP AT lt_configs INTO ls_config. ASSERT ls_config-type = zif_abapgit_data_config=>c_data_type-tabu. " todo ASSERT ls_config-name IS NOT INITIAL. lr_lc_data = zcl_abapgit_data_utils=>build_table_itab( ls_config-name ). READ TABLE it_files INTO ls_file WITH KEY file_path COMPONENTS path = zif_abapgit_data_config=>c_default_path filename = zcl_abapgit_data_utils=>build_data_filename( ls_config ). IF sy-subrc = 0. convert_json_to_itab( ir_data = lr_lc_data is_file = ls_file ). lr_db_data = read_database_table( iv_name = ls_config-name it_where = ls_config-where ). ls_result = preview_database_changes( iv_name = ls_config-name ir_lc_data = lr_lc_data ir_db_data = lr_db_data ). MOVE-CORRESPONDING ls_file TO ls_result-file. " data file READ TABLE it_files INTO ls_file WITH KEY file_path COMPONENTS path = zif_abapgit_data_config=>c_default_path filename = zcl_abapgit_data_utils=>build_config_filename( ls_config ). ASSERT sy-subrc = 0. MOVE-CORRESPONDING ls_file TO ls_result-config. " config file INSERT ls_result INTO TABLE rt_result. ENDIF. ENDLOOP. ENDMETHOD. METHOD zif_abapgit_data_deserializer~deserialize_check. DATA lt_configs TYPE zif_abapgit_data_config=>ty_config_tt. lt_configs = ii_config->get_configs( ). IF lt_configs IS NOT INITIAL. rs_checks-required = abap_true. rs_checks-type-request = zif_abapgit_cts_api=>c_transport_type-cust_request. rs_checks-type-task = zif_abapgit_cts_api=>c_transport_type-cust_task. rs_checks-transport = determine_transport_request( io_repo = io_repo iv_transport_type = rs_checks-type ). ENDIF. ENDMETHOD. ENDCLASS. |