diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceConfig.java b/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceConfig.java index 7952243e..febe709a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceConfig.java @@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.webservice; import org.cryptonode.jncryptor.AES256JNCryptor; import org.cryptonode.jncryptor.JNCryptor; import org.flywaydb.core.Flyway; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -24,6 +25,9 @@ import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; @WebServiceProfile public class WebserviceConfig { + @Value("${sebserver.webservice.clean-db-on-startup:false}") + boolean cleanDBOnStartup; + @Lazy @Bean public JNCryptor jnCryptor() { @@ -42,7 +46,9 @@ public class WebserviceConfig { final FlywayMigrationStrategy strategy = new FlywayMigrationStrategy() { @Override public void migrate(final Flyway flyway) { - flyway.clean(); + if (WebserviceConfig.this.cleanDBOnStartup) { + flyway.clean(); + } flyway.migrate(); } }; diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/PaginationService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/PaginationService.java index 6bad52a1..8799ab75 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/PaginationService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/PaginationService.java @@ -53,7 +53,15 @@ public interface PaginationService { /** Get a Page of specified domain models from given pagination attributes within collection supplier delegate. * - * + * NOTE: Paging always depends on SQL level. It depends on the collection given by the SQL select statement + * that is executed within MyBatis by using the MyBatis page service. + * Be aware that if the delegate that is given here applies an additional filter to the filtering done + * on SQL level, this will lead to paging with not fully filled pages or even to empty pages if the filter + * filters a lot of the entries given by the SQL statement away. + * So we recommend to apply as much of the filtering as possible on the SQL level and only if necessary and + * not avoidable, apply a additional filter on software-level that eventually filter one or two entities + * for a page. + * * @param pageNumber the current page number * @param pageSize the (full) size of the page * @param sort the name of the sort column with a leading '-' for descending sort order diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserActivityLogDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserActivityLogDAOImpl.java index 98d586c9..48ca1015 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserActivityLogDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserActivityLogDAOImpl.java @@ -294,7 +294,7 @@ public class UserActivityLogDAOImpl implements UserActivityLogDAO { return all( filterMap.getInstitutionId(), - filterMap.getString(UserActivityLog.FILTER_ATTR_USER_NAME), + filterMap.getSQLWildcard(UserActivityLog.FILTER_ATTR_USER_NAME), filterMap.getUserLogFrom(), filterMap.getUserLofTo(), filterMap.getString(UserActivityLog.FILTER_ATTR_ACTIVITY_TYPES), @@ -321,14 +321,6 @@ public class UserActivityLogDAOImpl implements UserActivityLogDAO { ? Arrays.asList(StringUtils.split(entityTypes, Constants.LIST_SEPARATOR)) : null; - Predicate _predicate = (predicate != null) - ? predicate - : model -> true; - - if (StringUtils.isNotBlank(userName)) { - _predicate = _predicate.and(model -> model.getUsername().contains(userName)); - } - final List records = this.userLogRecordMapper .selectByExample() .leftJoin(UserRecordDynamicSqlSupport.userRecord) @@ -338,6 +330,9 @@ public class UserActivityLogDAOImpl implements UserActivityLogDAO { .where( UserRecordDynamicSqlSupport.institutionId, SqlBuilder.isEqualToWhenPresent(institutionId)) + .and( + UserRecordDynamicSqlSupport.username, + SqlBuilder.isLikeWhenPresent(userName)) .and( UserActivityLogRecordDynamicSqlSupport.timestamp, SqlBuilder.isGreaterThanOrEqualToWhenPresent(from)) @@ -355,7 +350,7 @@ public class UserActivityLogDAOImpl implements UserActivityLogDAO { return this.toDomainModel(institutionId, records) .stream() - .filter(_predicate) + .filter(predicate) .collect(Collectors.toList()); }); } diff --git a/src/main/resources/config/application-dev-ws.properties b/src/main/resources/config/application-dev-ws.properties index 5ec2c44f..5f63b1b0 100644 --- a/src/main/resources/config/application-dev-ws.properties +++ b/src/main/resources/config/application-dev-ws.properties @@ -10,7 +10,7 @@ spring.datasource.url=jdbc:mariadb://localhost:3306/SEBServer?createDatabaseIfNo spring.datasource.driver-class-name=org.mariadb.jdbc.Driver spring.flyway.enabled=true spring.flyway.locations=classpath:config/sql/base,classpath:config/sql/dev -spring.flyway.baselineOnMigrate=true +spring.flyway.cleanDisabled=false spring.datasource.hikari.initializationFailTimeout=30000 spring.datasource.hikari.connectionTimeout=30000 spring.datasource.hikari.idleTimeout=600000 @@ -20,6 +20,8 @@ sebserver.http.client.connect-timeout=15000 sebserver.http.client.connection-request-timeout=10000 sebserver.http.client.read-timeout=20000 +sebserver.webservice.clean-db-on-startup=false + # webservice configuration sebserver.init.adminaccount.gen-on-init=false sebserver.webservice.distributed=false diff --git a/src/main/resources/config/application.properties b/src/main/resources/config/application.properties index abc6595c..54584a1c 100644 --- a/src/main/resources/config/application.properties +++ b/src/main/resources/config/application.properties @@ -72,6 +72,7 @@ spring.datasource.initialization-mode=always spring.datasource.url=jdbc:mariadb://${datastore.mariadb.server.address}:${datastore.mariadb.server.port}/SEBServer?useSSL=false&createDatabaseIfNotExist=true spring.flyway.enabled=true spring.flyway.locations=classpath:config/sql/base +spring.flyway.cleanDisabled=true spring.datasource.driver-class-name=org.mariadb.jdbc.Driver spring.datasource.hikari.initializationFailTimeout=3000 spring.datasource.hikari.connectionTimeout=30000