abapGit/src/objects/zcl_abapgit_object_ensc.clas.abap
2018-06-18 14:18:58 +02:00

197 lines
6.0 KiB
ABAP

CLASS zcl_abapgit_object_ensc DEFINITION PUBLIC INHERITING FROM zcl_abapgit_objects_super FINAL.
PUBLIC SECTION.
INTERFACES zif_abapgit_object.
ALIASES mo_files FOR zif_abapgit_object~mo_files.
ENDCLASS.
CLASS zcl_abapgit_object_ensc IMPLEMENTATION.
METHOD zif_abapgit_object~has_changed_since.
rv_changed = abap_true.
ENDMETHOD.
METHOD zif_abapgit_object~changed_by.
rv_user = c_user_unknown. " todo
ENDMETHOD.
METHOD zif_abapgit_object~deserialize.
DATA: lv_spot_name TYPE enhspotcompositename,
lv_message TYPE string,
lv_enh_shtext TYPE string,
lv_enh_spot TYPE enhspotname,
lt_enh_spots TYPE enhspotname_it,
lt_comp_spots TYPE enhspotname_it,
lx_root TYPE REF TO cx_root,
lv_package LIKE iv_package,
li_spot_ref TYPE REF TO if_enh_spot_composite,
lo_spot_ref TYPE REF TO cl_enh_spot_composite.
lv_spot_name = ms_item-obj_name.
io_xml->read( EXPORTING iv_name = 'SHORTTEXT'
CHANGING cg_data = lv_enh_shtext ).
io_xml->read( EXPORTING iv_name = 'ENH_SPOTS' "Enhancement spots
CHANGING cg_data = lt_enh_spots ).
io_xml->read( EXPORTING iv_name = 'COMP_ENH_SPOTS' "Composite enhancement spots
CHANGING cg_data = lt_comp_spots ).
IF zif_abapgit_object~exists( ) = abap_true.
zif_abapgit_object~delete( ).
ENDIF.
lv_package = iv_package.
TRY.
cl_enh_factory=>create_enhancement_spot_comp(
EXPORTING
name = lv_spot_name
run_dark = abap_true
IMPORTING
composite = li_spot_ref
CHANGING
devclass = lv_package ).
lo_spot_ref ?= li_spot_ref.
lo_spot_ref->if_enh_object_docu~set_shorttext( lv_enh_shtext ).
"Add subsequent enhancement spots
LOOP AT lt_enh_spots INTO lv_enh_spot.
lo_spot_ref->if_enh_spot_composite~add_enh_spot_child( lv_enh_spot ).
ENDLOOP.
"Add subsequent composite enhancement spots
LOOP AT lt_comp_spots INTO lv_enh_spot.
lo_spot_ref->if_enh_spot_composite~add_composite_child( lv_enh_spot ).
ENDLOOP.
lo_spot_ref->if_enh_object~save( ).
lo_spot_ref->if_enh_object~activate( ).
lo_spot_ref->if_enh_object~unlock( ).
CATCH cx_enh_root INTO lx_root.
lv_message = `Error occured while deserializing ENSC: `
&& lx_root->get_text( ) ##NO_TEXT.
zcx_abapgit_exception=>raise( lv_message ).
ENDTRY.
ENDMETHOD. "deserialize
METHOD zif_abapgit_object~serialize.
DATA: lv_spot_name TYPE enhspotcompositename,
lv_message TYPE string,
lv_enh_shtext TYPE string,
lt_enh_spots TYPE enhspotname_it,
lt_comp_spots TYPE enhspotname_it,
lx_root TYPE REF TO cx_root,
li_spot_ref TYPE REF TO if_enh_spot_composite,
lo_spot_ref TYPE REF TO cl_enh_spot_composite.
lv_spot_name = ms_item-obj_name.
TRY.
li_spot_ref = cl_enh_factory=>get_enhancement_spot_comp(
lock = ''
name = lv_spot_name ).
lo_spot_ref ?= li_spot_ref.
lv_enh_shtext = li_spot_ref->if_enh_object_docu~get_shorttext( ).
"find parent = composite enhancement (ENSC)
* lv_parent = cl_r3standard_persistence=>enh_find_parent_composite( lv_spot_name ).
"find subsequent enhancement spots
lt_enh_spots = lo_spot_ref->if_enh_spot_composite~get_enh_spot_childs( ).
"find subsequent composite enhancement spots
lt_comp_spots = lo_spot_ref->if_enh_spot_composite~get_composite_childs( ).
io_xml->add( ig_data = lv_enh_shtext
iv_name = 'SHORTTEXT' ).
io_xml->add( ig_data = lt_enh_spots
iv_name = 'ENH_SPOTS' ). "Enhancement spots
io_xml->add( ig_data = lt_comp_spots
iv_name = 'COMP_ENH_SPOTS' ). "Composite enhancement spots
CATCH cx_enh_root INTO lx_root.
lv_message = `Error occured while serializing ENSC: `
&& lx_root->get_text( ) ##NO_TEXT.
zcx_abapgit_exception=>raise( lv_message ).
ENDTRY.
ENDMETHOD. "serialize
METHOD zif_abapgit_object~exists.
DATA: lv_spot_name TYPE enhspotcompositename,
li_spot_ref TYPE REF TO if_enh_spot_composite.
lv_spot_name = ms_item-obj_name.
TRY.
li_spot_ref = cl_enh_factory=>get_enhancement_spot_comp(
lock = ''
name = lv_spot_name ).
rv_bool = abap_true.
CATCH cx_enh_root.
rv_bool = abap_false.
ENDTRY.
ENDMETHOD. "exists
METHOD zif_abapgit_object~delete.
DATA: lv_spot_name TYPE enhspotcompositename,
lv_message TYPE string,
lx_root TYPE REF TO cx_root,
li_spot_ref TYPE REF TO if_enh_spot_composite.
lv_spot_name = ms_item-obj_name.
TRY.
li_spot_ref = cl_enh_factory=>get_enhancement_spot_comp(
lock = 'X'
name = lv_spot_name ).
IF li_spot_ref IS BOUND.
li_spot_ref->if_enh_object~delete(
nevertheless_delete = 'X'
run_dark = 'X' ).
ENDIF.
li_spot_ref->if_enh_object~unlock( ).
CATCH cx_enh_root INTO lx_root.
lv_message = `Error occured while deleting ENSC: `
&& lx_root->get_text( ) ##NO_TEXT.
zcx_abapgit_exception=>raise( lv_message ).
ENDTRY.
ENDMETHOD. "delete
METHOD zif_abapgit_object~get_metadata.
rs_metadata = get_metadata( ).
ENDMETHOD. "get_metadata
METHOD zif_abapgit_object~jump.
CALL FUNCTION 'RS_TOOL_ACCESS'
EXPORTING
operation = 'SHOW'
object_name = ms_item-obj_name
object_type = 'ENSC'
in_new_window = abap_true.
ENDMETHOD. "jump
METHOD zif_abapgit_object~compare_to_remote_version.
CREATE OBJECT ro_comparison_result TYPE zcl_abapgit_comparison_null.
ENDMETHOD.
METHOD zif_abapgit_object~is_locked.
rv_is_locked = abap_false.
ENDMETHOD.
ENDCLASS. "zcl_abapgit_object_ensc