Commit 08036e3f authored by Matija Obreza's avatar Matija Obreza
Browse files

FTP: CanBeAnythingFile updated with date and dir/file type

parent 7c85407d
...@@ -18,6 +18,8 @@ package org.genesys.filerepository.service.ftp; ...@@ -18,6 +18,8 @@ package org.genesys.filerepository.service.ftp;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Path;
import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.ftpserver.ftplet.FtpFile; import org.apache.ftpserver.ftplet.FtpFile;
...@@ -28,20 +30,18 @@ import org.apache.ftpserver.ftplet.FtpFile; ...@@ -28,20 +30,18 @@ import org.apache.ftpserver.ftplet.FtpFile;
public abstract class CanBeAnythingFile implements FtpFile { public abstract class CanBeAnythingFile implements FtpFile {
/** The parent. */ /** The parent. */
private final String parent; private final Path path;
private long date = new Date().getTime();
/** The name. */ protected boolean dir = false;
private final String name;
/** /**
* Instantiates a new can be anything file. * Instantiates a new can be anything file.
* *
* @param parent the parent * @param parent the parent
* @param name the name * @param path2 the name
*/ */
public CanBeAnythingFile(final String parent, final String name) { public CanBeAnythingFile(final Path parent, final String name) {
this.parent = parent; this.path = parent.resolve(name);
this.name = name;
} }
/* /*
...@@ -50,7 +50,7 @@ public abstract class CanBeAnythingFile implements FtpFile { ...@@ -50,7 +50,7 @@ public abstract class CanBeAnythingFile implements FtpFile {
*/ */
@Override @Override
public String getAbsolutePath() { public String getAbsolutePath() {
return parent.length() > 1 ? parent.concat("/").concat(name) : parent.concat(name); return path.toAbsolutePath().toString();
} }
/* /*
...@@ -59,7 +59,7 @@ public abstract class CanBeAnythingFile implements FtpFile { ...@@ -59,7 +59,7 @@ public abstract class CanBeAnythingFile implements FtpFile {
*/ */
@Override @Override
public String getName() { public String getName() {
return name; return path.getFileName().toString();
} }
/* /*
...@@ -77,7 +77,7 @@ public abstract class CanBeAnythingFile implements FtpFile { ...@@ -77,7 +77,7 @@ public abstract class CanBeAnythingFile implements FtpFile {
*/ */
@Override @Override
public boolean isDirectory() { public boolean isDirectory() {
return true; return dir;
} }
/* /*
...@@ -86,7 +86,7 @@ public abstract class CanBeAnythingFile implements FtpFile { ...@@ -86,7 +86,7 @@ public abstract class CanBeAnythingFile implements FtpFile {
*/ */
@Override @Override
public boolean isFile() { public boolean isFile() {
return true; return !dir;
} }
/* /*
...@@ -158,7 +158,7 @@ public abstract class CanBeAnythingFile implements FtpFile { ...@@ -158,7 +158,7 @@ public abstract class CanBeAnythingFile implements FtpFile {
*/ */
@Override @Override
public long getLastModified() { public long getLastModified() {
return 0; return date;
} }
/* /*
......
...@@ -301,9 +301,9 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ ...@@ -301,9 +301,9 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
// directory // directory
directory(path.toString(), this) directory(path.toString(), this)
// or file // or file
: file(repositoryService.getFile( : file(FtpRunAs.asFtpUser(user, () -> repositoryService.getFile(
path.getParent().toString(), path.getParent().toString(),
path.getFileName().toString()), this); path.getFileName().toString())), this);
} catch (final AuthenticationException e) { } catch (final AuthenticationException e) {
LOG.warn("Authentication problem {}", e.getMessage(), e); LOG.warn("Authentication problem {}", e.getMessage(), e);
...@@ -311,10 +311,11 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ ...@@ -311,10 +311,11 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
} catch (final NoSuchRepositoryFileException e) { } catch (final NoSuchRepositoryFileException e) {
LOG.debug("Making new CanBeAnythingFile path={} name={}", path.getParent().toString(), path.getFileName().toString()); LOG.debug("Making new CanBeAnythingFile path={} name={}", path.getParent().toString(), path.getFileName().toString());
return new CanBeAnythingFile(path.getParent().toString(), path.getFileName().toString()) { return new CanBeAnythingFile(path.getParent(), path.getFileName().toString()) {
@Override @Override
public boolean mkdir() { public boolean mkdir() {
this.dir = true;
LOG.info("Mkdir path={}", this.getAbsolutePath()); LOG.info("Mkdir path={}", this.getAbsolutePath());
temporaryDirs.add(this.getAbsolutePath()); temporaryDirs.add(this.getAbsolutePath());
return true; return true;
...@@ -391,8 +392,8 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ ...@@ -391,8 +392,8 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
* @param user the user * @param user the user
*/ */
public RepositoryFileSystemView(final FtpUser user) { public RepositoryFileSystemView(final FtpUser user) {
username = user.getName();
this.user = user; this.user = user;
username = user.getName();
} }
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment