All files / src/apack zcl_abapgit_apack_helper.clas.abap

100% Statements 400/400
100% Branches 0/0
100% Functions 0/0
100% Lines 400/400

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 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 4011x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS zcl_abapgit_apack_helper DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .
 
  PUBLIC SECTION.
 
    CLASS-METHODS are_dependencies_met
      IMPORTING
        !it_dependencies TYPE zif_abapgit_apack_definitions=>ty_dependencies
      RETURNING
        VALUE(rv_status) TYPE zif_abapgit_definitions=>ty_yes_no
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS dependencies_popup
      IMPORTING
        !it_dependencies TYPE zif_abapgit_apack_definitions=>ty_dependencies
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS to_file
      IMPORTING
        !iv_package    TYPE devclass
      RETURNING
        VALUE(rs_file) TYPE zif_abapgit_git_definitions=>ty_file
      RAISING
        zcx_abapgit_exception .
 
    CLASS-METHODS get_manifest_implementations
      RETURNING
        VALUE(rt_manifest_implementations) TYPE zif_abapgit_apack_definitions=>ty_manifest_declarations.
 
  PROTECTED SECTION.
  PRIVATE SECTION.
 
    TYPES:
      BEGIN OF ty_dependency_status,
        met TYPE zif_abapgit_definitions=>ty_yes_no_partial.
        INCLUDE TYPE zif_abapgit_apack_definitions=>ty_dependency.
    TYPES: END OF ty_dependency_status .
    TYPES:
      ty_dependency_statuses TYPE STANDARD TABLE OF ty_dependency_status WITH NON-UNIQUE DEFAULT KEY .
    TYPES:
      BEGIN OF ty_color_line,
        exception(1) TYPE c,
        color        TYPE lvc_t_scol.
        INCLUDE TYPE ty_dependency_status.
    TYPES: t_hyperlink  TYPE salv_t_int4_column,
      END OF ty_color_line.
 
    TYPES: ty_color_tab TYPE STANDARD TABLE OF ty_color_line WITH DEFAULT KEY.
 
    CLASS-METHODS get_dependencies_met_status
      IMPORTING
        !it_dependencies TYPE zif_abapgit_apack_definitions=>ty_dependencies
      RETURNING
        VALUE(rt_status) TYPE ty_dependency_statuses
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS get_installed_packages
      RETURNING
        VALUE(rt_packages) TYPE zif_abapgit_apack_definitions=>ty_descriptors
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS show_dependencies_popup
      IMPORTING
        !it_dependencies TYPE ty_dependency_statuses
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS get_color_table
      IMPORTING
        !io_alv          TYPE REF TO cl_salv_table
        !it_dependencies TYPE ty_dependency_statuses
      CHANGING
        !ct_color_table  TYPE ty_color_tab
      RAISING
        cx_salv_existing.
ENDCLASS.
 
 
 
