DataSourceAppComponent

Required to implement a data-source component. Data sources produces 0 or more rows of results.

Source: Github

Example:

package my.org.components;

import io.dexi.service.AppContext;
import io.dexi.service.components.AppComponent;
import io.dexi.service.components.DataSourceAppComponent;
import io.dexi.service.utils.ResultStream;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static java.util.Collections.singletonMap;

@AppComponent("read-data-from-my-app")
public class MyAppDataSourceAppComponent implements DataSourceAppComponent<MyAppConfig, MyComponentConfig> {
    
    private static final String ID = "id";

    @Override
    public void read(AppContext<MyAppConfig, MyComponentConfig> ctxt, String offset, int batchSize, ResultStream resultStream) throws IOException {
        List<Map<String,Object>> data = Arrays.asList(
                singletonMap(ID, 1),
                singletonMap(ID, 2),
                singletonMap(ID, 3),
                singletonMap(ID, 4),
                singletonMap(ID, 5)
        ); 
        
        for(Map<String,Object> row : data) {
            resultStream.append(row);
        }

    }

    @Override
    public Class<MyComponentConfig> getComponentConfigClass() {
        return MyComponentConfig.class;
    }
}
components:
- name: read-data-from-my-app
  type: data-source
  title: Read data from my app
  specification:
    endpoint: # Will invoke MyAppDataSourceAppComponent::read
      url: "${baseUrl}/dexi/data/source/read"
      method: POST
    outputs:
    	id: 
      	type: number
        title: ID