package eu.dnetlib.apps.oai2ftp.utils; import java.net.URL; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class StorageClientFactory { @Value("${oai2ftp.conf.storage.url}") private URL storageUrl; @Value("${oai2ftp.conf.storage.user}") private String storageUser; @Value("${oai2ftp.conf.storage.password}") private String storagePassword; public StorageClient newClientForJob(final String jobId) { final String protocol = storageUrl.getProtocol(); final String host = storageUrl.getHost(); final int port = storageUrl.getPort(); final String path = storageUrl.getPath(); StorageClient client; if (protocol.equalsIgnoreCase("ftp")) { client = new FtpStorage(host, port, false); } else if (protocol.equalsIgnoreCase("ftps")) { client = new FtpStorage(host, port, true); } else if (protocol.equalsIgnoreCase("file")) { client = new LocalStorage(); } else { throw new RuntimeException("Invalid storage protocol: " + protocol); } client.login(storageUser, storagePassword); client.changeDir(path); client.changeDir(jobId); return client; } }