For download functionality we have the same process as for Upload. Download WD is created as separate WD component and is referred in the main WD application.
The download logic is as laid out in the diagram below. Event from download component is sent to the main WD component. Which then uses the assistance class to convert the structure into file layout. Then it calls the interface method in the download WD to send the file via the browser to the user for it to be saved.
WD app component using Download WD component.
Download WD Component
This component will download any file that is selected into the internal table of the assistance class. The following has been created in this component.Context (V_DOWNLOAD & Component Controller)
There is one difference from the upload WD here, the context has been set to be as interface. The calling WD will the context with file information when it initialises the download WD.
Methods in the main controller
At the component start up get the app name it is embedded in and create structure for mapping the file.
METHOD wddoinit . wd_this->app_name = get_app_name( ). get_file_struc( ). get_date_format( ).
App name is retrieved here.
METHOD get_app_name . lo_api_componentcontroller = wd_this->wd_get_api( ). lo_app = lo_api_componentcontroller->get_application( ). lo_app_info = lo_app->get_application_info( ). r_app_name = lo_app_info->get_name( ).
Retrieve the structure for the particular app and create dynamic structure in the assistance class.
METHOD get_file_struc . * Look for file structure in the lookup table FROM ZBC_LKP WHERE LKP_KEY = wd_this->app_name. * get message manager lo_api_controller ?= wd_this->wd_get_api( ). lo_message_manager = lo_api_controller->get_message_manager( ). * report message lo_message_manager->report_error_message( message_text = 'No file structure defined for this app' ). ELSE. * Send the assitance class the structure name TRY . wd_assist->set_structure_name( i_structure_name = l_struc_name ). CATCH zcx_library. * report message lo_message_manager->report_error_message( message_text = 'File format not supported' ).
If date format is specified then use it.
METHOD get_date_format . * Look for date format in the lookup table FROM zbc_lkp WHERE lkp_key = wd_this->app_name. * Send the assitance class date format wd_assist->set_external_date_format( i_date_format = l_date_format ).
Now we come to user interactions. Assuming there is data that user wants to download, user will click the download button. Fire event for the App WD for data to be parsed and mapped into a file structure as per the application structure. Once the file structure is created then call the download method to push the file out. The file here is assumed to be tab delimited so that’s what the separator has been specified to.
Action attached to the download button
The component controller method start_download is called hence.
method ONACTIONDOWNLOAD_FILE . wd_comp_controller->start_download( ).
By this time the calling WD will receive the event and convert the data in to the file structure that it needs to send to. After this it will call the method DOWNLOAD_FILE in the download WD.
METHOD START_DOWNLOAD. * navigate from <CONTEXT> to <FILE> via lead selection lo_nd_file = wd_context->get_child_node( name = wd_this->wdctx_file ). * get element via lead selection lo_el_file = lo_nd_file->get_element( ). * get all declared attributes lo_el_file->get_static_attributes( IMPORTING static_attributes = ls_file ). * Calling WD should have provided file information throw_message( EXPORTING i_message = 'No file information provided' i_type = if_wd_message_manager=>co_type_error ). wd_this->file_name = ls_file-filename. wd_this->mime_type = ls_file-mimetype. * Fire event wd_this->fire_download_clicked_evt( ).
METHOD download_file . wd_assist->get_mapped_file( IMPORTING e_t_mapped_file = lt_data ). CALL FUNCTION 'SCMS_STRING_TO_XSTRING' EXPORTING text = l_data_string IMPORTING buffer = l_data_xstring. cl_wd_runtime_services=>attach_file_to_response( i_filename = wd_this->file_name i_content = l_data_xstring i_mime_type = wd_this->mime_type ).
This covers the download WD component, in part III we will look at the usage of these 2 WD components.
No comments:
Post a Comment