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

EHN: New behavior for FIND queries

parent 1c10e5c6
No related branches found
No related tags found
2 merge requests!96DOC: Added CITATION.cff to the list of files in the release guide where the...,!71F find query
Pipeline #30295 failed
......@@ -211,6 +211,15 @@ USER_NAME_INVALID_MESSAGE=User names must have a length from 1 to 32 characters.
PASSWORD_VALID_REGEX=^((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\\p{Punct}]).{8,128})$
PASSWORD_INVALID_MESSAGE=Passwords must have a length from 8 to 128 characters. THe must contain at least one [A-Z], one [a-z], one [0-9] and a special character e.g. [!§$%&/()=?.;,:#+*+~].
# --------------------------------------------------
# Query Settings
# --------------------------------------------------
# FIND blablabla is short for FIND $FIND_QUERY_DEFAULT_ROLE blablabla. Should be
# either ENTITY or RECORD. RECORDTYPE, FILE, and PROPERTY will work as well but
# are rather unexpected for human users.
FIND_QUERY_DEFAULT_ROLE=RECORD
# --------------------------------------------------
# Extensions
# --------------------------------------------------
......
......@@ -31,6 +31,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Properties;
import org.caosdb.server.query.Query;
import org.caosdb.server.utils.AbstractObservable;
import org.caosdb.server.utils.Observable;
import org.caosdb.server.utils.Observer;
......@@ -114,6 +115,7 @@ public class ServerProperties extends Properties implements Observable {
public static final String KEY_QUERY_FILTER_ENTITIES_WITHOUT_RETRIEVE_PERMISSIONS =
"QUERY_FILTER_ENTITIES_WITHOUT_RETRIEVE_PERMISSIONS";
public static final String KEY_FIND_QUERY_DEFAULT_ROLE = "FIND_QUERY_DEFAULT_ROLE";
public static final String KEY_SERVER_NAME = "SERVER_NAME";
......@@ -199,9 +201,25 @@ public class ServerProperties extends Properties implements Observable {
logger.info(name + "=" + val);
}
}
sanityCheck(serverProperties);
return serverProperties;
}
private static void sanityCheck(ServerProperties serverProperties) {
try {
Query.Role.valueOf(serverProperties.getProperty(KEY_FIND_QUERY_DEFAULT_ROLE));
} catch (IllegalArgumentException e) {
logger.error(
"Unsupported value for server property "
+ KEY_FIND_QUERY_DEFAULT_ROLE
+ ": "
+ serverProperties.getProperty(KEY_FIND_QUERY_DEFAULT_ROLE));
System.exit(1);
}
}
private static void loadConfigFile(final Properties serverProperties, final File confFile)
throws IOException {
if (confFile.exists() && confFile.isFile()) {
......
......@@ -55,6 +55,7 @@ import org.caosdb.server.caching.Cache;
import org.caosdb.server.database.access.Access;
import org.caosdb.server.database.backend.implementation.MySQL.ConnectionException;
import org.caosdb.server.database.backend.implementation.MySQL.MySQLHelper;
import org.caosdb.server.database.backend.transaction.RetrieveFullEntityTransaction;
import org.caosdb.server.database.backend.transaction.RetrieveSparseEntity;
import org.caosdb.server.database.misc.DBHelper;
import org.caosdb.server.database.misc.TransactionBenchmark;
......@@ -604,6 +605,22 @@ public class Query implements QueryInterface, ToElementable, TransactionInterfac
this.role = Role.ENTITY;
}
}
// "FIND Person" is interpreted as "FIND RECORD Person"
if (this.role == null) {
try {
this.role =
Role.valueOf(
CaosDBServer.getServerProperty(ServerProperties.KEY_FIND_QUERY_DEFAULT_ROLE));
} catch (IllegalArgumentException e) {
addError(
"Unsupportet value of the server property "
+ ServerProperties.KEY_FIND_QUERY_DEFAULT_ROLE
+ ": "
+ CaosDBServer.getServerProperty(ServerProperties.KEY_FIND_QUERY_DEFAULT_ROLE));
throw new UnsupportedOperationException(e);
}
}
}
private String executeStrategy(final boolean versioned) throws QueryException {
......@@ -829,6 +846,10 @@ public class Query implements QueryInterface, ToElementable, TransactionInterfac
this.messages.add(new Message(MessageType.Warning, MessageCode.MESSAGE_CODE_UNKNOWN, w));
}
private void addError(final String e) {
this.messages.add(new Message(MessageType.Error, MessageCode.MESSAGE_CODE_UNKNOWN, e));
}
private void cleanUp() {
if (getConnection() != null) {
ResultSet rs = null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment