diff --git a/src/main/java/org/caosdb/server/database/BackendTransaction.java b/src/main/java/org/caosdb/server/database/BackendTransaction.java index a3093651117742ccf448a262ce76c9dae12ff55c..4f41f7a3d4e5f4b077abbf7a2a6aa9e196112bc2 100644 --- a/src/main/java/org/caosdb/server/database/BackendTransaction.java +++ b/src/main/java/org/caosdb/server/database/BackendTransaction.java @@ -46,6 +46,7 @@ import org.caosdb.server.database.backend.implementation.MySQL.MySQLInsertRole; import org.caosdb.server.database.backend.implementation.MySQL.MySQLInsertSparseEntity; import org.caosdb.server.database.backend.implementation.MySQL.MySQLInsertTransactionHistory; import org.caosdb.server.database.backend.implementation.MySQL.MySQLIsSubType; +import org.caosdb.server.database.backend.implementation.MySQL.MySQLListFiles; import org.caosdb.server.database.backend.implementation.MySQL.MySQLListRoles; import org.caosdb.server.database.backend.implementation.MySQL.MySQLListUsers; import org.caosdb.server.database.backend.implementation.MySQL.MySQLLogUserVisit; @@ -73,10 +74,8 @@ import org.caosdb.server.database.backend.implementation.MySQL.MySQLSyncStats; import org.caosdb.server.database.backend.implementation.MySQL.MySQLUpdateSparseEntity; import org.caosdb.server.database.backend.implementation.MySQL.MySQLUpdateUser; import org.caosdb.server.database.backend.implementation.MySQL.MySQLUpdateUserRoles; -import org.caosdb.server.database.backend.implementation.UnixFileSystem.DeleteFile; import org.caosdb.server.database.backend.interfaces.BackendTransactionImpl; import org.caosdb.server.database.backend.interfaces.DeleteEntityPropertiesImpl; -import org.caosdb.server.database.backend.interfaces.DeleteFileImpl; import org.caosdb.server.database.backend.interfaces.DeletePasswordImpl; import org.caosdb.server.database.backend.interfaces.DeleteRoleImpl; import org.caosdb.server.database.backend.interfaces.DeleteSparseEntityImpl; @@ -123,7 +122,6 @@ import org.caosdb.server.database.backend.interfaces.SetFileChecksumImpl; import org.caosdb.server.database.backend.interfaces.SetPasswordImpl; import org.caosdb.server.database.backend.interfaces.SetPermissionRulesImpl; import org.caosdb.server.database.backend.interfaces.SetQueryTemplateDefinitionImpl; -import org.caosdb.server.database.backend.interfaces.StoreFileImpl; import org.caosdb.server.database.backend.interfaces.SyncStatsImpl; import org.caosdb.server.database.backend.interfaces.UpdateSparseEntityImpl; import org.caosdb.server.database.backend.interfaces.UpdateUserImpl; @@ -132,7 +130,6 @@ import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.database.misc.TransactionBenchmark; import org.caosdb.server.entity.EntityInterface; import org.caosdb.server.entity.RetrieveEntity; -import org.caosdb.server.filesystem.StoreFile; import org.caosdb.server.utils.UndoHandler; import org.caosdb.server.utils.Undoable; @@ -186,10 +183,6 @@ public abstract class BackendTransaction implements Undoable { setImpl(RetrievePropertiesImpl.class, MySQLRetrieveProperties.class); setImpl(RetrieveSparseEntityImpl.class, MySQLRetrieveSparseEntity.class); setImpl(SyncStatsImpl.class, MySQLSyncStats.class); - // setImpl(FileExists.class, FileSystemFileExists.class); - // setImpl(FileWasModifiedAfter.class, FileSystemFileWasModifiedAfter.class); - // setImpl(FileCheckHash.class, FileSystemCheckHash.class); - // setImpl(GetFileIteratorImpl.class, FileSystemGetFileIterator.class); setImpl(SetFileCheckedTimestampImpl.class, MySQLSetFileCheckedTimestamp.class); setImpl(RetrieveAllUncheckedFilesImpl.class, MySQLRetrieveAllUncheckedFiles.class); setImpl(UpdateUserImpl.class, MySQLUpdateUser.class); @@ -198,7 +191,6 @@ public abstract class BackendTransaction implements Undoable { setImpl(RetrievePasswordValidatorImpl.class, MySQLRetrievePasswordValidator.class); setImpl(DeletePasswordImpl.class, MySQLDeletePassword.class); setImpl(GetUpdateableChecksumsImpl.class, MySQLGetUpdateableChecksums.class); - // setImpl(FileCheckSize.class, FileSystemCheckSize.class); setImpl(InsertRoleImpl.class, MySQLInsertRole.class); setImpl(RetrieveRoleImpl.class, MySQLRetrieveRole.class); setImpl(ListRolesImpl.class, MySQLListRoles.class); @@ -212,9 +204,6 @@ public abstract class BackendTransaction implements Undoable { setImpl( RetrieveQueryTemplateDefinitionImpl.class, MySQLRetrieveQueryTemplateDefinition.class); setImpl(InsertEntityDatatypeImpl.class, MySQLInsertEntityDatatype.class); - setImpl(StoreFileImpl.class, StoreFile.class); - setImpl(DeleteFileImpl.class, DeleteFile.class); - // setImpl(ResolveFileImpl.class, ResolveFile.class); setImpl(RetrieveVersionHistoryImpl.class, MySQLRetrieveVersionHistory.class); setImpl(SetFileChecksumImpl.class, MySQLSetFileChecksum.class); setImpl(GetFilesInDirectoryImpl.class, MySQLGetFilesInDirectory.class); diff --git a/src/main/java/org/caosdb/server/database/DatabaseUtils.java b/src/main/java/org/caosdb/server/database/DatabaseUtils.java index 1ce5d93089d93f10f5796404407c09f54872827c..ad8810418015deebc81a587f30ce904ac3401a4a 100644 --- a/src/main/java/org/caosdb/server/database/DatabaseUtils.java +++ b/src/main/java/org/caosdb/server/database/DatabaseUtils.java @@ -235,7 +235,7 @@ public class DatabaseUtils { bytes2UTF8(rs.getBytes("FileHash")), rs.getLong("FileHashChecked"), bytes2UTF8(rs.getBytes("FileHashAlgo"))); - final String mimetype = bytes2UTF8(rs.getBytes("FileMimetype")); + final String mimetype = bytes2UTF8(rs.getBytes("FileMimeType")); ret.fileType = java.util.Objects.equals("inode/directory", mimetype) ? ObjectType.DIRECTORY diff --git a/src/main/java/org/caosdb/server/database/MySQLListFiles.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLListFiles.java similarity index 92% rename from src/main/java/org/caosdb/server/database/MySQLListFiles.java rename to src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLListFiles.java index c5b1774fa2acd8f4ae5bb35cc49f040c005b8bad..dfeed05b36d4001ad46e24aa82dab2b968d14db0 100644 --- a/src/main/java/org/caosdb/server/database/MySQLListFiles.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLListFiles.java @@ -1,13 +1,12 @@ -package org.caosdb.server.database; +package org.caosdb.server.database.backend.implementation.MySQL; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.LinkedList; import java.util.List; +import org.caosdb.server.database.DatabaseUtils; import org.caosdb.server.database.access.Access; -import org.caosdb.server.database.backend.implementation.MySQL.ConnectionException; -import org.caosdb.server.database.backend.implementation.MySQL.MySQLTransaction; import org.caosdb.server.database.backend.interfaces.ListFilesImpl; import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.database.proto.SparseEntity; @@ -21,7 +20,7 @@ public class MySQLListFiles extends MySQLTransaction implements ListFilesImpl { } public static final String LIST_FILES_STMT = - "SELECT 'SHA-512' AS FileHashAlgo, file_id AS FileId, parent_directory AS FileParentID, path AS FilePath, size AS FileSize, hex(hash) AS FileHash, checked_timestamp AS FileHashChecked, mimetype AS FileMimetype, file_storage_id AS FileStorageID, file_key AS FileKey FROM files"; + "SELECT 'SHA-512' AS FileHashAlgo, file_id AS FileId, parent_directory AS FileParentID, path AS FilePath, size AS FileSize, hex(hash) AS FileHash, checked_timestamp AS FileHashChecked, mimetype AS FileMimeType, file_storage_id AS FileStorageID, file_key AS FileKey FROM files"; public static final String FILE_STORAGE_CLAUSE = " file_storage_id = ?"; public static final String PATH_LIKE_CLAUSE = " path LIKE ?"; public static final String LAST_CHECKED_BEFORE_CLAUSE = " checked_timestamp < ?"; diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveAllUncheckedFiles.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveAllUncheckedFiles.java index a1c547bdb8a236f479bb045ba3b0557a485ec2d3..9fc50c821f59325f3ac320d1d3693b6bad3510bc 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveAllUncheckedFiles.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/MySQLRetrieveAllUncheckedFiles.java @@ -42,7 +42,7 @@ public class MySQLRetrieveAllUncheckedFiles extends MySQLTransaction private static final String STMT_RETRIEVE_ALL = "SELECT hash_algorithm AS FileHashAlgo, file_id AS FileId, " /*parent_directory AS FileParentId,*/ - + "path AS FilePath, size AS FileSize, hex(hash) AS FileHash, checked_timestamp AS FileHashChecked, mimetype AS FileMimetype, file_storage_id AS FileStorageId, file_key AS FileKey FROM files WHERE checked_timestamp<? AND path LIKE ? AND (mimetype IS NULL OR mimetype != 'inode/directory')"; + + "path AS FilePath, size AS FileSize, hex(hash) AS FileHash, checked_timestamp AS FileHashChecked, mimetype AS FileMimeType, file_storage_id AS FileStorageId, file_key AS FileKey FROM files WHERE checked_timestamp<? AND path LIKE ? AND (mimetype IS NULL OR mimetype != 'inode/directory')"; public MySQLRetrieveAllUncheckedFiles(final Access access) { super(access); diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/DeleteFile.java b/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/DeleteFile.java deleted file mode 100644 index 212239d52d493170e7d1eb6e8342a97f5d598077..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/DeleteFile.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.caosdb.server.database.backend.implementation.UnixFileSystem; - -import org.caosdb.server.database.access.Access; -import org.caosdb.server.database.backend.interfaces.DeleteFileImpl; -import org.caosdb.server.entity.Message; -import org.caosdb.server.filesystem.FSODescriptorInterface; -import org.caosdb.server.utils.Undoable; - -public class DeleteFile extends FileSystemTransaction implements DeleteFileImpl { - - public DeleteFile(Access access) { - super(access); - } - - @Override - public Undoable delete(FSODescriptorInterface fileDescriptor) throws Message { - return getFileSystem().delete(fileDescriptor); - } -} diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemCheckHash.java b/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemCheckHash.java deleted file mode 100644 index 2ad904100ea48bf779b11330a803988795fa4bef..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemCheckHash.java +++ /dev/null @@ -1,54 +0,0 @@ -/// * -// * ** header v3.0 -// * This file is a part of the CaosDB Project. -// * -// * Copyright (C) 2018 Research Group Biomedical Physics, -// * Max-Planck-Institute for Dynamics and Self-Organization Göttingen -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU Affero General Public License as -// * published by the Free Software Foundation, either version 3 of the -// * License, or (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU Affero General Public License for more details. -// * -// * You should have received a copy of the GNU Affero General Public License -// * along with this program. If not, see <https://www.gnu.org/licenses/>. -// * -// * ** end header -// */ -// package org.caosdb.server.database.backend.implementation.UnixFileSystem; -// -// import java.io.IOException; -// import java.io.InputStream; -// import org.caosdb.server.database.access.Access; -// import org.caosdb.server.database.backend.interfaces.FileCheckHash; -// import org.caosdb.server.database.exceptions.TransactionException; -// import org.caosdb.server.filesystem.Hash; -// import org.caosdb.server.filesystem.Hasher; -// -/// ** -// * TODO refactor. remove this class and let the file system back-end calculate the hash. -// * -// * @author Timm Fitschen (t.fitschen@indiscale.com) -// */ -// public class FileSystemCheckHash extends FileSystemTransaction implements FileCheckHash { -// -// public FileSystemCheckHash(final Access access) { -// super(access); -// } -// -// @Override -// public boolean execute(final InputStream stream, final Hash hash) throws TransactionException { -// try { -// Hasher hasher = Hasher.create(hash.getAlgorithm()); -// final Hash normativeHash = hasher.hash(stream); -// return hash.equals(normativeHash); -// } catch (final IOException e) { -// throw new TransactionException(e); -// } -// } -// } diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemCheckSize.java b/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemCheckSize.java deleted file mode 100644 index 768ebbd15c0fb25b87240a62fde647a3e2263af7..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemCheckSize.java +++ /dev/null @@ -1,57 +0,0 @@ -/// * -// * ** header v3.0 -// * This file is a part of the CaosDB Project. -// * -// * Copyright (C) 2018 Research Group Biomedical Physics, -// * Max-Planck-Institute for Dynamics and Self-Organization Göttingen -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU Affero General Public License as -// * published by the Free Software Foundation, either version 3 of the -// * License, or (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU Affero General Public License for more details. -// * -// * You should have received a copy of the GNU Affero General Public License -// * along with this program. If not, see <https://www.gnu.org/licenses/>. -// * -// * ** end header -// */ -// package org.caosdb.server.database.backend.implementation.UnixFileSystem; -// -// import com.google.common.base.Objects; -// import org.caosdb.server.database.access.Access; -// import org.caosdb.server.database.backend.interfaces.FileCheckSize; -// import org.caosdb.server.database.exceptions.TransactionException; -// import org.caosdb.server.entity.Message; -// import org.caosdb.server.filesystem.FSODescriptorInterface; -// -/// ** -// * TODO refactor. remove this class and let the file system back-end return the file size. -// * -// * @author Timm Fitschen (t.fitschen@indiscale.com) -// */ -// public class FileSystemCheckSize extends FileSystemTransaction implements FileCheckSize { -// -// public FileSystemCheckSize(final Access access) { -// super(access); -// } -// -// @Override -// public boolean execute(final String storage, final String path, final Long size) -// throws TransactionException { -// if (size == null) { -// return true; -// } -// try { -// final FSODescriptorInterface file = getFile(storage, path); -// boolean result = Objects.equal(size, file.getFile().length()); -// return result; -// } catch (final Message e) { -// throw new TransactionException(e); -// } -// } -// } diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemFileExists.java b/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemFileExists.java deleted file mode 100644 index ac477650ac1a6be1f10f9651c59f4787421b63fe..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemFileExists.java +++ /dev/null @@ -1,52 +0,0 @@ -/// * -// * ** header v3.0 -// * This file is a part of the CaosDB Project. -// * -// * Copyright (C) 2018 Research Group Biomedical Physics, -// * Max-Planck-Institute for Dynamics and Self-Organization Göttingen -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU Affero General Public License as -// * published by the Free Software Foundation, either version 3 of the -// * License, or (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU Affero General Public License for more details. -// * -// * You should have received a copy of the GNU Affero General Public License -// * along with this program. If not, see <https://www.gnu.org/licenses/>. -// * -// * ** end header -// */ -// package org.caosdb.server.database.backend.implementation.UnixFileSystem; -// -// import java.io.File; -// import org.caosdb.server.database.access.Access; -// import org.caosdb.server.database.backend.interfaces.FileExists; -// import org.caosdb.server.database.exceptions.TransactionException; -// import org.caosdb.server.entity.Message; -// -/// ** -// * TODO refactor. remove this class and let the file system back-end decide if the file exists. -// * -// * @author Timm Fitschen (t.fitschen@indiscale.com) -// */ -// public class FileSystemFileExists extends FileSystemTransaction implements FileExists { -// -// public FileSystemFileExists(final Access access) { -// super(access); -// } -// -// @Override -// public boolean execute(final String storage, final String path) throws TransactionException { -// try { -// final File f = getFile(storage, path).getFile(); -// final boolean ret = f.exists(); -// return ret; -// } catch (final Message e) { -// throw new TransactionException(e); -// } -// } -// } diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemFileWasModifiedAfter.java b/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemFileWasModifiedAfter.java deleted file mode 100644 index f692f5cd524d330e3186642db743c6e39f47f959..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemFileWasModifiedAfter.java +++ /dev/null @@ -1,54 +0,0 @@ -/// * -// * ** header v3.0 -// * This file is a part of the CaosDB Project. -// * -// * Copyright (C) 2018 Research Group Biomedical Physics, -// * Max-Planck-Institute for Dynamics and Self-Organization Göttingen -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU Affero General Public License as -// * published by the Free Software Foundation, either version 3 of the -// * License, or (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU Affero General Public License for more details. -// * -// * You should have received a copy of the GNU Affero General Public License -// * along with this program. If not, see <https://www.gnu.org/licenses/>. -// * -// * ** end header -// */ -// package org.caosdb.server.database.backend.implementation.UnixFileSystem; -// -// import java.io.File; -// import org.caosdb.server.database.access.Access; -// import org.caosdb.server.database.backend.interfaces.FileWasModifiedAfter; -// import org.caosdb.server.database.exceptions.TransactionException; -// import org.caosdb.server.entity.Message; -// -/// ** -// * TODO refactor. remove this class and let the file system back-end return the last-modified -// date. -// * -// * @author Timm Fitschen (t.fitschen@indiscale.com) -// */ -// public class FileSystemFileWasModifiedAfter extends FileSystemTransaction -// implements FileWasModifiedAfter { -// -// public FileSystemFileWasModifiedAfter(final Access access) { -// super(access); -// } -// -// @Override -// public boolean execute(final String storage, final String path, final Long timestamp) -// throws TransactionException { -// try { -// final File f = getFile(storage, path).getFile(); -// return f.lastModified() > timestamp; -// } catch (final Message e) { -// throw new TransactionException(e); -// } -// } -// } diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemGetFileIterator.java b/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemGetFileIterator.java deleted file mode 100644 index 12cf752fbd39e72bd11188bae1bf2bff72318e2d..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemGetFileIterator.java +++ /dev/null @@ -1,101 +0,0 @@ -/// * -// * ** header v3.0 -// * This file is a part of the CaosDB Project. -// * -// * Copyright (C) 2018 Research Group Biomedical Physics, -// * Max-Planck-Institute for Dynamics and Self-Organization Göttingen -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU Affero General Public License as -// * published by the Free Software Foundation, either version 3 of the -// * License, or (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU Affero General Public License for more details. -// * -// * You should have received a copy of the GNU Affero General Public License -// * along with this program. If not, see <https://www.gnu.org/licenses/>. -// * -// * ** end header -// */ -// package org.caosdb.server.database.backend.implementation.UnixFileSystem; -// -// import java.io.File; -// import java.util.Arrays; -// import java.util.Iterator; -// import org.caosdb.server.database.access.Access; -// import org.caosdb.server.database.backend.interfaces.GetFileIteratorImpl; -// import org.caosdb.server.database.exceptions.TransactionException; -// import org.caosdb.server.entity.Message; -// -// public class FileSystemGetFileIterator extends FileSystemTransaction -// implements GetFileIteratorImpl { -// -// public FileSystemGetFileIterator(final Access access) { -// super(access); -// } -// -// @Override -// public Iterator<String> execute(final String storage, final String location) -// throws TransactionException { -// File base; -// try { -// // TODO: move everything to GetFileIterator and refactor. Needs a listFiles -// // Transaction -// base = getFile(storage, location).getFile(); -// } catch (final Message e) { -// throw new TransactionException(e); -// } -// return new FileNameIterator(base, location); -// } -// -// public static class FileNameIterator implements Iterator<String> { -// -// private final File base; -// private File[] files = null; -// private FileNameIterator subfiles = null; -// private int i = 0; -// private final String rootPath; -// -// public FileNameIterator(final File base, final String rootPath) { -// this.rootPath = rootPath.length() == 0 || rootPath.endsWith("/") ? rootPath : rootPath + -// "/"; -// this.base = base; -// this.files = this.base.listFiles(); -// Arrays.sort(this.files); -// } -// -// @Override -// public boolean hasNext() { -// return this.files.length > this.i; -// } -// -// @Override -// public String next() { -// if (this.subfiles != null) { -// if (this.subfiles.hasNext()) { -// return this.subfiles.next(); -// } else { -// this.subfiles = null; -// } -// } -// final File ret = this.files[this.i++]; -// if (ret.isDirectory()) { -// this.subfiles = new FileNameIterator(ret, this.rootPath + ret.getName() + "/"); -// if (this.subfiles.hasNext()) { -// return next(); -// } else { -// return this.rootPath + ret.getName() + "/"; -// } -// } -// return this.rootPath + ret.getName(); -// } -// -// @Override -// public void remove() { -// throw new UnsupportedOperationException(); -// } -// } -// } diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemTransaction.java b/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemTransaction.java deleted file mode 100644 index 1f6766a70a03b478f04c7d37353c26d89a92f5df..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/FileSystemTransaction.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.caosdb.server.database.backend.implementation.UnixFileSystem; - -import org.caosdb.server.database.access.Access; -import org.caosdb.server.database.backend.interfaces.BackendTransactionImpl; -import org.caosdb.server.database.misc.TransactionBenchmark; -import org.caosdb.server.entity.Message; -import org.caosdb.server.filesystem.FSODescriptorInterface; -import org.caosdb.server.filesystem.FileSystem; -import org.caosdb.server.filesystem.FileSystemInterface; - -/** - * Encapsulates the FileSystem access an brings the access to the file system into a form which is - * consistent with any other interaction with the storage back-ends. - * - * <p>This class is also responsible for measuring the file-system access performance. - * - * @author Timm Fitschen (t.fitschen@indiscale.com) - */ -public abstract class FileSystemTransaction implements BackendTransactionImpl { - - private Access access; - private TransactionBenchmark transactionBenchmark; - private FileSystemInterface fileSystem = FileSystem.getInstance(); - - public FileSystemTransaction(Access access) { - this.access = access; - } - - public Access getAccess() { - return access; - } - - @Override - public void setTransactionBenchmark(TransactionBenchmark b) { - this.transactionBenchmark = b; - } - - @Override - public TransactionBenchmark getBenchmark() { - return transactionBenchmark; - } - - public FileSystemInterface getFileSystem() { - return fileSystem; - } - - public FSODescriptorInterface getFile(String storage, String path) throws Message { - return fileSystem.resolve(storage, path); - } -} diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/ResolveFile.java b/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/ResolveFile.java deleted file mode 100644 index 28b27de61e60d28110d2749d0588a174486a2afa..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/implementation/UnixFileSystem/ResolveFile.java +++ /dev/null @@ -1,18 +0,0 @@ -// package org.caosdb.server.database.backend.implementation.UnixFileSystem; -// -// import org.caosdb.server.database.access.Access; -// import org.caosdb.server.database.backend.interfaces.ResolveFileImpl; -// import org.caosdb.server.entity.Message; -// import org.caosdb.server.filesystem.FSODescriptorInterface; -// -// public class ResolveFile extends FileSystemTransaction implements ResolveFileImpl { -// -// public ResolveFile(Access access) { -// super(access); -// } -// -// @Override -// public FSODescriptorInterface resolveFile(String fileStorageId, String fileKey) throws Message { -// return getFileSystem().resolve(fileStorageId, fileKey); -// } -// } diff --git a/src/main/java/org/caosdb/server/database/backend/interfaces/DeleteFileImpl.java b/src/main/java/org/caosdb/server/database/backend/interfaces/DeleteFileImpl.java deleted file mode 100644 index 40cd48f1440f243d68e4cb09c6b4daaf36394954..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/interfaces/DeleteFileImpl.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.caosdb.server.database.backend.interfaces; - -import org.caosdb.server.entity.Message; -import org.caosdb.server.filesystem.FSODescriptorInterface; -import org.caosdb.server.utils.Undoable; - -public interface DeleteFileImpl extends BackendTransactionImpl { - - Undoable delete(FSODescriptorInterface fileDescriptor) throws Message; -} diff --git a/src/main/java/org/caosdb/server/database/backend/interfaces/FileCheckSize.java b/src/main/java/org/caosdb/server/database/backend/interfaces/FileCheckSize.java deleted file mode 100644 index b9644d17e4f151b23a8c1c0eb4bd531e133b8727..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/interfaces/FileCheckSize.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ** header v3.0 - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2018 Research Group Biomedical Physics, - * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header - */ -package org.caosdb.server.database.backend.interfaces; - -import org.caosdb.server.database.exceptions.TransactionException; - -public interface FileCheckSize extends BackendTransactionImpl { - - public boolean execute(String storage, String path, Long size) throws TransactionException; -} diff --git a/src/main/java/org/caosdb/server/database/backend/interfaces/FileExists.java b/src/main/java/org/caosdb/server/database/backend/interfaces/FileExists.java deleted file mode 100644 index 36cf762c5853920237d6e310ec12f34724c1692c..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/interfaces/FileExists.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ** header v3.0 - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2018 Research Group Biomedical Physics, - * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header - */ -package org.caosdb.server.database.backend.interfaces; - -import org.caosdb.server.database.exceptions.TransactionException; - -public interface FileExists extends BackendTransactionImpl { - - public boolean execute(String storage, String path) throws TransactionException; -} diff --git a/src/main/java/org/caosdb/server/database/backend/interfaces/FileWasModifiedAfter.java b/src/main/java/org/caosdb/server/database/backend/interfaces/FileWasModifiedAfter.java deleted file mode 100644 index 143797ff099d47fea14e893ac2cb0a9aa8e420a0..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/interfaces/FileWasModifiedAfter.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ** header v3.0 - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2018 Research Group Biomedical Physics, - * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header - */ -package org.caosdb.server.database.backend.interfaces; - -import org.caosdb.server.database.exceptions.TransactionException; - -public interface FileWasModifiedAfter extends BackendTransactionImpl { - - public boolean execute(String storage, String path, Long timestamp) throws TransactionException; -} diff --git a/src/main/java/org/caosdb/server/database/backend/interfaces/GetFileIteratorImpl.java b/src/main/java/org/caosdb/server/database/backend/interfaces/GetFileIteratorImpl.java deleted file mode 100644 index cb6609a90c560c75f276f74e209232abf0221a89..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/interfaces/GetFileIteratorImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ** header v3.0 - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2018 Research Group Biomedical Physics, - * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header - */ -package org.caosdb.server.database.backend.interfaces; - -import java.util.Iterator; -import org.caosdb.server.database.exceptions.TransactionException; - -public interface GetFileIteratorImpl extends BackendTransactionImpl { - - public Iterator<String> execute(String storage, String location) throws TransactionException; -} diff --git a/src/main/java/org/caosdb/server/database/backend/interfaces/StoreFileImpl.java b/src/main/java/org/caosdb/server/database/backend/interfaces/StoreFileImpl.java deleted file mode 100644 index a6e3da0e10d7bfb61262f9199232f7afc29a569f..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/database/backend/interfaces/StoreFileImpl.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.caosdb.server.database.backend.interfaces; - -import org.caosdb.server.entity.Message; -import org.caosdb.server.filesystem.VirtualFSODescriptorInterface; -import org.caosdb.server.utils.Undoable; - -public interface StoreFileImpl extends BackendTransactionImpl { - - public Undoable store(VirtualFSODescriptorInterface file) throws Message; -} diff --git a/src/main/java/org/caosdb/server/database/backend/transaction/DeleteFile.java b/src/main/java/org/caosdb/server/database/backend/transaction/DeleteFile.java index c48ef84ba7fa01aaa0fa0151204c21a10cdf5d01..e387171bff1b65885fc5f328e3f932baeb701bdc 100644 --- a/src/main/java/org/caosdb/server/database/backend/transaction/DeleteFile.java +++ b/src/main/java/org/caosdb/server/database/backend/transaction/DeleteFile.java @@ -23,10 +23,10 @@ package org.caosdb.server.database.backend.transaction; import org.caosdb.server.database.BackendTransaction; -import org.caosdb.server.database.backend.interfaces.DeleteFileImpl; import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.entity.EntityInterface; import org.caosdb.server.entity.Message; +import org.caosdb.server.filesystem.FileSystem; public class DeleteFile extends BackendTransaction { @@ -39,8 +39,7 @@ public class DeleteFile extends BackendTransaction { @Override public void execute() throws TransactionException { try { - DeleteFileImpl t = getImplementation(DeleteFileImpl.class); - getUndoHandler().append(t.delete(this.entity.getFSODescriptor())); + getUndoHandler().append(FileSystem.getInstance().delete(this.entity.getFSODescriptor())); } catch (final Message m) { this.entity.addError(m); throw new TransactionException(m); diff --git a/src/main/java/org/caosdb/server/database/backend/transaction/GetFileIterator.java b/src/main/java/org/caosdb/server/database/backend/transaction/GetFileIterator.java index 3fe8f2fc97a364fc1d0109224bc3db69a933b7d9..4a150c428444b710aa25d80a18f8948d72abf509 100644 --- a/src/main/java/org/caosdb/server/database/backend/transaction/GetFileIterator.java +++ b/src/main/java/org/caosdb/server/database/backend/transaction/GetFileIterator.java @@ -24,7 +24,6 @@ package org.caosdb.server.database.backend.transaction; import java.util.Iterator; import org.caosdb.server.database.BackendTransaction; -import org.caosdb.server.database.backend.interfaces.GetFileIteratorImpl; import org.caosdb.server.database.exceptions.TransactionException; /** @@ -35,18 +34,12 @@ import org.caosdb.server.database.exceptions.TransactionException; public class GetFileIterator extends BackendTransaction { private Iterator<String> iterator; - private final String location; - private String storage; - public GetFileIterator(final String fileStorageId, final String directory) { - this.location = directory; - this.storage = fileStorageId; - } + public GetFileIterator(final String fileStorageId, final String directory) {} @Override protected void execute() throws TransactionException { - final GetFileIteratorImpl t = getImplementation(GetFileIteratorImpl.class); - this.iterator = t.execute(this.storage, this.location); + // TODO } public Iterator<String> getIterator() { diff --git a/src/main/java/org/caosdb/server/database/backend/transaction/StoreFile.java b/src/main/java/org/caosdb/server/database/backend/transaction/StoreFile.java index 102d6eb83935bee01eca7f612dd023d71be09b15..ed796d32eca6aa9374d1b8c5929aecfdbe86b79f 100644 --- a/src/main/java/org/caosdb/server/database/backend/transaction/StoreFile.java +++ b/src/main/java/org/caosdb/server/database/backend/transaction/StoreFile.java @@ -23,10 +23,11 @@ package org.caosdb.server.database.backend.transaction; import org.caosdb.server.database.BackendTransaction; -import org.caosdb.server.database.backend.interfaces.StoreFileImpl; import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.entity.EntityInterface; import org.caosdb.server.entity.Message; +import org.caosdb.server.filesystem.FileSystem; +import org.caosdb.server.filesystem.RealFSODescriptorInterface; import org.caosdb.server.utils.EntityStatus; public class StoreFile extends BackendTransaction { @@ -40,11 +41,10 @@ public class StoreFile extends BackendTransaction { @Override public void execute() { if (this.entity.getEntityStatus() == EntityStatus.QUALIFIED) { - + RealFSODescriptorInterface twin = entity.getFSODescriptor().getTwin(); try { - StoreFileImpl t = getImplementation(StoreFileImpl.class); + getUndoHandler().append(FileSystem.getInstance().move(twin, entity.getFSODescriptor())); - getUndoHandler().append(t.store(this.entity.getFSODescriptor())); } catch (final Message m) { this.entity.addMessage(m); throw new TransactionException(m); diff --git a/src/main/java/org/caosdb/server/entity/container/WritableContainer.java b/src/main/java/org/caosdb/server/entity/container/WritableContainer.java index 33f433941b2856904616a213d67b95d3a4ce01ef..dc88de5731c6948314f7594c14ae3e2d621814fd 100644 --- a/src/main/java/org/caosdb/server/entity/container/WritableContainer.java +++ b/src/main/java/org/caosdb/server/entity/container/WritableContainer.java @@ -24,7 +24,6 @@ package org.caosdb.server.entity.container; import java.util.HashMap; import org.apache.shiro.SecurityUtils; import org.apache.shiro.subject.Subject; -import org.caosdb.server.filesystem.RealFSODescriptorInterface; public class WritableContainer extends TransactionContainer { private static final long serialVersionUID = -4097777313518959519L; @@ -40,9 +39,4 @@ public class WritableContainer extends TransactionContainer { public WritableContainer() { this(SecurityUtils.getSubject(), System.currentTimeMillis(), null, null); } - - @Override - public void addFile(final String uploadId, final RealFSODescriptorInterface fileProperties) { - super.addFile(uploadId, fileProperties); - } } diff --git a/src/main/java/org/caosdb/server/filesystem/FileStorageInterface.java b/src/main/java/org/caosdb/server/filesystem/FileStorageInterface.java index 5e41e7c372252e976ce90a5aee5d87a064b5373c..f0b8be54c72e20eaf3b75164a94ce5d3a85bfce1 100644 --- a/src/main/java/org/caosdb/server/filesystem/FileStorageInterface.java +++ b/src/main/java/org/caosdb/server/filesystem/FileStorageInterface.java @@ -47,40 +47,10 @@ public interface FileStorageInterface { public abstract Hash getHash(FSODescriptorInterface fso, String algorithm); - // /** - // * If key identifies a link in this file storage, return a descriptor for that file. - // * - // * <p>Otherwise, return null. - // * - // * <p>The returned descriptor has the following properties: - // * - // * <p>If the descriptor has a file the link is intact. Otherwise the link is broken and the - // target - // * does not exist. - // * - // * <p>If the target is indeed stored in this file storage, the fileStorageId and the key of - // the - // * descriptor are non-null. A null fileStorageId or key indicates that the target lies outside - // of - // * this file storage. - // * - // * @param key - // * @return A descriptor of the target. - // */ - // public abstract FSODescriptorInterface resolveLinkTarget(String key); - - // /** - // * Try and resolve the key for the given descriptor. - // * - // * <p>There is no guarantee that it works. - // * - // * @param fso - // * @return true if the resolution did indeed work. - // */ - // public abstract boolean resolveKey(FSODescriptorInterface fso); - /** Return true iff an object with this key exists. */ public abstract boolean exists(String key); - // public abstract boolean resolve(FSODescriptorInterface fso); + /* + * fileIterator(String keyPrefix, Long lastModifiedAfter, + */ } diff --git a/src/main/java/org/caosdb/server/filesystem/LocalFileStorage.java b/src/main/java/org/caosdb/server/filesystem/LocalFileStorage.java index 03b96d2f994fb7f396e63bff21df4838c23671ae..b2666d26e3b7f0fe0b29f45ecfbfa1fd9b0973c7 100644 --- a/src/main/java/org/caosdb/server/filesystem/LocalFileStorage.java +++ b/src/main/java/org/caosdb/server/filesystem/LocalFileStorage.java @@ -629,34 +629,6 @@ public abstract class LocalFileStorage implements FileStorageInterface { } return null; } - // - // @Override - // public RealFSODescriptorInterface resolveLinkTarget(String key) { - // File file = getFile(key); - // if (isSymlink(file)) { - // try { - // FSODescriptor result = new LocalFSODescriptor(kkkk); - // return result; - // } catch (IOException e) { - // throw new FileSystemException( - // "Could not resolve the link target: " + file.getAbsolutePath()); - // } - // } else { - // throw new FileSystemException("Not a symlink: " + id + ":" + key); - // } - // } - - // @Override - // public boolean resolveKey(FSODescriptorInterface fso) { - // Path absolute = fso.getFile().toPath().toAbsolutePath(); - // if (absolute.startsWith(getRoot())) { - // String key = getRoot().relativize(absolute).toString(); - // fso.setKey(key); - // fso.setFileStorageId(id); - // return true; - // } - // return false; - // } @Override public boolean exists(String key) { @@ -702,4 +674,67 @@ public abstract class LocalFileStorage implements FileStorageInterface { throw new RuntimeException(e); } } + + // @Override + // public Iterator<String> execute(final String storage, final String location) + // throws TransactionException { + // File base; + // try { + // // TODO: move everything to GetFileIterator and refactor. Needs a listFiles + // // Transaction + // base = getFile(storage, location).getFile(); + // } catch (final Message e) { + // throw new TransactionException(e); + // } + // return new FileNameIterator(base, location); + // } + // + // public static class FileNameIterator implements Iterator<String> { + // + // private final File base; + // private File[] files = null; + // private FileNameIterator subfiles = null; + // private int i = 0; + // private final String rootPath; + // + // public FileNameIterator(final File base, final String rootPath) { + // this.rootPath = rootPath.length() == 0 || rootPath.endsWith("/") ? rootPath : rootPath + + // "/"; + // this.base = base; + // this.files = this.base.listFiles(); + // Arrays.sort(this.files); + // } + // + // @Override + // public boolean hasNext() { + // return this.files.length > this.i; + // } + // + // @Override + // public String next() { + // if (this.subfiles != null) { + // if (this.subfiles.hasNext()) { + // return this.subfiles.next(); + // } else { + // this.subfiles = null; + // } + // } + // final File ret = this.files[this.i++]; + // if (ret.isDirectory()) { + // this.subfiles = new FileNameIterator(ret, this.rootPath + ret.getName() + "/"); + // if (this.subfiles.hasNext()) { + // return next(); + // } else { + // return this.rootPath + ret.getName() + "/"; + // } + // } + // return this.rootPath + ret.getName(); + // } + // + // @Override + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // } + // } } diff --git a/src/main/java/org/caosdb/server/filesystem/StoreFile.java b/src/main/java/org/caosdb/server/filesystem/StoreFile.java deleted file mode 100644 index b538c2e5a28eb46ad4f8b585e53948280c2e88a2..0000000000000000000000000000000000000000 --- a/src/main/java/org/caosdb/server/filesystem/StoreFile.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.caosdb.server.filesystem; - -import org.caosdb.server.database.access.Access; -import org.caosdb.server.database.backend.implementation.UnixFileSystem.FileSystemTransaction; -import org.caosdb.server.database.backend.interfaces.StoreFileImpl; -import org.caosdb.server.entity.Message; -import org.caosdb.server.utils.Undoable; - -public class StoreFile extends FileSystemTransaction implements StoreFileImpl { - - public StoreFile(Access access) { - super(access); - } - - @Override - public Undoable store(VirtualFSODescriptorInterface file) throws Message { - RealFSODescriptorInterface twin = file.getTwin(); - return FileSystem.getInstance().move(twin, file); - } -} diff --git a/src/main/java/org/caosdb/server/filesystem/consistency/AbstractConsistencyEvent.java b/src/main/java/org/caosdb/server/filesystem/consistency/AbstractConsistencyEvent.java index 05b2bea612d17161268c97dbbeff327a269fa3e2..fabedaf7ffdf216a301e6e751a829ea620e2b687 100644 --- a/src/main/java/org/caosdb/server/filesystem/consistency/AbstractConsistencyEvent.java +++ b/src/main/java/org/caosdb/server/filesystem/consistency/AbstractConsistencyEvent.java @@ -10,7 +10,6 @@ public class AbstractConsistencyEvent implements ConsistencyEvent { private String fileStorageId; private String key; private String type; - // private ConsistencyEvent parent; private String uuid = null; private Long timestamp; @@ -21,10 +20,6 @@ public class AbstractConsistencyEvent implements ConsistencyEvent { this.fileStorageId = fileStorageId; this.key = key; } - // - // AbstractConsistencyEvent(String name, String fileStorageId, String key) { - // this(name, null, fileStorageId, key); - // } @Override public String getFileStorageId() { diff --git a/src/main/java/org/caosdb/server/transaction/FileStorageConsistencyCheck.java b/src/main/java/org/caosdb/server/transaction/FileStorageConsistencyCheck.java index 473dc8c869c0b25fbda4d0c0513148bbd1f4c7d0..df876fdc418bbf1985a6e78b0de68b98888060ec 100644 --- a/src/main/java/org/caosdb/server/transaction/FileStorageConsistencyCheck.java +++ b/src/main/java/org/caosdb/server/transaction/FileStorageConsistencyCheck.java @@ -80,10 +80,6 @@ public class FileStorageConsistencyCheck extends Thread this.ts = System.currentTimeMillis(); while (iterator != null && iterator.hasNext()) { final String path = iterator.next(); - // this prevents all thumbnails from being checked. - if (path.contains(".thumbnails/")) { - continue; - } if (DatabaseAccessManager.whoHasReservedWriteAccess() != null) { // there is a thread waiting to write. pause this one and