All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.edurt.datacap.plugin.http.cratedb.CrateDBPlugin Maven / Gradle / Ivy

There is a newer version: 2024.3.11
Show newest version
package io.edurt.datacap.plugin.http.cratedb;

import io.edurt.datacap.spi.Plugin;
import io.edurt.datacap.spi.PluginType;
import io.edurt.datacap.spi.adapter.Adapter;
import io.edurt.datacap.spi.connection.HttpConfigure;
import io.edurt.datacap.spi.connection.HttpConnection;
import io.edurt.datacap.spi.model.Configure;
import io.edurt.datacap.spi.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.ObjectUtils;

@Slf4j
public class CrateDBPlugin
        implements Plugin
{
    private HttpConfigure httpConfigure;
    private HttpConnection connection;
    private Response response;

    @Override
    public String name()
    {
        return "CrateDB";
    }

    @Override
    public String description()
    {
        return "Integrate CrateDB data sources";
    }

    @Override
    public PluginType type()
    {
        return PluginType.HTTP;
    }

    @Override
    public void connect(Configure configure)
    {
        try {
            this.response = new Response();
            this.httpConfigure = new HttpConfigure();
            BeanUtils.copyProperties(this.httpConfigure, configure);
            this.connection = new CrateDBConnection(this.httpConfigure, this.response);
        }
        catch (Exception ex) {
            this.response.setIsConnected(Boolean.FALSE);
            this.response.setMessage(ex.getMessage());
        }
    }

    @Override
    public Response execute(String content)
    {
        if (ObjectUtils.isNotEmpty(this.connection)) {
            log.info("Execute cratedb plugin logic started");
            this.response = this.connection.getResponse();
            Adapter processor = new CrateDBAdapter(this.connection);
            this.response = processor.handlerExecute(content);
            log.info("Execute cratedb plugin logic end");
        }
        return this.response;
    }

    @Override
    public void destroy()
    {
        if (ObjectUtils.isNotEmpty(this.connection)) {
            this.connection.destroy();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy