From 8bfbf9cce092e1fbb2d03a56b8253040493015c9 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Fri, 22 Jan 2021 17:22:51 +0100 Subject: [PATCH] cleanup --- .../handlers/FileUploadHandler.java | 39 -- .../handlers/GetNamesRequestHandler.java | 13 - .../transaction/handlers/IDHandler.java | 36 -- .../transaction/handlers/RequestHandler.java | 31 -- ...etrieveGlobalEntityPermissionsHandler.java | 37 -- .../handlers/RetriveOwnerRequestHandler.java | 36 -- .../handlers/SimpleDeleteRequestHandler.java | 55 --- .../handlers/SimpleGetRequestHandler.java | 38 -- .../handlers/SimpleWriteHandler.java | 34 -- .../org/caosdb/server/transaction/Delete.java | 56 --- .../org/caosdb/server/transaction/Insert.java | 59 --- .../org/caosdb/server/transaction/Update.java | 401 ------------------ .../server/transaction/WriteTransaction.java | 35 +- 13 files changed, 16 insertions(+), 854 deletions(-) delete mode 100644 src/main/java/org/caosdb/server/resource/transaction/handlers/FileUploadHandler.java delete mode 100644 src/main/java/org/caosdb/server/resource/transaction/handlers/GetNamesRequestHandler.java delete mode 100644 src/main/java/org/caosdb/server/resource/transaction/handlers/IDHandler.java delete mode 100644 src/main/java/org/caosdb/server/resource/transaction/handlers/RequestHandler.java delete mode 100644 src/main/java/org/caosdb/server/resource/transaction/handlers/RetrieveGlobalEntityPermissionsHandler.java delete mode 100644 src/main/java/org/caosdb/server/resource/transaction/handlers/RetriveOwnerRequestHandler.java delete mode 100644 src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleDeleteRequestHandler.java delete mode 100644 src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleGetRequestHandler.java delete mode 100644 src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleWriteHandler.java delete mode 100644 src/main/java/org/caosdb/server/transaction/Delete.java delete mode 100644 src/main/java/org/caosdb/server/transaction/Insert.java delete mode 100644 src/main/java/org/caosdb/server/transaction/Update.java diff --git a/src/main/java/org/caosdb/server/resource/transaction/handlers/FileUploadHandler.java b/src/main/java/org/caosdb/server/resource/transaction/handlers/FileUploadHandler.java deleted file mode 100644 index d04706e3..00000000 --- a/src/main/java/org/caosdb/server/resource/transaction/handlers/FileUploadHandler.java +++ /dev/null @@ -1,39 +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 caosdb.server.resource.transaction.handlers; -// -// import org.restlet.data.MediaType; -// import caosdb.server.entity.Message; -// import caosdb.server.entity.Message.MessageType; -// import caosdb.server.entity.container.WritableContainer; -// import caosdb.server.resource.transaction.EntityResource; -// -// public class FileUploadHandler<T extends WritableContainer> extends SimpleWriteHandler<T> { -// -// @Override -// public void handle(final EntityResource t, final T container) throws Exception { -// if (!t.getRequest().getEntity().getMediaType().equals(MediaType.MULTIPART_FORM_DATA, true)) { -// throw new Message(MessageType.Error, "Wrong MediaType"); -// } -// } -// } diff --git a/src/main/java/org/caosdb/server/resource/transaction/handlers/GetNamesRequestHandler.java b/src/main/java/org/caosdb/server/resource/transaction/handlers/GetNamesRequestHandler.java deleted file mode 100644 index 779a20b3..00000000 --- a/src/main/java/org/caosdb/server/resource/transaction/handlers/GetNamesRequestHandler.java +++ /dev/null @@ -1,13 +0,0 @@ -// package caosdb.server.resource.transaction.handlers; -// -// import caosdb.server.entity.container.RetrieveContainer; -// import caosdb.server.resource.transaction.RetrieveEntityResource; -// -// public class GetNamesRequestHandler extends RequestHandler<RetrieveContainer> { -// -// /** Adds the `names` flag to the RetrieveContainer which triggers the RetrieveAllNames job. */ -// @Override -// public void handle(RetrieveEntityResource t, RetrieveContainer container) throws Exception { -// container.getFlags().put("names", null); -// } -// } diff --git a/src/main/java/org/caosdb/server/resource/transaction/handlers/IDHandler.java b/src/main/java/org/caosdb/server/resource/transaction/handlers/IDHandler.java deleted file mode 100644 index a3256ab6..00000000 --- a/src/main/java/org/caosdb/server/resource/transaction/handlers/IDHandler.java +++ /dev/null @@ -1,36 +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 caosdb.server.resource.transaction.handlers; -// -// import caosdb.server.entity.container.EntityByIdContainer; -// import caosdb.server.resource.transaction.RetrieveEntityResource; -// -// public class IDHandler<T extends EntityByIdContainer> extends RequestHandler<T> { -// -// @Override -// public void handle(final RetrieveEntityResource t, final T container) throws Exception { -// for (final int id : t.getRequestedIDs()) { -// container.add(id); -// } -// } -// } diff --git a/src/main/java/org/caosdb/server/resource/transaction/handlers/RequestHandler.java b/src/main/java/org/caosdb/server/resource/transaction/handlers/RequestHandler.java deleted file mode 100644 index 2931d526..00000000 --- a/src/main/java/org/caosdb/server/resource/transaction/handlers/RequestHandler.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 caosdb.server.resource.transaction.handlers; -// -// import caosdb.server.entity.container.TransactionContainer; -// import caosdb.server.resource.transaction.RetrieveEntityResource; -// -// public abstract class RequestHandler<T extends TransactionContainer> { -// -// public abstract void handle(final RetrieveEntityResource t, T container) throws Exception; -// } diff --git a/src/main/java/org/caosdb/server/resource/transaction/handlers/RetrieveGlobalEntityPermissionsHandler.java b/src/main/java/org/caosdb/server/resource/transaction/handlers/RetrieveGlobalEntityPermissionsHandler.java deleted file mode 100644 index d87f9a06..00000000 --- a/src/main/java/org/caosdb/server/resource/transaction/handlers/RetrieveGlobalEntityPermissionsHandler.java +++ /dev/null @@ -1,37 +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 caosdb.server.resource.transaction.handlers; -// -// import caosdb.server.entity.container.RetrieveContainer; -// import caosdb.server.permissions.EntityPermission; -// import caosdb.server.resource.transaction.RetrieveEntityResource; -// -// public class RetrieveGlobalEntityPermissionsHandler extends SimpleGetRequestHandler { -// -// @Override -// public void handle(final RetrieveEntityResource t, final RetrieveContainer container) throws -// Exception { -// super.handle(t, container); -// container.addMessage(EntityPermission.getAllEntityPermissions()); -// } -// } diff --git a/src/main/java/org/caosdb/server/resource/transaction/handlers/RetriveOwnerRequestHandler.java b/src/main/java/org/caosdb/server/resource/transaction/handlers/RetriveOwnerRequestHandler.java deleted file mode 100644 index cd059526..00000000 --- a/src/main/java/org/caosdb/server/resource/transaction/handlers/RetriveOwnerRequestHandler.java +++ /dev/null @@ -1,36 +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 caosdb.server.resource.transaction.handlers; -// -// import caosdb.server.entity.EntityInterface; -// import caosdb.server.entity.container.RetrieveContainer; -// import caosdb.server.resource.transaction.RetrieveEntityResource; -// -// public class RetriveOwnerRequestHandler extends SimpleGetRequestHandler { -// -// @Override -// public void handle(final RetrieveEntityResource t, final RetrieveContainer container) throws -// Exception { -// super.handle(t, container); -// } -// } diff --git a/src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleDeleteRequestHandler.java b/src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleDeleteRequestHandler.java deleted file mode 100644 index 02e6cfd1..00000000 --- a/src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleDeleteRequestHandler.java +++ /dev/null @@ -1,55 +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 -// * Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> -// * Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> -// * -// * 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 caosdb.server.resource.transaction.handlers; -// -// import caosdb.server.entity.container.DeleteContainer; -// import caosdb.server.resource.transaction.EntityResource; -// -// public class SimpleDeleteRequestHandler extends RequestHandler<DeleteContainer> { -// -// @Override -// public void handle(final EntityResource t, final DeleteContainer container) throws Exception { -// // TODO a lot of code duplication, see SimpleGetRequestHandle#handle. -// // However, this is about to be changed again when string ids are -// // introduced, anyways. So we just leave it. -// for (final String item : t.getRequestedItems()) { -// String[] elem = item.split("@", 1); -// Integer id = null; -// String version = null; -// try { -// id = Integer.parseInt(elem[0]); -// } catch (NumberFormatException e) { -// // pass -// } -// if (elem.length > 1) { -// version = elem[1]; -// } -// -// if (id != null) { -// container.add(id, version); -// } -// } -// } -// } diff --git a/src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleGetRequestHandler.java b/src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleGetRequestHandler.java deleted file mode 100644 index 0e127d0e..00000000 --- a/src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleGetRequestHandler.java +++ /dev/null @@ -1,38 +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 caosdb.server.resource.transaction.handlers; -// -// import caosdb.server.entity.container.RetrieveContainer; -// import caosdb.server.resource.transaction.RetrieveEntityResource; -// -// public class SimpleGetRequestHandler extends IDHandler<RetrieveContainer> { -// -// @Override -// public void handle(final RetrieveEntityResource t, final RetrieveContainer container) throws -// Exception { -// super.handle(t, container); -// for (final String name : t.getRequestedNames()) { -// container.add(name); -// } -// } -// } diff --git a/src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleWriteHandler.java b/src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleWriteHandler.java deleted file mode 100644 index a7e50270..00000000 --- a/src/main/java/org/caosdb/server/resource/transaction/handlers/SimpleWriteHandler.java +++ /dev/null @@ -1,34 +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 caosdb.server.resource.transaction.handlers; -// -// import caosdb.server.entity.container.WritableContainer; -// import caosdb.server.resource.transaction.EntityResource; -// -// public class SimpleWriteHandler<T extends WritableContainer> extends RequestHandler<T> { -// -// -// @Override -// public void handle(final EntityResource t, final T container) throws Exception { -// } -// } diff --git a/src/main/java/org/caosdb/server/transaction/Delete.java b/src/main/java/org/caosdb/server/transaction/Delete.java deleted file mode 100644 index a3bf24c8..00000000 --- a/src/main/java/org/caosdb/server/transaction/Delete.java +++ /dev/null @@ -1,56 +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 caosdb.server.transaction; -// -// import caosdb.server.entity.container.WritableContainer; -// -// public class Delete extends WriteTransaction { -// -// public Delete(final WritableContainer container) { -// super(container); -// } -// -// @Override -// protected void init() throws Exception {} -// -// @Override -// protected void preCheck() throws InterruptedException, Exception { -// } -// -// @Override -// protected void postCheck() {} -// -// @Override -// protected void postTransaction() { -// } -// -// @Override -// public void transaction() throws Exception { -// } -// -// -// @Override -// public boolean logHistory() { -// return true; -// } -// } diff --git a/src/main/java/org/caosdb/server/transaction/Insert.java b/src/main/java/org/caosdb/server/transaction/Insert.java deleted file mode 100644 index 13ef9c96..00000000 --- a/src/main/java/org/caosdb/server/transaction/Insert.java +++ /dev/null @@ -1,59 +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 caosdb.server.transaction; -// -// import caosdb.server.entity.container.WritableContainer; -// -// public class Insert extends WriteTransaction { -// -// public Insert(final WritableContainer container) { -// super(container); -// } -// -// @Override -// protected void init() throws Exception { -// -// -// } -// -// @Override -// protected void preCheck() throws InterruptedException { -// } -// -// @Override -// protected void postCheck() {} -// -// @Override -// protected void postTransaction() {} -// -// @Override -// public void transaction() throws Exception { -// // write new entities to database -// insert(getContainer(), getAccess()); -// } -// -// @Override -// public boolean logHistory() { -// return true; -// } -// } diff --git a/src/main/java/org/caosdb/server/transaction/Update.java b/src/main/java/org/caosdb/server/transaction/Update.java deleted file mode 100644 index 74fd2deb..00000000 --- a/src/main/java/org/caosdb/server/transaction/Update.java +++ /dev/null @@ -1,401 +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 caosdb.server.transaction; -// -// import java.io.IOException; -// import java.security.NoSuchAlgorithmException; -// import java.util.HashSet; -// import java.util.Set; -// import org.apache.shiro.authz.AuthorizationException; -// import com.google.common.base.Objects; -// import caosdb.server.CaosDBException; -// import caosdb.server.database.access.Access; -// import caosdb.server.database.backend.transaction.RetrieveFullEntity; -// import caosdb.server.database.backend.transaction.UpdateEntity; -// import caosdb.server.entity.Entity; -// import caosdb.server.entity.EntityInterface; -// import caosdb.server.entity.FileProperties; -// import caosdb.server.entity.RetrieveEntity; -// import caosdb.server.entity.container.TransactionContainer; -// import caosdb.server.entity.container.UpdateContainer; -// import caosdb.server.entity.wrapper.Parent; -// import caosdb.server.entity.wrapper.Property; -// import caosdb.server.permissions.EntityPermission; -// import caosdb.server.permissions.Permission; -// import caosdb.server.utils.EntityStatus; -// import caosdb.server.utils.ServerMessages; -// -// public class Update extends WriteTransaction { -// -// public Update(final UpdateContainer container) { -// super(container); -// } -// -// @Override -// protected void preCheck() throws Exception {} -// -// @Override -// protected void init() throws Exception { -// // collect all ids of the entities which are to be updated. -// final TransactionContainer oldContainer = new TransactionContainer(); -// for (final EntityInterface entity : getContainer()) { -// // entity has no id -> it cannot be updated. -// if (!entity.hasId()) { -// entity.addError(ServerMessages.ENTITY_HAS_NO_ID); -// entity.setEntityStatus(EntityStatus.UNQUALIFIED); -// continue; -// } -// -// // add entity with this id to the updateContainer -// if (entity.getEntityStatus() == EntityStatus.QUALIFIED) { -// final Entity oldEntity = new RetrieveEntity(entity.getId()); -// oldContainer.add(oldEntity); -// } -// } -// -// // allocate strong (write) access. Only one thread can do this -// // at a time. But weak access can still be acquired by other -// // thread until the allocated strong access is actually -// // acquired. -// setAccess(getMonitor().allocateStrongAccess(this)); -// -// // retrieve a container which contains all id of those entities -// // which are to be updated. -// execute(new RetrieveFullEntity(oldContainer), getAccess()); -// -// // Check if any updates are to be processed. -// for (final EntityInterface newEntity : getContainer()) { -// if (newEntity.getEntityStatus() == EntityStatus.QUALIFIED) { -// innerLoop: -// for (final EntityInterface oldEntity : oldContainer) { -// if (oldEntity.getId().equals(newEntity.getId())) { -// if (oldEntity.getEntityStatus() == EntityStatus.NONEXISTENT) { -// newEntity.addError(ServerMessages.ENTITY_DOES_NOT_EXIST); -// newEntity.setEntityStatus(EntityStatus.UNQUALIFIED); -// } else { -// // dereference files (upload only) -// if (newEntity.hasFileProperties() && !newEntity.getFileProperties().isPickupable()) -// { -// -// if (newEntity.getFileProperties().getTmpIdentifyer() != null) { -// // get file by tmpIdentifier -// final FileProperties f = -// getContainer() -// .getFiles() -// .get(newEntity.getFileProperties().getTmpIdentifyer()); -// -// // is it there? -// if (f != null) { -// newEntity.getFileProperties().setFile(f.getFile()); -// -// // has it a thumbnail? -// if (f.getThumbnail() != null) { -// newEntity.getFileProperties().setThumbnail(f.getThumbnail()); -// } else { -// final FileProperties thumbnail = -// getContainer() -// .getFiles() -// .get(newEntity.getFileProperties().getTmpIdentifyer() + -// ".thumbnail"); -// if (thumbnail != null) { -// newEntity.getFileProperties().setThumbnail(thumbnail.getFile()); -// } else { -// newEntity.addWarning(ServerMessages.THUMBNAIL_HAS_NOT_BEEN_UPLOAED); -// } -// } -// } else { -// newEntity.addError(ServerMessages.FILE_HAS_NOT_BEEN_UPLOAED); -// newEntity.setEntityStatus(EntityStatus.UNQUALIFIED); -// } -// -// } else { -// // in case no file has been uploaded, -// // the file is expected to stay -// // unchanged. Therefore we let the file -// // object point to the original file in -// // the file system. -// newEntity -// .getFileProperties() -// .setFile(oldEntity.getFileProperties().retrieveFromFileSystem()); -// } -// } -// -// try { -// checkPermissions(newEntity, deriveUpdate(newEntity, oldEntity)); -// } catch (final AuthorizationException exc) { -// newEntity.setEntityStatus(EntityStatus.UNQUALIFIED); -// newEntity.addError(ServerMessages.AUTHORIZATION_ERROR); -// newEntity.addInfo(exc.getMessage()); -// } -// } -// break innerLoop; -// } -// } -// } -// } -// -// // make schedule of those entities which are to be updated. -// makeSchedule(); -// } -// -// @Override -// protected void postCheck() {} -// -// @Override -// protected void postTransaction() {} -// -// @Override -// public void transaction() throws Exception { -// // write new entities to database -// update(getContainer(), getAccess()); -// } -// -// private void update(final TransactionContainer container, final Access access) throws Exception -// { -// if (container.getStatus().ordinal() >= EntityStatus.QUALIFIED.ordinal()) { -// execute(new UpdateEntity(container), access); -// } -// } -// -// /** Check if the user has all permissions */ -// @Override -// public void checkPermissions(final EntityInterface entity, final Set<Permission> permissions) { -// for (final Permission p : permissions) { -// entity.checkPermission(p); -// } -// } -// -// /** -// * The entity is set to VALID iff there are no updates to be processed. The entity is set to -// * QUALIFIED otherwise. -// * -// * @param newEntity -// * @param oldEntity -// * @throws CaosDBException -// * @throws IOException -// * @throws NoSuchAlgorithmException -// */ -// public static HashSet<Permission> deriveUpdate( -// final EntityInterface newEntity, final EntityInterface oldEntity) -// throws NoSuchAlgorithmException, IOException, CaosDBException { -// final HashSet<Permission> needPermissions = new HashSet<>(); -// boolean updatetable = false; -// -// // new acl? -// if (newEntity.hasEntityACL() && !newEntity.getEntityACL().equals(oldEntity.getEntityACL())) { -// oldEntity.checkPermission(EntityPermission.EDIT_ACL); -// if (!newEntity -// .getEntityACL() -// .getPriorityEntityACL() -// .equals(oldEntity.getEntityACL().getPriorityEntityACL())) { -// // priority acl is to be changed? -// oldEntity.checkPermission(Permission.EDIT_PRIORITY_ACL); -// } -// updatetable = true; -// } else if (!newEntity.hasEntityACL()) { -// newEntity.setEntityACL(oldEntity.getEntityACL()); -// } -// -// // new query template definition? -// if (!Objects.equal( -// newEntity.getQueryTemplateDefinition(), oldEntity.getQueryTemplateDefinition())) { -// needPermissions.add(EntityPermission.UPDATE_QUERY_TEMPLATE_DEFINITION); -// updatetable = true; -// } -// -// // new datatype? -// if (newEntity.hasDatatype() -// && oldEntity.hasDatatype() -// && !newEntity.getDatatype().equals(oldEntity.getDatatype()) -// || newEntity.hasDatatype() ^ oldEntity.hasDatatype()) { -// needPermissions.add(EntityPermission.UPDATE_DATA_TYPE); -// updatetable = true; -// } -// -// // entity role -// if (newEntity.hasRole() -// && oldEntity.hasRole() -// && !newEntity.getRole().equals(oldEntity.getRole()) -// || newEntity.hasRole() ^ oldEntity.hasRole()) { -// needPermissions.add(EntityPermission.UPDATE_ROLE); -// updatetable = true; -// } -// -// // entity value -// if (newEntity.hasValue() -// && oldEntity.hasValue() -// && !newEntity.getValue().equals(oldEntity.getValue()) -// || newEntity.hasValue() ^ oldEntity.hasValue()) { -// needPermissions.add(EntityPermission.UPDATE_VALUE); -// updatetable = true; -// } -// -// // entity name -// if (newEntity.hasName() -// && oldEntity.hasName() -// && !newEntity.getName().equals(oldEntity.getName()) -// || newEntity.hasName() ^ oldEntity.hasName()) { -// needPermissions.add(EntityPermission.UPDATE_NAME); -// updatetable = true; -// } -// -// // entity description -// if (newEntity.hasDescription() -// && oldEntity.hasDescription() -// && !newEntity.getDescription().equals(oldEntity.getDescription()) -// || newEntity.hasDescription() ^ oldEntity.hasDescription()) { -// needPermissions.add(EntityPermission.UPDATE_DESCRIPTION); -// updatetable = true; -// } -// -// // file properties -// if (newEntity.hasFileProperties() || oldEntity.hasFileProperties()) { -// if (newEntity.hasFileProperties() && !oldEntity.hasFileProperties()) { -// // add a file -// needPermissions.add(EntityPermission.UPDATE_ADD_FILE); -// updatetable = true; -// } else if (!newEntity.hasFileProperties() && oldEntity.hasFileProperties()) { -// // remove a file -// needPermissions.add(EntityPermission.UPDATE_REMOVE_FILE); -// updatetable = true; -// } else { -// // change file -// final FileProperties newFile = newEntity.getFileProperties(); -// final FileProperties oldFile = oldEntity.getFileProperties(); -// -// // file path -// if (newFile.hasPath() && oldFile.hasPath() && !newFile.getPath().equals(oldFile.getPath()) -// || newFile.hasPath() ^ oldFile.hasPath()) { -// // this means, the location of the file is to be changed -// needPermissions.add(EntityPermission.UPDATE_MOVE_FILE); -// updatetable = true; -// } -// -// // change actual file (different byte code!) -// if (!oldFile.retrieveFromFileSystem().equals(newFile.getFile())) { -// // CHANGE A FILE is like REMOVE AND ADD -// needPermissions.add(EntityPermission.UPDATE_REMOVE_FILE); -// needPermissions.add(EntityPermission.UPDATE_ADD_FILE); -// updatetable = true; -// } -// } -// } -// -// // properties -// outerLoop: -// for (final EntityInterface newProperty : newEntity.getProperties()) { -// -// // find corresponding oldProperty for this new property and make a -// // diff. -// if (newProperty.hasId()) { -// for (final EntityInterface oldProperty : oldEntity.getProperties()) { -// if (newProperty.getId().equals(oldProperty.getId())) { -// // do not check again. -// oldEntity.getProperties().remove(oldProperty); -// -// if (((Property) oldProperty).getPIdx() != ((Property) newProperty).getPIdx()) { -// // change order of properties -// needPermissions.add(EntityPermission.UPDATE_ADD_PROPERTY); -// needPermissions.add(EntityPermission.UPDATE_REMOVE_PROPERTY); -// updatetable = true; -// } -// -// deriveUpdate(newProperty, oldProperty); -// if (newProperty.getEntityStatus() == EntityStatus.QUALIFIED) { -// needPermissions.add(EntityPermission.UPDATE_ADD_PROPERTY); -// needPermissions.add(EntityPermission.UPDATE_REMOVE_PROPERTY); -// updatetable = true; -// } -// -// continue outerLoop; -// } -// } -// } else { -// newProperty.setEntityStatus(EntityStatus.UNQUALIFIED); -// newProperty.addError(ServerMessages.ENTITY_HAS_NO_ID); -// newProperty.addInfo("On updates, allways specify the id not just the name."); -// newEntity.addError(ServerMessages.ENTITY_HAS_UNQUALIFIED_PROPERTIES); -// newEntity.setEntityStatus(EntityStatus.UNQUALIFIED); -// return needPermissions; -// } -// -// // no corresponding property found -> this property is new. -// needPermissions.add(EntityPermission.UPDATE_ADD_PROPERTY); -// updatetable = true; -// } -// -// // some old properties left (and not matched with new ones) -> there are -// // properties to be deleted. -// if (!oldEntity.getProperties().isEmpty()) { -// needPermissions.add(EntityPermission.UPDATE_REMOVE_PROPERTY); -// updatetable = true; -// } -// -// // update parents -// outerLoop: -// for (final Parent newParent : newEntity.getParents()) { -// -// // find corresponding oldParent -// if (newParent.hasId()) { -// for (final Parent oldParent : oldEntity.getParents()) { -// if (oldParent.getId().equals(newParent.getId())) { -// // still there! do not check this one again -// oldEntity.getParents().remove(oldParent); -// continue outerLoop; -// } -// } -// } else { -// newParent.setEntityStatus(EntityStatus.UNQUALIFIED); -// newParent.addError(ServerMessages.ENTITY_HAS_NO_ID); -// newParent.addInfo("On updates, allways specify the id not just the name."); -// newEntity.addError(ServerMessages.ENTITY_HAS_UNQUALIFIED_PROPERTIES); -// newEntity.setEntityStatus(EntityStatus.UNQUALIFIED); -// return needPermissions; -// } -// -// // no corresponding parent found -> this parent is new. -// needPermissions.add(EntityPermission.UPDATE_ADD_PARENT); -// updatetable = true; -// } -// -// // some old parents left (and not matched with new ones) -> there are -// // parents to be deleted. -// if (!oldEntity.getParents().isEmpty()) { -// needPermissions.add(EntityPermission.UPDATE_REMOVE_PARENT); -// updatetable = true; -// } -// -// // nothing to be updated -// if (!updatetable) { -// newEntity.setEntityStatus(EntityStatus.VALID); -// newEntity.addInfo("Nothing to be updated."); -// } -// -// return needPermissions; -// } -// -// @Override -// public boolean logHistory() { -// return true; -// } -// } diff --git a/src/main/java/org/caosdb/server/transaction/WriteTransaction.java b/src/main/java/org/caosdb/server/transaction/WriteTransaction.java index f57d4cab..86255f21 100644 --- a/src/main/java/org/caosdb/server/transaction/WriteTransaction.java +++ b/src/main/java/org/caosdb/server/transaction/WriteTransaction.java @@ -1,19 +1,24 @@ /* - * ** header v3.0 This file is a part of the CaosDB Project. + * ** 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 + * Copyright (C) 2018 Research Group Biomedical Physics, + * Max-Planck-Institute for Dynamics and Self-Organization Göttingen + * Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> * - * 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 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. + * 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/>. + * 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 */ @@ -77,18 +82,10 @@ public class WriteTransaction extends Transaction<WritableContainer> private void update(final TransactionContainer container, final Access access) throws Exception { execute(new UpdateEntityTransaction(container), access); - setVersionDates(container); - } - - private void setVersionDates(TransactionContainer container) { - for (EntityInterface e : container) { - if (e.hasVersion()) e.getVersion().setDate(getTimestamp()); - } } private void insert(final TransactionContainer container, final Access access) throws Exception { execute(new InsertEntityTransaction(container), access); - setVersionDates(container); } private void delete(final TransactionContainer container, final Access access) throws Exception { -- GitLab