package com.linkedpipes.etl.convert.uv.configuration;

import com.linkedpipes.etl.convert.uv.pipeline.LpPipeline;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.openrdf.model.Statement;
import org.openrdf.model.ValueFactory;
import org.openrdf.model.impl.SimpleValueFactory;
import org.openrdf.model.vocabulary.RDF;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Petr Škoda
 */
@XStreamAlias("eu.unifiedviews.plugins.extractor.filesdownload.FilesDownloadConfig_V1")
class FilesDownloadConfig_V1 implements Configuration {

    @XStreamAlias("eu.unifiedviews.plugins.extractor.filesdownload.VfsFile")
    static class VfsFile {

        String uri = "";

        String username = "";

        String password = "";

        String fileName = "";

    }

    private static final Logger LOG
            = LoggerFactory.getLogger(FilesDownloadConfig_V1.class);

    List<VfsFile> vfsFiles = new LinkedList<>();

    boolean softFail = false;

    int defaultTimeout = 20000;

    boolean ignoreTlsErrors = false;

    @Override
    public void update(LpPipeline pipeline, LpPipeline.Component component) {

        if (vfsFiles.isEmpty()) {
            LOG.error("At least one file to download must be specified.");
            throw new UnsupportedOperationException("FilesDownloadConfig_V1");
        } else if (vfsFiles.size() == 1) {
            toHttpGet(pipeline, component);
        } else {
            LOG.error("Multiple files to download are not suported.");
            throw new UnsupportedOperationException("FilesDownloadConfig_V1");
        }

    }

    public void toHttpGet(LpPipeline pipeline, LpPipeline.Component component) {

        pipeline.renameOutPort(component, "output", "FilesOutput");

        component.setTemplate(LpPipeline.BASE_IRI + "resources/components/e-httpGetFile");

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final List<Statement> st = new ArrayList<>();

        final VfsFile file = vfsFiles.get(0);

        st.add(vf.createStatement(
                vf.createIRI("http://localhost/resources/configuration/e-httpGetFile"),
                RDF.TYPE,
                vf.createIRI("http://plugins.linkedpipes.com/ontology/e-httpGetFile#Configuration")));

        st.add(vf.createStatement(
                vf.createIRI("http://localhost/resources/configuration/e-httpGetFile"),
                vf.createIRI("http://plugins.linkedpipes.com/ontology/e-httpGetFile#fileUri"),
                vf.createLiteral(file.uri)));

        if (file.fileName == null || file.fileName.isEmpty()) {
            file.fileName = "generated_name";
        }

        st.add(vf.createStatement(
                vf.createIRI("http://localhost/resources/configuration/e-httpGetFile"),
                vf.createIRI("http://plugins.linkedpipes.com/ontology/e-httpGetFile#fileName"),
                vf.createLiteral(file.fileName)));

        if (softFail) {
            LOG.warn("{} : Soft fail is not supported.", component);
        }
        if (ignoreTlsErrors) {
            LOG.warn("{} : Options 'ignoreTlsErrors' is not supported.", component);
        }
        LOG.info("{} : Custom time out is not supported.", component);

        component.setLpConfiguration(st);
    }

}

@@ -1456,24 +1456,195 @@
 e() == 1) %7B%0A
+            final VfsFile file = vfsFiles.get(0);%0A            if (file.uri.startsWith(%22file://%22)) %7B%0A                toLocal(pipeline, component);%0A            %7D else %7B%0A    
             
@@ -1667,32 +1667,46 @@
 ne, component);%0A
+            %7D%0A
         %7D else %7B
@@ -1870,24 +1870,1252 @@
   %7D%0A%0A    %7D%0A%0A
+    public void toLocal(LpPipeline pipeline, LpPipeline.Component component) %7B%0A%0A        pipeline.renameOutPort(component, %22output%22, %22FilesOutput%22);%0A%0A        component.setTemplate(LpPipeline.BASE_IRI + %22resources/components/e-filesFromLocal%22);%0A%0A        final ValueFactory vf = SimpleValueFactory.getInstance();%0A        final List%3CStatement%3E st = new ArrayList%3C%3E();%0A%0A        st.add(vf.createStatement(%0A                vf.createIRI(%22http://localhost/resources/configuration/e-filesFromLocal%22),%0A                RDF.TYPE,%0A                vf.createIRI(%22http://plugins.linkedpipes.com/ontology/e-filesFromLocal#Configuration%22)));%0A%0A        final VfsFile file = vfsFiles.get(0);%0A        if (!file.fileName.endsWith(file.fileName)) %7B%0A            LOG.warn(%22%7B%7D : Custom name of local file is not supported. Please check the pipeline.%22, component);%0A        %7D%0A%0A        final String path = file.uri.substring(%22file://%22.length());%0A        st.add(vf.createStatement(%0A                vf.createIRI(%22http://localhost/resources/configuration/e-filesFromLocal%22),%0A                vf.createIRI(%22http://plugins.linkedpipes.com/ontology/e-filesFromLocal#path%22),%0A                vf.createLiteral(path)));%0A%0A        component.setLpConfiguration(st);%0A    %7D%0A%0A
     public v

Fix import of FilesDownloadConfig_V1