Skip to content
Snippets Groups Projects
Unverified Commit f1cd5d27 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Merge branch 'dev' into f-anonymous-user

parents 9b8815a2 dca49be8
No related branches found
No related tags found
No related merge requests found
Showing
with 209 additions and 24 deletions
......@@ -145,7 +145,7 @@ public class ServerProperties extends Properties {
serverProperties.setProperty(KEY_MYSQL_USER_NAME, "CaosDB");
serverProperties.setProperty(KEY_MYSQL_USER_PASSWORD, "CaosDB");
serverProperties.setProperty(KEY_MYSQL_SCHEMA_VERSION, "v2.0.31");
serverProperties.setProperty(KEY_MYSQL_SCHEMA_VERSION, "v2.1.0");
serverProperties.setProperty(KEY_BASE_PATH, basepath);
serverProperties.setProperty(KEY_CONTEXT_ROOT, "");
......
/*
* ** 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.accessControl;
import org.apache.shiro.authc.AuthenticationToken;
......
/*
* ** 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.accessControl;
import org.apache.shiro.authc.AuthenticationInfo;
......
......@@ -34,6 +34,7 @@ import caosdb.server.database.backend.implementation.MySQL.MySQLGetFileRecordByP
import caosdb.server.database.backend.implementation.MySQL.MySQLGetIDByName;
import caosdb.server.database.backend.implementation.MySQL.MySQLGetInfo;
import caosdb.server.database.backend.implementation.MySQL.MySQLGetUpdateableChecksums;
import caosdb.server.database.backend.implementation.MySQL.MySQLInsertEntityDatatype;
import caosdb.server.database.backend.implementation.MySQL.MySQLInsertEntityProperties;
import caosdb.server.database.backend.implementation.MySQL.MySQLInsertLinCon;
import caosdb.server.database.backend.implementation.MySQL.MySQLInsertLogRecord;
......@@ -87,6 +88,7 @@ import caosdb.server.database.backend.interfaces.GetFileRecordByPathImpl;
import caosdb.server.database.backend.interfaces.GetIDByNameImpl;
import caosdb.server.database.backend.interfaces.GetInfoImpl;
import caosdb.server.database.backend.interfaces.GetUpdateableChecksumsImpl;
import caosdb.server.database.backend.interfaces.InsertEntityDatatypeImpl;
import caosdb.server.database.backend.interfaces.InsertEntityPropertiesImpl;
import caosdb.server.database.backend.interfaces.InsertLinConImpl;
import caosdb.server.database.backend.interfaces.InsertLogRecordImpl;
......@@ -131,13 +133,11 @@ public abstract class BackendTransaction implements Undoable {
BackendTransaction parent = null;
private static HashMap<
Class<? extends BackendTransactionImpl>, Class<? extends BackendTransactionImpl>>
impl =
new HashMap<
Class<? extends BackendTransactionImpl>, Class<? extends BackendTransactionImpl>>();
impl = new HashMap<>();
protected abstract void execute() throws TransactionException;
protected abstract void execute();
final void executeTransaction() throws TransactionException {
final void executeTransaction() {
final long t1 = System.currentTimeMillis();
execute();
final long t2 = System.currentTimeMillis();
......@@ -194,10 +194,11 @@ public abstract class BackendTransaction implements Undoable {
setImpl(SetQueryTemplateDefinitionImpl.class, MySQLSetQueryTemplateDefinition.class);
setImpl(
RetrieveQueryTemplateDefinitionImpl.class, MySQLRetrieveQueryTemplateDefinition.class);
setImpl(InsertEntityDatatypeImpl.class, MySQLInsertEntityDatatype.class);
}
}
protected <K extends BackendTransaction> K execute(final K t) throws TransactionException {
protected <K extends BackendTransaction> K execute(final K t) {
assert t != this;
this.undoHandler.append(t);
t.setAccess(this.access);
......@@ -219,8 +220,7 @@ public abstract class BackendTransaction implements Undoable {
}
@SuppressWarnings("unchecked")
protected <T extends BackendTransactionImpl> T getImplementation(final Class<T> clz)
throws TransactionException {
protected <T extends BackendTransactionImpl> T getImplementation(final Class<T> clz) {
init();
try {
final T ret = (T) impl.get(clz).getConstructor(Access.class).newInstance(this.access);
......
package caosdb.server.database.backend.implementation.MySQL;
import caosdb.server.database.access.Access;
import caosdb.server.database.backend.interfaces.InsertEntityDatatypeImpl;
import caosdb.server.database.exceptions.IntegrityException;
import caosdb.server.database.exceptions.TransactionException;
import caosdb.server.database.proto.SparseEntity;
import java.sql.PreparedStatement;
import java.sql.SQLIntegrityConstraintViolationException;
public class MySQLInsertEntityDatatype extends MySQLTransaction
implements InsertEntityDatatypeImpl {
public MySQLInsertEntityDatatype(Access access) {
super(access);
}
public static final String STMT_INSERT_ENTITY_DATATYPE =
"INSERT INTO data_type (domain_id, entity_id, property_id, datatype) SELECT 0, 0, ?, ( SELECT id from entities where name = ? LIMIT 1);";
public static final String STMT_INSERT_ENTITY_COLLECTION =
"INSERT INTO collection_type (domain_id, entity_id, property_id, collection) SELECT 0, 0, ?, ?;";
@Override
public void execute(final SparseEntity entity) {
try {
final PreparedStatement insertEntityDatatypeStmt =
prepareStatement(STMT_INSERT_ENTITY_DATATYPE);
insertEntityDatatypeStmt.setInt(1, entity.id);
insertEntityDatatypeStmt.setString(2, entity.datatype);
insertEntityDatatypeStmt.execute();
if (entity.collection != null) {
final PreparedStatement insertEntityCollectionStmt =
prepareStatement(STMT_INSERT_ENTITY_COLLECTION);
insertEntityCollectionStmt.setInt(1, entity.id);
insertEntityCollectionStmt.setString(2, entity.collection);
insertEntityCollectionStmt.execute();
}
} catch (final SQLIntegrityConstraintViolationException exc) {
throw new IntegrityException(exc);
} catch (final TransactionException exc) {
throw exc;
} catch (final Exception exc) {
throw new TransactionException(exc);
}
}
}
......@@ -38,12 +38,12 @@ public class MySQLInsertSparseEntity extends MySQLTransaction implements InsertS
super(access);
}
public static final String STMT_INSERT_SPARSE_ENTITY = "call insertEntity(?,?,?,?,?,?)";
public static final String STMT_INSERT_SPARSE_ENTITY = "call insertEntity(?,?,?,?)";
public static final String STMT_INSERT_FILE_PROPERTIES =
"INSERT INTO files (file_id, hash, size, path) VALUES (?, unhex(?), ?, ?);";
@Override
public void execute(final SparseEntity entity) throws TransactionException {
public void execute(final SparseEntity entity) {
try {
final PreparedStatement insertEntityStmt = prepareStatement(STMT_INSERT_SPARSE_ENTITY);
final PreparedStatement insertFilePropsStmt = prepareStatement(STMT_INSERT_FILE_PROPERTIES);
......@@ -51,15 +51,14 @@ public class MySQLInsertSparseEntity extends MySQLTransaction implements InsertS
insertEntityStmt.setString(1, entity.name);
insertEntityStmt.setString(2, entity.description);
insertEntityStmt.setString(3, entity.role);
insertEntityStmt.setString(4, entity.datatype);
insertEntityStmt.setString(5, entity.collection);
insertEntityStmt.setString(6, entity.acl);
insertEntityStmt.setString(4, entity.acl);
final ResultSet rs = insertEntityStmt.executeQuery();
if (rs.next()) {
entity.id = rs.getInt("EntityID");
} else {
throw new TransactionException("Didn't get new EntityID back.");
try (final ResultSet rs = insertEntityStmt.executeQuery()) {
if (rs.next()) {
entity.id = rs.getInt("EntityID");
} else {
throw new TransactionException("Didn't get new EntityID back.");
}
}
if (entity.filePath != null) {
......
package caosdb.server.database.backend.interfaces;
import caosdb.server.database.proto.SparseEntity;
import caosdb.server.utils.Undoable;
public interface InsertEntityDatatypeImpl extends BackendTransactionImpl, Undoable {
public abstract void execute(SparseEntity entity);
}
......@@ -22,11 +22,10 @@
*/
package caosdb.server.database.backend.interfaces;
import caosdb.server.database.exceptions.TransactionException;
import caosdb.server.database.proto.SparseEntity;
import caosdb.server.utils.Undoable;
public interface InsertSparseEntityImpl extends BackendTransactionImpl, Undoable {
public abstract void execute(SparseEntity entity) throws TransactionException;
public abstract void execute(SparseEntity entity);
}
......@@ -23,7 +23,6 @@
package caosdb.server.database.backend.transaction;
import caosdb.server.database.BackendTransaction;
import caosdb.server.database.exceptions.TransactionException;
import caosdb.server.entity.EntityInterface;
import caosdb.server.entity.container.TransactionContainer;
import caosdb.server.utils.EntityStatus;
......@@ -37,12 +36,17 @@ public class InsertEntity extends BackendTransaction {
}
@Override
public void execute() throws TransactionException {
public void execute() {
for (final EntityInterface newEntity : this.container) {
if (newEntity.getEntityStatus() == EntityStatus.QUALIFIED) {
execute(new InsertSparseEntity(newEntity));
}
}
for (final EntityInterface newEntity : this.container) {
if (newEntity.getEntityStatus() == EntityStatus.QUALIFIED && newEntity.hasDatatype()) {
execute(new InsertEntityDatatype(newEntity));
}
}
for (final EntityInterface newEntity : this.container) {
if (newEntity.getEntityStatus() == EntityStatus.QUALIFIED) {
if (newEntity.getQueryTemplateDefinition() != null) {
......@@ -51,7 +55,6 @@ public class InsertEntity extends BackendTransaction {
if (newEntity.hasFileProperties()) {
execute(new InsertFile(newEntity));
}
// execute(new InsertEntityValue(newEntity));
execute(new InsertEntityProperties(newEntity));
execute(new InsertParents(newEntity));
......
package caosdb.server.database.backend.transaction;
import static caosdb.server.transaction.Transaction.ERROR_INTEGRITY_VIOLATION;
import caosdb.server.database.BackendTransaction;
import caosdb.server.database.backend.interfaces.InsertEntityDatatypeImpl;
import caosdb.server.database.exceptions.IntegrityException;
import caosdb.server.database.proto.SparseEntity;
import caosdb.server.entity.EntityInterface;
import caosdb.server.utils.EntityStatus;
public class InsertEntityDatatype extends BackendTransaction {
private final EntityInterface entity;
public InsertEntityDatatype(final EntityInterface entity) {
this.entity = entity;
}
@Override
public void execute() {
final InsertEntityDatatypeImpl t = getImplementation(InsertEntityDatatypeImpl.class);
final SparseEntity e = this.entity.getSparseEntity();
try {
t.execute(e);
} catch (final IntegrityException exc) {
this.entity.addError(ERROR_INTEGRITY_VIOLATION);
this.entity.setEntityStatus(EntityStatus.CORRUPT);
throw exc;
}
this.entity.setId(e.id);
}
}
/*
* ** 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.scripting;
import caosdb.server.CaosDBException;
......
/*
* ** 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.utils;
public interface Serializer<T, S> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment