DataStorageAppComponent

Required to implement a data-storage component. Data storage components receives 0 or more rows from dexi and typically then stores those rows in some sort of data store.

Source: Github

Example:

package my.org.components;

import io.dexi.service.AppContext;
import io.dexi.service.components.AppComponent;
import io.dexi.service.components.DataStorageAppComponent;
import io.dexi.service.utils.RowStream;

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

@AppComponent("write-data-to-my-app")
public class MyAppDataStorageAppComponent implements DataStorageAppComponent<MyAppConfig, MyComponentConfig> {

    private final SomeRepository someRepository;

    public MyAppDataStorageAppComponent(SomeRepository someRepository) {
        this.someRepository = someRepository;
    }

    @Override
    public Object write(AppContext<MyAppConfig, MyComponentConfig> ctxt, RowStream rows) throws IOException {
        int inserts = 0;
        while(rows.hasNext()) {
            final Map<String, Object> next = rows.next();
            if (someRepository.insert(next)) {
                inserts++;
            }
        }

        return inserts;
    }

    @Override
    public Class<MyComponentConfig> getComponentConfigClass() {
        return MyComponentConfig.class;
    }
}
components:
- name: write-data-to-my-app
  type: data-storage
  title: Write data to my app
  specification:
    endpoint: # Will invoke MyAppDataStorageAppComponent::write
      url: "${baseUrl}/dexi/data/storage/write"
      method: POST
    inputs:
    	id: 
      	type: number
        title: ID
      title:
      	type: string
        title: Title