Skip to content

Instantly share code, notes, and snippets.

@mbtools
Created November 2, 2021 23:43
Show Gist options
  • Save mbtools/dac02e5b5582c7d099f6d65db70311cb to your computer and use it in GitHub Desktop.
Save mbtools/dac02e5b5582c7d099f6d65db70311cb to your computer and use it in GitHub Desktop.
SRVB
CLASS zcl_abapgit_object_srvb DEFINITION PUBLIC INHERITING FROM zcl_abapgit_objects_super FINAL.
PUBLIC SECTION.
INTERFACES zif_abapgit_object.
ALIASES mo_files FOR zif_abapgit_object~mo_files.
METHODS:
constructor
IMPORTING
is_item TYPE zif_abapgit_definitions=>ty_item
iv_language TYPE spras
RAISING
zcx_abapgit_exception.
PROTECTED SECTION.
PRIVATE SECTION.
DATA mi_persistence TYPE REF TO if_wb_object_persist .
DATA mv_service_binding_key TYPE seu_objkey .
DATA mr_service_binding TYPE REF TO data .
DATA mr_srvb_svrs_config TYPE REF TO object .
DATA mo_object_operator TYPE REF TO object .
METHODS clear_fields
CHANGING
!cs_service_binding TYPE any .
METHODS clear_field
IMPORTING
!iv_fieldname TYPE csequence
CHANGING
!cs_service_binding TYPE any .
METHODS get_transport_req_if_needed
IMPORTING
!iv_package TYPE devclass
RETURNING
VALUE(rv_transport_request) TYPE trkorr
RAISING
zcx_abapgit_exception .
METHODS get_wb_object_operator
RETURNING
VALUE(ro_object_operator) TYPE REF TO object
RAISING
zcx_abapgit_exception .
METHODS merge_object_data
IMPORTING
!io_object_data TYPE REF TO object
RETURNING
VALUE(ro_object_data_merged) TYPE REF TO if_wb_object_data_model
RAISING
zcx_abapgit_exception .
METHODS get_object_data
IMPORTING
!io_xml TYPE REF TO zif_abapgit_xml_input
RETURNING
VALUE(ro_object_data) TYPE REF TO if_wb_object_data_model
RAISING
zcx_abapgit_exception .
ENDCLASS.
CLASS ZCL_ABAPGIT_OBJECT_SRVB IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_ABAPGIT_OBJECT_SRVB->CLEAR_FIELD
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_FIELDNAME TYPE CSEQUENCE
* | [<-->] CS_SERVICE_BINDING TYPE ANY
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD clear_field.
FIELD-SYMBOLS: <lv_value> TYPE data.
ASSIGN COMPONENT iv_fieldname OF STRUCTURE cs_service_binding
TO <lv_value>.
ASSERT sy-subrc = 0.
CLEAR: <lv_value>.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_ABAPGIT_OBJECT_SRVB->CLEAR_FIELDS
* +-------------------------------------------------------------------------------------------------+
* | [<-->] CS_SERVICE_BINDING TYPE ANY
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD clear_fields.
clear_field(
EXPORTING
iv_fieldname = 'METADATA-VERSION'
CHANGING
cs_service_binding = cs_service_binding ).
clear_field(
EXPORTING
iv_fieldname = 'METADATA-CREATED_AT'
CHANGING
cs_service_binding = cs_service_binding ).
clear_field(
EXPORTING
iv_fieldname = 'METADATA-CREATED_BY'
CHANGING
cs_service_binding = cs_service_binding ).
clear_field(
EXPORTING
iv_fieldname = 'METADATA-CHANGED_AT'
CHANGING
cs_service_binding = cs_service_binding ).
clear_field(
EXPORTING
iv_fieldname = 'METADATA-CHANGED_BY'
CHANGING
cs_service_binding = cs_service_binding ).
clear_field(
EXPORTING
iv_fieldname = 'METADATA-LANGUAGE'
CHANGING
cs_service_binding = cs_service_binding ).
clear_field(
EXPORTING
iv_fieldname = 'METADATA-PACKAGE_REF'
CHANGING
cs_service_binding = cs_service_binding ).
clear_field(
EXPORTING
iv_fieldname = 'METADATA-MASTER_SYSTEM'
CHANGING
cs_service_binding = cs_service_binding ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* | [--->] IS_ITEM TYPE ZIF_ABAPGIT_DEFINITIONS=>TY_ITEM
* | [--->] IV_LANGUAGE TYPE SPRAS
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD constructor.
super->constructor(
is_item = is_item
iv_language = iv_language ).
mv_service_binding_key = ms_item-obj_name.
TRY.
CREATE DATA mr_service_binding TYPE ('CL_SRVB_OBJECT_DATA=>TY_OBJECT_DATA').
CREATE OBJECT mi_persistence TYPE ('CL_SRVB_OBJECT_PERSIST').
CATCH cx_sy_create_error.
zcx_abapgit_exception=>raise( |SRVB not supported by your NW release| ).
ENDTRY.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_ABAPGIT_OBJECT_SRVB->GET_OBJECT_DATA
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_XML TYPE REF TO ZIF_ABAPGIT_XML_INPUT
* | [<-()] RO_OBJECT_DATA TYPE REF TO IF_WB_OBJECT_DATA_MODEL
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_object_data.
FIELD-SYMBOLS:
<ls_service_binding> TYPE any,
<lv_language> TYPE data.
ASSIGN mr_service_binding->* TO <ls_service_binding>.
ASSERT sy-subrc = 0.
io_xml->read(
EXPORTING
iv_name = 'SRVB'
CHANGING
cg_data = <ls_service_binding> ).
" We have to set the language explicitly,
" because otherwise the description isn't stored
ASSIGN COMPONENT 'METADATA-LANGUAGE' OF STRUCTURE <ls_service_binding>
TO <lv_language>.
ASSERT sy-subrc = 0.
<lv_language> = mv_language.
CREATE OBJECT ro_object_data TYPE ('CL_SRVB_OBJECT_DATA').
ro_object_data->set_data( p_data = <ls_service_binding> ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_ABAPGIT_OBJECT_SRVB->GET_TRANSPORT_REQ_IF_NEEDED
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_PACKAGE TYPE DEVCLASS
* | [<-()] RV_TRANSPORT_REQUEST TYPE TRKORR
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_transport_req_if_needed.
DATA: li_sap_package TYPE REF TO zif_abapgit_sap_package.
li_sap_package = zcl_abapgit_factory=>get_sap_package( iv_package ).
IF li_sap_package->are_changes_recorded_in_tr_req( ) = abap_true.
rv_transport_request = zcl_abapgit_default_transport=>get_instance( )->get( )-ordernum.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_ABAPGIT_OBJECT_SRVB->GET_WB_OBJECT_OPERATOR
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RO_OBJECT_OPERATOR TYPE REF TO OBJECT
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_wb_object_operator.
DATA:
ls_object_type TYPE wbobjtype,
lx_error TYPE REF TO cx_root.
IF mo_object_operator IS BOUND.
ro_object_operator = mo_object_operator.
ENDIF.
ls_object_type-objtype_tr = 'SRVB'.
ls_object_type-subtype_wb = 'SVB'.
TRY.
CALL METHOD ('CL_WB_OBJECT_OPERATOR')=>('CREATE_INSTANCE')
EXPORTING
object_type = ls_object_type
object_key = mv_service_binding_key
RECEIVING
result = mo_object_operator.
CATCH cx_root INTO lx_error.
zcx_abapgit_exception=>raise_with_text( lx_error ).
ENDTRY.
ro_object_operator = mo_object_operator.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_ABAPGIT_OBJECT_SRVB->MERGE_OBJECT_DATA
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_OBJECT_DATA TYPE REF TO OBJECT
* | [<-()] RO_OBJECT_DATA_MERGED TYPE REF TO IF_WB_OBJECT_DATA_MODEL
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD merge_object_data.
DATA:
lo_object_data TYPE REF TO object,
lo_object_data_old TYPE REF TO if_wb_object_data_model,
lr_new TYPE REF TO data,
lr_old TYPE REF TO data,
lo_wb_object_operator TYPE REF TO object.
FIELD-SYMBOLS:
<ls_new> TYPE any,
<ls_old> TYPE any,
<lv_field_old> TYPE any,
<lv_field_new> TYPE any.
CREATE OBJECT lo_object_data TYPE ('CL_SRVB_OBJECT_DATA').
lo_object_data = io_object_data.
CREATE DATA lr_new TYPE ('CL_SRVB_OBJECT_DATA=>TY_OBJECT_DATA').
ASSIGN lr_new->* TO <ls_new>.
ASSERT sy-subrc = 0.
CREATE DATA lr_old TYPE ('CL_SRVB_OBJECT_DATA=>TY_OBJECT_DATA').
ASSIGN lr_old->* TO <ls_old>.
ASSERT sy-subrc = 0.
CALL METHOD lo_object_data->('IF_WB_OBJECT_DATA_MODEL~GET_DATA')
EXPORTING
p_metadata_only = abap_false
p_data_selection = 'AL'
IMPORTING
p_data = <ls_new>.
lo_wb_object_operator = get_wb_object_operator( ).
CALL METHOD lo_wb_object_operator->('IF_WB_OBJECT_OPERATOR~READ')
EXPORTING
data_selection = 'AL' " if_wb_object_data_selection_co=>c_all_data
IMPORTING
eo_object_data = lo_object_data_old.
CALL METHOD lo_object_data_old->('GET_DATA')
EXPORTING
p_metadata_only = abap_false
p_data_selection = 'AL' " if_wb_object_data_selection_co=>c_all_data
IMPORTING
p_data = <ls_old>.
ASSIGN COMPONENT 'METADATA-DESCRIPTION' OF STRUCTURE <ls_old> TO <lv_field_old>.
ASSIGN COMPONENT 'METADATA-DESCRIPTION' OF STRUCTURE <ls_new> TO <lv_field_new>.
<lv_field_old> = <lv_field_new>.
CREATE OBJECT ro_object_data_merged TYPE ('CL_SRVB_OBJECT_DATA').
CALL METHOD ro_object_data_merged->('SET_DATA')
EXPORTING
p_data = <ls_old>.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->ZIF_ABAPGIT_OBJECT~CHANGED_BY
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RV_USER TYPE XUBNAME
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_abapgit_object~changed_by.
DATA:
li_object_data_model TYPE REF TO if_wb_object_data_model.
TRY.
mi_persistence->get(
EXPORTING
p_object_key = mv_service_binding_key
p_version = 'A'
CHANGING
p_object_data = li_object_data_model ).
rv_user = li_object_data_model->get_changed_by( ).
CATCH cx_swb_exception.
rv_user = c_user_unknown.
ENDTRY.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->ZIF_ABAPGIT_OBJECT~DELETE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_PACKAGE TYPE DEVCLASS
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_abapgit_object~delete.
DATA: lx_error TYPE REF TO cx_swb_exception.
TRY.
mi_persistence->delete( mv_service_binding_key ).
CATCH cx_swb_exception INTO lx_error.
CALL FUNCTION 'DEQUEUE_ESWB_EO'
EXPORTING
objtype = ms_item-obj_type
objname = ms_item-obj_name.
zcx_abapgit_exception=>raise_with_text( lx_error ).
ENDTRY.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->ZIF_ABAPGIT_OBJECT~DESERIALIZE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_PACKAGE TYPE DEVCLASS
* | [--->] IO_XML TYPE REF TO ZIF_ABAPGIT_XML_INPUT
* | [--->] IV_STEP TYPE ZIF_ABAPGIT_DEFINITIONS=>TY_DESERIALIZATION_STEP
* | [--->] II_LOG TYPE REF TO ZIF_ABAPGIT_LOG
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_abapgit_object~deserialize.
DATA:
lo_object_data TYPE REF TO if_wb_object_data_model,
lx_error TYPE REF TO cx_root,
lv_transport_request TYPE trkorr,
lo_wb_object_operator TYPE REF TO object,
lo_merged_data_all TYPE REF TO if_wb_object_data_model.
TRY.
lo_object_data = get_object_data( io_xml ).
lv_transport_request = get_transport_req_if_needed( iv_package ).
lo_wb_object_operator = get_wb_object_operator( ).
tadir_insert( iv_package ).
IF zif_abapgit_object~exists( ) = abap_false.
"if_wb_adt_plugin_resource_co=>co_sfs_res_category_atomic.
CALL METHOD lo_wb_object_operator->('IF_WB_OBJECT_OPERATOR~CREATE')
EXPORTING
io_object_data = lo_object_data
data_selection = 'AL' "if_wb_object_data_selection_co=>c_all_data
version = 'I'
package = iv_package
transport_request = lv_transport_request.
ELSE.
lo_merged_data_all = merge_object_data( lo_object_data ).
CALL METHOD lo_wb_object_operator->('IF_WB_OBJECT_OPERATOR~UPDATE')
EXPORTING
io_object_data = lo_merged_data_all
data_selection = 'AL' "if_wb_object_data_selection_co=>c_all_data
version = 'I'
transport_request = lv_transport_request.
ENDIF.
corr_insert( iv_package ).
CATCH cx_root INTO lx_error.
CALL FUNCTION 'DEQUEUE_ESWB_EO'
EXPORTING
objtype = ms_item-obj_type
objname = ms_item-obj_name.
zcx_abapgit_exception=>raise_with_text( lx_error ).
ENDTRY.
zcl_abapgit_objects_activation=>add_item( ms_item ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->ZIF_ABAPGIT_OBJECT~EXISTS
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RV_BOOL TYPE ABAP_BOOL
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_abapgit_object~exists.
DATA lo_object_data TYPE REF TO if_wb_object_data_model.
DATA lo_wb_object_operator TYPE REF TO object.
lo_wb_object_operator = get_wb_object_operator( ).
TRY.
CALL METHOD lo_wb_object_operator->('IF_WB_OBJECT_OPERATOR~READ')
EXPORTING
data_selection = 'P'
IMPORTING
eo_object_data = lo_object_data.
rv_bool = boolc( lo_object_data IS NOT INITIAL AND lo_object_data->get_object_key( ) IS NOT INITIAL ).
CATCH cx_root.
rv_bool = abap_false.
ENDTRY.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->ZIF_ABAPGIT_OBJECT~GET_COMPARATOR
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RI_COMPARATOR TYPE REF TO ZIF_ABAPGIT_COMPARATOR
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_abapgit_object~get_comparator.
RETURN.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->ZIF_ABAPGIT_OBJECT~GET_DESERIALIZE_STEPS
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RT_STEPS TYPE ZIF_ABAPGIT_DEFINITIONS=>TY_DESERIALIZATION_STEP_TT
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_abapgit_object~get_deserialize_steps.
APPEND zif_abapgit_object=>gc_step_id-abap TO rt_steps.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->ZIF_ABAPGIT_OBJECT~GET_METADATA
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RS_METADATA TYPE ZIF_ABAPGIT_DEFINITIONS=>TY_METADATA
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_abapgit_object~get_metadata.
rs_metadata = get_metadata( ).
rs_metadata-delete_tadir = abap_true.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->ZIF_ABAPGIT_OBJECT~IS_ACTIVE
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RV_ACTIVE TYPE ABAP_BOOL
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_abapgit_object~is_active.
rv_active = is_active( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->ZIF_ABAPGIT_OBJECT~IS_LOCKED
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RV_IS_LOCKED TYPE ABAP_BOOL
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_abapgit_object~is_locked.
rv_is_locked = exists_a_lock_entry_for( iv_lock_object = 'ESWB_EO'
iv_argument = |{ ms_item-obj_type }{ ms_item-obj_name }| ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->ZIF_ABAPGIT_OBJECT~JUMP
* +-------------------------------------------------------------------------------------------------+
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_abapgit_object~jump.
CALL FUNCTION 'RS_TOOL_ACCESS'
EXPORTING
operation = 'SHOW'
object_name = ms_item-obj_name
object_type = ms_item-obj_type
in_new_window = abap_true
EXCEPTIONS
not_executed = 1
invalid_object_type = 2
OTHERS = 3.
IF sy-subrc <> 0.
zcx_abapgit_exception=>raise_t100( ).
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_ABAPGIT_OBJECT_SRVB->ZIF_ABAPGIT_OBJECT~SERIALIZE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_XML TYPE REF TO ZIF_ABAPGIT_XML_OUTPUT
* | [!CX!] ZCX_ABAPGIT_EXCEPTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_abapgit_object~serialize.
DATA:
li_object_data_model TYPE REF TO if_wb_object_data_model,
li_wb_object_operator TYPE REF TO object,
lx_error TYPE REF TO cx_root.
FIELD-SYMBOLS:
<ls_service_binding> TYPE any.
ASSIGN mr_service_binding->* TO <ls_service_binding>.
ASSERT sy-subrc = 0.
TRY.
li_wb_object_operator = get_wb_object_operator( ).
CALL METHOD li_wb_object_operator->('IF_WB_OBJECT_OPERATOR~READ')
EXPORTING
version = 'A'
data_selection = 'AL'
IMPORTING
"data = <ls_service_definition>
eo_object_data = li_object_data_model.
li_object_data_model->get_data( IMPORTING p_data = <ls_service_binding> ).
clear_fields( CHANGING cs_service_binding = <ls_service_binding> ).
CATCH cx_root INTO lx_error.
zcx_abapgit_exception=>raise_with_text( lx_error ).
ENDTRY.
io_xml->add(
iv_name = 'SRVB'
ig_data = <ls_service_binding> ).
ENDMETHOD.
ENDCLASS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment