Data Providers

My project in GSoC was to implement a usable interface for Data Providers and adding transformations .

What is Data Provider ?

Data Provider can be accessed by going to Tabbed UI -> Data -> Data Providers in Libreoffice Calc . It can also be customised into any toolbar and menu . It supports importing external data from various sources. The external data currently supported are CSV , HTML , XML and Base . Data can be imported either from local storage such as CSV files or from the external sources such as HTML Web Pages . Data can also be manipulated using various transformations before loading it into the sheet .

What are Data Transformations ?

After importing data , various transformations such as Delete Columns , Sort Columns , etc. can be applied to the data . This is useful in the scenarios when users want to modify the data according to their convenience before importing . 

The project is divided into three phases -
1. Implement UI for Data Providers .
2. Adding Transformations .
3. Implement Extension Data Providers .

UI at start of Project


Implement UI for Data Providers

The first task was to implement a working UI for Data Providers and fix issues in the existing interface .
The UI is developed with the help of Glade . I want to thank Heiko Tietze for all the UI related helps .
The mockup for UI was prepared at the start of the project .

Mockup


Final UI


Working
Select the database range from the LibreOffice calc sheet . Select the type of data to be imported . Select the file from local storage or external web page in URL . Id ( of the Table ) field is required when HTML Data Provider is selected and Xpath in case of XML Data Provider . 
Transformations can also be added using the dropdown . Apply button is used to preview the data before importing into calc sheet . Okay button is to import the final data into the calc sheet .
Imported data can be kept updated with External Data Source by clicking on Refresh Data Provider ( Data -> Refresh Data Provider ) . This field becomes active only after data is imported into sheet .

Implementation
Class ScDataProviderBaseControl was removed and all the widgets were implemented in ScDataProviderDlg in file dataproviderdlg.cxx. It makes it easier to implement any new functionality in DataProvider dialog box without worrying about linking two classes. 
Also file dataproviderentry.ui was removed since all the widgets were moved to dataproviderdlg.ui .
My work can be found at -

There were many issues/bugs present in the existing interface such as currently implemented transformations were not working as expected . So the aim was to fix these issues . 
More details about my work can be found at -


Adding Transformations 

During my project I added few transformations which can be useful for the user .

- Find & Replace Transformation ->  https://gerrit.libreoffice.org/c/core/+/118384
- Delete Row Tranformation ->  https://gerrit.libreoffice.org/c/core/+/120296
- Swap Rows Transformation ->  https://gerrit.libreoffice.org/c/core/+/120556

Implementation
The code for UI is written in dataproviderdlg.cxx where Transformation class extends ScDataTransformationBaseControl . Struct type of Menudata is used to store all the transformations and callbacks associated with them . They are inserted into Transformation dropdown at the time of UI initialisation . The getTransformation() function calls the implementation class of Transformation in file datatransformation.cxx with the required input parameters .


Implement Extension Data Providers 

After implementing UI of Data Providers and fixing transformation issues , I with the help of my mentors decided to implement Extension Data Providers . The aim was to implement UNO interface for Data Providers . Since I was new to UNO , I want to thank Markus Mohrhard to help me getting introduced with UNO components .

Implementation
Interface XDataProvider was implemented to provide abstraction and following functions need to be implemented in Extension -
1. css::uno::Sequence <long> getProviderRange() - returns the database range provided by user.
2. css::table::XCell getCellByPosition(row,col) to return the cell at given position and then retrieving properties of cell using methods of CellContentType.

Class ExtensionDataProvider implements the XDataProvider Interface. 
ExtensionDataProvider was coded to provide compatibility with existing internal Data Providers and is called from dataprovider.cxx .
More details about implementation can be found at -
This patch is not merged to master yet and few changes might be there after final review .


I learnt many important things working with LibreOffice and most important of them is writing Industry level code . I want to thank my mentors Markus Mohrhard and Heiko Tietze for patiently listening to my doubts and helping me through it . I also want to thank LibreOffice community to help me getting started with Open Source Contributions .

Comments