package com.ericsson.uecontrol.core.behaviour;

import com.ericsson.uecontrol.core.UeBehaviour;
import com.ericsson.uecontrol.gui.util.Configurator.Configurable;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * This behaviour simulates downloading a file from FTP
 *
 * Created by ezivkoc on 2014-07-15.
 */
public class UeBehaviourFtpDownload extends UeBehaviourFileDownload {
    private static final Logger log = Logger.getLogger(UeBehaviourFtpDownload.class);

    @Configurable("Host")
    private String host     = "ftp.otenet.gr";
    @Configurable("File Path")
    private String filePath = "/test1Mb.db";
    @Configurable("Username")
    private String username = "speedtest";
    @Configurable("Password")
    private String password = "speedtest";


    @Override
    protected String getFileUrl() {
        String url = "ftp://";
        if(username != null && !username.isEmpty()) {
            url += username;
            if(password !=null && !password.isEmpty())
                url += ":"+password;
            url += "@";
        }
        url += host;
        if(filePath != null && !filePath.isEmpty()){
            if(!filePath.startsWith("/"))
                filePath = "/"+filePath;
            url += filePath;
        }
        return url;
    }


    @Override
    public String getName() {
        return "FTP Download";
    }

}
