Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

*&---------------------------------------------------------------------*

*& Report ZNISC_HTTP_CLOUD


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT znisc_http_cloud.

* mit SM59 einrichten


DATA: lv_http_dest TYPE rfcdest VALUE 'CTSM2CLOUD'.
DATA: lv_host LIKE rfcdisplay-rfchost.

TRY.

CALL FUNCTION 'RFC_READ_HTTP_DESTINATION'


EXPORTING
destination = lv_http_dest
IMPORTING
server = lv_host
EXCEPTIONS
authority_not_available = 1
destination_not_exist = 2
information_failure = 3
internal_failure = 4
no_http_destination = 5.

DATA lv TYPE string.

lv = |https://{ lv_host }/api/study/v1/|.

*lv = |https://ctsm-test-test-ctsm-core.cfapps.eu10.hana.ondemand.com/api/study/
v1/StudyMaterials?$filter=(material_ID%20eq
%20'119')&$select=material_ID&$expand=study($select=ID,study_ID,protocol_ID,descrip
tion,| &&
*|modifiedAt;
$expand=contacts($select=ID,personNumber),siteGroups($select=ID,siteGroup_ID,centra
lDepot_ID,distrDepot_ID,depotBuffer,shipLeadTime,siteBuffer,countryId),scenarios($s
elect=ID,scenarioID,study_ID,| &&
*|description,statusChangedAt,ctmProtocolUpdate,copiedFrom,status_code;
$expand=scenarioSiteGroups($select=ID,active,regulatoryApproval,firstSubjectFirstVi
sit,lastSubjectFirstVisit,manualEnrollment,plannedEnrollment,| &&
*|
plannedNumberOfSites,actualEnrollment,siteGroupId,scenario_ID,studySiteGroup_ID)),k
itTypes($select=ID,kitTypeID,study_ID,blindingGroup_ID;
$expand=blindingGroup($select=ID,blindingGroupID,blindingGroupDescription;| &&
*|
$expand=texts($select=ID,locale,blindingGroupDescription)),labelGroups($select=ID),
countryLabelGroups($select=ID,country_countryId,labelGroup_ID,study_ID),countryMate
rials($select=ID,labelGroup_ID,study_ID;| &&
*|$expand=material($select=ID,material_ID,material_plant,study_ID))))|.

lv = |{ lv }StudyMaterials?$filter=(material_ID%20eq
%20'238')&$select=material_ID,study_ID&$expand=study($select=ID,CTSMStudyID,CTSMPro
tocolID,description,modifiedAt,status_code,studyType_ID,studyPhase_ID,| &&
|costObject_ID,costObject_type,isSiteLevelTracking;
$expand=contacts($select=ID,personNumber,createdBy),siteGroups($select=ID,siteGroup
_ID,centralDepot_ID,distrDepot_ID,depotBuffer,shipLeadTime,siteBuffer,countryId),|
&&
|
scenarios($select=ID,scenarioID,study_ID,description,statusChangedAt,ctmProtocolUpd
ate,copiedFrom,status_code;
$expand=scenarioSiteGroups($select=ID,active,regulatoryApproval,firstSubjectFirstVi
sit,| &&
|
lastSubjectFirstVisit,manualEnrollment,plannedEnrollment,plannedNumberOfSites,actua
lEnrollment,siteGroupId,scenario_ID,studySiteGroup_ID)),blindingGroups($select=ID,b
lindingGroupID,blindingGroupDescription,| &&
|
blindedDescription,study_ID),studyType($select=ID,description),studyPhase($select=I
D,description),kitTypes($select=ID,kitTypeID,study_ID,blindingGroup_ID,description,
serialization;| &&
|
$expand=blindingGroup($select=ID,blindingGroupID,blindingGroupDescription),countryM
aterials($select=ID,study_ID,kitType_ID,material_ID,labelGroupAssignment_ID,validFr
om;$expand=material($select=ID,material_ID,| &&
|study_ID),labelGroupAssignment($select=ID,kitType_ID,labelGroup_ID;
$expand=labelGroup($select=ID,labelGroupDescription,labelGroupID,study_ID;
$expand=labelGroupCountryAssignments($select=ID,country_countryId,| &&
|labelGroup_ID,study_ID))))))|.

* lv = |{ lv }$metadata|.

cl_http_client=>create_by_url( EXPORTING
"url = 'https://ctsm-cust-test-ctsm-ctsm-
test-test-ctsm-site-approuter.cfapps.eu10.hana.ondemand.com/api/study/v1/Studies'
"url = 'https://ctsm-ctsm-test-test-ctsm-
core.cfapps.eu10.hana.ondemand.com/api/study/v1/Studies'
"url = 'https://ctsm-sandbox-sandbox-ctsm-
core-pr1051.cfapps.sap.hana.ondemand.com/api/study/v1/Studies'
* url = 'https://ctsm-dev-development-ctsm-
core.cfapps.sap.hana.ondemand.com/api/study/v1/Studies?$expand=*'
url = lv
* url = 'https://ctsm-dev-development-ctsm-
core.cfapps.sap.hana.ondemand.com/api/study/v1/$metadata'
IMPORTING
client = DATA(lo_client) ).

SELECT SINGLE * FROM /ctco/sync_cloud INTO @DATA(ls_sync_cnf).


IF sy-subrc EQ 0.
DATA(lo_oauth_client) = cl_oauth2_client=>create(
i_profile = ls_sync_cnf-oauth2_profile " Development Object
i_configuration = ls_sync_cnf-oauth2_config " Configured using transaction
OA2C_CONFIG
).

ELSE.
lo_oauth_client = cl_oauth2_client=>create(
i_profile = '/CTCO/OAUTH_CLIENT_PROFILE' " Development Object
i_configuration = 'ZSAP_CTSM_OAUTH_DEV_TENANT_1' " Configured using
transaction OA2C_CONFIG
).

ENDIF.

TRY.
lo_oauth_client->execute_cc_flow( ).
" set token to be used on HTTP client
lo_oauth_client->set_token( lo_client ).

CATCH cx_oa2c_at_not_available
cx_oa2c_at_expired
INTO DATA(lx_oa2c).
"Create new token as it has expired or not available
TRY.
lo_oauth_client->execute_cc_flow( ).

lo_oauth_client->set_token( lo_client ).

CATCH cx_oa2c INTO lx_oa2c.


DATA(lv_oa2c_text) = lx_oa2c->get_text( ).
ENDTRY.

CATCH cx_oa2c INTO lx_oa2c.


lv_oa2c_text = lx_oa2c->get_text( ).
ENDTRY.

lo_client->request->set_method( if_http_request=>co_request_method_get ).

lo_client->send( ).

lo_client->receive( ).

lo_client->response->get_status( IMPORTING
code = DATA(lv_http_rc)
reason = DATA(lv_reason) ).

IF lv_http_rc = 200.
DATA(lv_xml) = lo_client->response->get_cdata( ).
WRITE lv_http_rc.
WRITE lv_xml.
ELSE.
WRITE: / 'Fehler: ', lv_http_rc.
ENDIF.

lo_client->close( ).

CATCH cx_root INTO DATA(e_txt).


WRITE: / e_txt->get_text( ).
ENDTRY.

You might also like