CLASS zcl_abapgit_apack_helper IMPLEMENTATION.
 
 
  METHOD are_dependencies_met.
 
    DATA: lt_dependencies_status TYPE ty_dependency_statuses.
 
    IF it_dependencies IS INITIAL.
      rv_status = zif_abapgit_definitions=>c_yes.
      RETURN.
    ENDIF.
 
    lt_dependencies_status = get_dependencies_met_status( it_dependencies ).
 
    LOOP AT lt_dependencies_status TRANSPORTING NO FIELDS WHERE met <> zif_abapgit_definitions=>c_yes.
      EXIT.
    ENDLOOP.
 
    IF sy-subrc = 0.
      rv_status = zif_abapgit_definitions=>c_no.
    ELSE.
      rv_status = zif_abapgit_definitions=>c_yes.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD dependencies_popup.
 
    DATA: lt_met_status TYPE ty_dependency_statuses,
          lv_answer     TYPE c LENGTH 1.
 
    lt_met_status = get_dependencies_met_status( it_dependencies ).
 
    show_dependencies_popup( lt_met_status ).
 
    lv_answer = zcl_abapgit_ui_factory=>get_popups( )->popup_to_confirm(
      iv_titlebar      = 'Warning'
      iv_text_question = 'The project has unmet dependencies. Do you want to continue?' ).
 
    IF lv_answer <> '1'.
      zcx_abapgit_exception=>raise( 'Cancelling because of unmet dependencies.' ).
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD get_color_table.
 
    DATA:
      lo_functional_settings TYPE REF TO cl_salv_functional_settings,
      lo_hyperlinks          TYPE REF TO cl_salv_hyperlinks,
      lt_color_negative      TYPE lvc_t_scol,
      lt_color_normal        TYPE lvc_t_scol,
      lt_color_positive      TYPE lvc_t_scol,
      ls_color               TYPE lvc_s_scol,
      lv_handle              TYPE i,
      ls_hyperlink           TYPE salv_s_int4_column,
      lv_hyperlink           TYPE service_rl.
 
    FIELD-SYMBOLS:
      <ls_line>       TYPE ty_color_line,
      <ls_dependency> LIKE LINE OF it_dependencies.
 
    CLEAR: ls_color.
    ls_color-color-col = col_negative.
    APPEND ls_color TO lt_color_negative.
 
    CLEAR: ls_color.
    ls_color-color-col = col_normal.
    APPEND ls_color TO lt_color_normal.
 
    CLEAR: ls_color.
    ls_color-color-col = col_positive.
    APPEND ls_color TO lt_color_positive.
 
    lo_functional_settings = io_alv->get_functional_settings( ).
    lo_hyperlinks = lo_functional_settings->get_hyperlinks( ).
 
    CLEAR: lv_handle, ls_color.
    LOOP AT it_dependencies ASSIGNING <ls_dependency>.
      lv_handle = lv_handle + 1.
 
      APPEND INITIAL LINE TO ct_color_table ASSIGNING <ls_line>.
      MOVE-CORRESPONDING <ls_dependency> TO <ls_line>.
 
      CASE <ls_line>-met.
        WHEN zif_abapgit_definitions=>c_yes.
          <ls_line>-color     = lt_color_positive.
          <ls_line>-exception = '3'.
        WHEN zif_abapgit_definitions=>c_partial.
          <ls_line>-color     = lt_color_normal.
          <ls_line>-exception = '2'.
        WHEN zif_abapgit_definitions=>c_no.
          <ls_line>-color     = lt_color_negative.
          <ls_line>-exception = '1'.
      ENDCASE.
 
      CLEAR: ls_hyperlink.
      ls_hyperlink-columnname = 'GIT_URL'.
      ls_hyperlink-value      = lv_handle.
      APPEND ls_hyperlink TO <ls_line>-t_hyperlink.
 
      lv_hyperlink = <ls_line>-git_url.
      lo_hyperlinks->add_hyperlink( handle    = lv_handle
                                    hyperlink = lv_hyperlink ).
 
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD get_dependencies_met_status.
 
    DATA: lt_installed_packages TYPE zif_abapgit_apack_definitions=>ty_descriptors,
          ls_installed_package  TYPE zif_abapgit_apack_definitions=>ty_descriptor,
          ls_dependecy          TYPE zif_abapgit_apack_definitions=>ty_dependency,
          ls_dependecy_popup    TYPE ty_dependency_status.
 
    IF it_dependencies IS INITIAL.
      RETURN.
    ENDIF.
 
    lt_installed_packages = get_installed_packages( ).
 
    LOOP AT it_dependencies INTO ls_dependecy.
      CLEAR: ls_dependecy_popup.
 
      MOVE-CORRESPONDING ls_dependecy TO ls_dependecy_popup.
 
      READ TABLE lt_installed_packages INTO ls_installed_package
        WITH KEY group_id    = ls_dependecy-group_id
                 artifact_id = ls_dependecy-artifact_id.
      IF sy-subrc <> 0.
        ls_dependecy_popup-met = zif_abapgit_definitions=>c_no.
      ELSE.
        TRY.
            zcl_abapgit_version=>check_dependant_version( is_current   = ls_installed_package-sem_version
                                                          is_dependant = ls_dependecy-sem_version ).
            ls_dependecy_popup-met = zif_abapgit_definitions=>c_yes.
          CATCH zcx_abapgit_exception.
            ls_dependecy_popup-met = zif_abapgit_definitions=>c_partial.
        ENDTRY.
      ENDIF.
 
      INSERT ls_dependecy_popup INTO TABLE rt_status.
 
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD get_installed_packages.
 
    DATA: lo_apack_reader            TYPE REF TO zcl_abapgit_apack_reader,
          lt_manifest_implementation TYPE zif_abapgit_apack_definitions=>ty_manifest_declarations,
          ls_manifest_implementation TYPE zif_abapgit_apack_definitions=>ty_manifest_declaration,
          lo_manifest_provider       TYPE REF TO object,
          ls_descriptor              TYPE zif_abapgit_apack_definitions=>ty_descriptor.
 
    lt_manifest_implementation = get_manifest_implementations( ).
 
    LOOP AT lt_manifest_implementation INTO ls_manifest_implementation.
      CLEAR: lo_manifest_provider, lo_apack_reader.
 
      TRY.
          CREATE OBJECT lo_manifest_provider TYPE (ls_manifest_implementation-clsname).
        CATCH cx_sy_create_object_error.
          CLEAR: lo_manifest_provider.
      ENDTRY.
 
      IF lo_manifest_provider IS NOT BOUND.
        CONTINUE.
      ENDIF.
 
      lo_apack_reader = zcl_abapgit_apack_reader=>create_instance( ls_manifest_implementation-devclass ).
      lo_apack_reader->copy_manifest_descriptor( lo_manifest_provider ).
      ls_descriptor = lo_apack_reader->get_manifest_descriptor( ).
 
      IF ls_descriptor IS NOT INITIAL.
        INSERT ls_descriptor INTO TABLE rt_packages.
      ENDIF.
 
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD get_manifest_implementations.
 
    DATA lt_refclsname TYPE RANGE OF abap_classname.
    DATA ls_refclsname LIKE LINE OF lt_refclsname.
 
    ls_refclsname-sign   = 'I'.
    ls_refclsname-option = 'EQ'.
    ls_refclsname-low    = zif_abapgit_apack_definitions=>c_apack_interface_cust.
    INSERT ls_refclsname INTO TABLE lt_refclsname.
 
    ls_refclsname-sign   = 'I'.
    ls_refclsname-option = 'EQ'.
    ls_refclsname-low    = zif_abapgit_apack_definitions=>c_apack_interface_sap.
    INSERT ls_refclsname INTO TABLE lt_refclsname.
 
    ls_refclsname-sign   = 'I'.
    ls_refclsname-option = 'CP'.
    ls_refclsname-low    = zif_abapgit_apack_definitions=>c_apack_interface_nspc.
    INSERT ls_refclsname INTO TABLE lt_refclsname.
 
    " Find all classes that implement customer or SAP version of APACK interface
    SELECT seometarel~clsname tadir~devclass FROM seometarel "#EC CI_NOORDER
      INNER JOIN tadir ON seometarel~clsname = tadir~obj_name "#EC CI_BUFFJOIN
      INTO TABLE rt_manifest_implementations
      WHERE tadir~pgmid           = 'R3TR'
        AND tadir~object          = 'CLAS'
        AND seometarel~version    = '1'
        AND seometarel~refclsname IN lt_refclsname
       ORDER BY clsname devclass ##SUBRC_OK.
 
  ENDMETHOD.
 
 
  METHOD show_dependencies_popup.
 
    DATA: lo_alv          TYPE REF TO cl_salv_table,
          lo_column       TYPE REF TO cl_salv_column,
          lo_column_table TYPE REF TO cl_salv_column_table,
          lo_columns      TYPE REF TO cl_salv_columns_table,
          lt_columns      TYPE salv_t_column_ref,
          ls_column       LIKE LINE OF lt_columns,
          lt_color_table  TYPE ty_color_tab,
          ls_position     TYPE zif_abapgit_popups=>ty_popup_position,
          lx_ex           TYPE REF TO cx_root.
 
    IF it_dependencies IS INITIAL.
      RETURN.
    ENDIF.
 
    TRY.
        cl_salv_table=>factory( IMPORTING r_salv_table  = lo_alv
                                CHANGING  t_table       = lt_color_table ).
 
        lo_columns = lo_alv->get_columns( ).
        lt_columns = lo_columns->get( ).
        LOOP AT lt_columns INTO ls_column WHERE columnname CP 'SEM_VERSION-*'.
          ls_column-r_column->set_technical( ).
        ENDLOOP.
 
        lo_column = lo_columns->get_column( 'MET' ).
        lo_column->set_technical( ).
 
        lo_column = lo_columns->get_column( 'GROUP_ID' ).
        lo_column->set_short_text( 'Org/ProjId' ).
 
        lo_columns->set_color_column( 'COLOR' ).
        lo_columns->set_exception_column( 'EXCEPTION' ).
        lo_columns->set_hyperlink_entry_column( 'T_HYPERLINK' ).
        lo_columns->set_optimize( ).
 
        lo_column = lo_columns->get_column( 'GROUP_ID' ).
        lo_column->set_short_text( 'Org/ProjId' ).
 
        lo_column = lo_columns->get_column( 'ARTIFACT_ID' ).
        lo_column->set_short_text( 'Proj. Name' ).
 
        lo_column = lo_columns->get_column( 'GIT_URL' ).
        lo_column->set_short_text( 'Git URL' ).
 
        lo_column_table ?= lo_column.
        lo_column_table->set_cell_type( if_salv_c_cell_type=>link ).
 
        lo_column = lo_columns->get_column( 'VERSION' ).
        lo_column->set_short_text( 'Version' ).
 
        lo_column = lo_columns->get_column( 'TARGET_PACKAGE' ).
        lo_column->set_technical( ).
 
        get_color_table(
          EXPORTING
            io_alv          = lo_alv
            it_dependencies = it_dependencies
          CHANGING
            ct_color_table  = lt_color_table ).
 
        ls_position = zcl_abapgit_popups=>center(
          iv_width  = 90
          iv_height = 10 ).
 
        lo_alv->set_screen_popup( start_column = ls_position-start_column
                                  end_column   = ls_position-end_column
                                  start_line   = ls_position-start_row
                                  end_line     = ls_position-end_row ).
 
        lo_alv->get_display_settings( )->set_list_header( 'APACK dependencies' ).
        lo_alv->display( ).
 
      CATCH cx_salv_msg cx_salv_not_found cx_salv_data_error cx_salv_existing INTO lx_ex.
        zcx_abapgit_exception=>raise( lx_ex->get_text( ) ).
    ENDTRY.
 
  ENDMETHOD.
 
 
  METHOD to_file.
 
    DATA: lo_manifest_reader TYPE REF TO zcl_abapgit_apack_reader,
          ls_descriptor      TYPE zif_abapgit_apack_definitions=>ty_descriptor,
          lo_manifest_writer TYPE REF TO zcl_abapgit_apack_writer.
 
    lo_manifest_reader = zcl_abapgit_apack_reader=>create_instance( iv_package ).
    IF lo_manifest_reader->has_manifest( ) = abap_true.
      ls_descriptor = lo_manifest_reader->get_manifest_descriptor( ).
      lo_manifest_writer = zcl_abapgit_apack_writer=>create_instance( ls_descriptor ).
      rs_file-path     = zif_abapgit_definitions=>c_root_dir.
      rs_file-filename = zif_abapgit_apack_definitions=>c_dot_apack_manifest.
      rs_file-data     = zcl_abapgit_convert=>string_to_xstring_utf8( lo_manifest_writer->serialize( ) ).
      rs_file-sha1     = zcl_abapgit_hash=>sha1_blob( rs_file-data ).
    ENDIF.
 
  ENDMETHOD.
ENDCLASS.