Sunday, March 25, 2018

Gateway Debug Points- Navigation



/IWCOR/CL_DS_URI=>HANDLE_NAV_PATH_OPTIONS

 DATA:
      lv_segment TYPE string,
      lv_property TYPE string,
      lv_parentheses TYPE string,
      lv_length TYPE i,
      lv_length_minus_2 TYPE i,
      lv_key_predicate TYPE string,
      lo_from_entity_type TYPE REF TO /iwcor/if_ds_edm_entity_type,
      lo_property TYPE REF TO /iwcor/if_ds_edm_typed,
      lo_property_type TYPE REF TO /iwcor/if_ds_edm_type,
      lo_entity_property TYPE REF TO /iwcor/if_ds_edm_property,
      lo_navigation_property TYPE REF TO /iwcor/if_ds_edm_nav_property,
      lr_navigation_end TYPE REF TO /iwcor/if_ds_uri=>navigation_path_segment_s,
      lv_lines TYPE i.

    lo_from_entity_type io_from_entity_set->get_entity_type).

    lv_segment shift).

    " Case 0: Segment is $count
    IF lv_segment '$count'.
      mo_target_type lo_from_entity_type"Target Type for URI 15, 16
      mo_target_entity_set io_from_entity_set.
      IF mt_segment IS INITIAL.
        /iwcor/if_ds_uri~count abap_true.
        IF /iwcor/if_ds_uri~navigation_path IS INITIAL.
          IF /iwcor/if_ds_uri~key_predicates IS INITIAL.
            /iwcor/if_ds_uri~uri_type /iwcor/if_ds_uri~gc_uri_type_15.
          ELSE.
            /iwcor/if_ds_uri~uri_type /iwcor/if_ds_uri~gc_uri_type_16.
          ENDIF.
        ELSE.
          " $count of last navigation property in navigation path
          lv_lines lines/iwcor/if_ds_uri~navigation_path ).
          READ TABLE /iwcor/if_ds_uri~navigation_path INDEX lv_lines REFERENCE INTO lr_navigation_end.
          IF lr_navigation_end->key_predicates IS INITIAL AND
             lr_navigation_end->navigation_property->get_multiplicity/iwcor/if_ds_edm=>gc_multiplicity_many.
            /iwcor/if_ds_uri~uri_type /iwcor/if_ds_uri~gc_uri_type_15.
          ELSE.
            /iwcor/if_ds_uri~uri_type /iwcor/if_ds_uri~gc_uri_type_16.
          ENDIF.
        ENDIF.
      ELSE.
        " $count must be the last segment.
        RAISE EXCEPTION TYPE /iwcor/cx_ds_uri_syntax_error
          EXPORTING
            textid  /iwcor/cx_ds_uri_syntax_error=>segment_not_last_segment
            segment lv_segment.
      ENDIF.
      RETURN.
    ENDIF.

    " Case 1: Segment is $Value - Media Resource only valid, if entity type has annotation "hasStream=true"
    IF lv_segment '$value'.

      IF lo_from_entity_type->has_streamabap_true.
        lv_segment shift).
        IF lv_segment IS NOT INITIAL.
          RAISE EXCEPTION TYPE /iwcor/cx_ds_uri_syntax_error
            EXPORTING
              textid  /iwcor/cx_ds_uri_syntax_error=>segment_last_segment
              segment '$value'.
        ENDIF.
        /iwcor/if_ds_uri~uri_type /iwcor/if_ds_uri~gc_uri_type_17.
        mo_target_type lo_from_entity_type"Target Type for URI 17
        mo_target_entity_set io_from_entity_set.
        /iwcor/if_ds_uri~value abap_true.
        RETURN.
      ELSE.
        RAISE EXCEPTION TYPE /iwcor/cx_ds_uri_syntax_error
          EXPORTING
            textid  /iwcor/cx_ds_uri_syntax_error=>invalid_media_resource_request
            segment lv_segment.
      ENDIF.
    ENDIF.

    " Case 2: Segment is $links - followed by a Navigation Property.
    IF lv_segment '$links'.
      /iwcor/if_ds_uri~links abap_true.
      handle_nav_propertiesio_from_entity_set io_from_entity_set ).
      RETURN.
    ENDIF.

    " The multiplicity of of a navigation property has to be evaluated to prevent URIs like
    " ...Employees('1')/ne_Team()/nt_Employees where ne_Team is an entity type instance,
    " thus parentheses are not allowed after ne_Team.

    " Case 3: Segment is a simple, complex or a Navigation Property.
    FIND REGEX '^([^()]+)(\(.*\))?$' IN lv_segment SUBMATCHES lv_property lv_parentheses.
    IF sy-subrc IS NOT INITIAL.
      RAISE EXCEPTION TYPE /iwcor/cx_ds_uri_not_matching
        EXPORTING
          textid  /iwcor/cx_ds_uri_not_matching=>invalid_segment
          segment lv_segment.
    ENDIF.
    lv_length strlenlv_parentheses ).

    lo_property lo_from_entity_type->get_propertylv_property ).
    IF lo_property IS NOT BOUND.
      RAISE EXCEPTION TYPE /iwcor/cx_ds_uri_not_matching
        EXPORTING
          textid  /iwcor/cx_ds_uri_not_matching=>invalid_segment
          segment lv_segment.
    ENDIF.

    lo_property_type lo_property->get_type).
    CASE lo_property_type->kind.
      WHEN /iwcor/if_ds_edm_type=>kind_simple OR /iwcor/if_ds_edm_type=>kind_complex.
        IF lv_length IS NOT INITIAL.
          RAISE EXCEPTION TYPE /iwcor/cx_ds_uri_not_matching
            EXPORTING
              textid  /iwcor/cx_ds_uri_not_matching=>invalid_segment
              segment lv_segment.
        ENDIF.
        lo_entity_property ?= lo_property.
        handle_property_pathlo_entity_property ).
      WHEN /iwcor/if_ds_edm_type=>kind_navigation.
        lo_navigation_property ?= lo_property.
        IF lv_length > 2.
          lv_length_minus_2 lv_length 2.
          lv_key_predicate lv_parentheses+1(lv_length_minus_2).
        ENDIF.
        IF lv_parentheses '()' AND lo_navigation_property->get_multiplicity<> /iwcor/if_ds_edm=>gc_multiplicity_many.
          RAISE EXCEPTION TYPE /iwcor/cx_ds_uri_not_matching
            EXPORTING
              textid  /iwcor/cx_ds_uri_not_matching=>invalid_segment
              segment lv_segment.
        ENDIF.
        handle_nav_propertiesio_from_entity_set io_from_entity_set io_navigation_property lo_navigation_property iv_key_predicate lv_key_predicate ).
    ENDCASE.


No comments:

Post a Comment