SEBSERV-125 fix

This commit is contained in:
anhefti 2020-05-06 11:19:11 +02:00
parent 29c09adff9
commit bebb4094b6
5 changed files with 25 additions and 13 deletions

View file

@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.webservice;
import org.cryptonode.jncryptor.AES256JNCryptor; import org.cryptonode.jncryptor.AES256JNCryptor;
import org.cryptonode.jncryptor.JNCryptor; import org.cryptonode.jncryptor.JNCryptor;
import org.flywaydb.core.Flyway; import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy; import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -24,6 +25,9 @@ import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
@WebServiceProfile @WebServiceProfile
public class WebserviceConfig { public class WebserviceConfig {
@Value("${sebserver.webservice.clean-db-on-startup:false}")
boolean cleanDBOnStartup;
@Lazy @Lazy
@Bean @Bean
public JNCryptor jnCryptor() { public JNCryptor jnCryptor() {
@ -42,7 +46,9 @@ public class WebserviceConfig {
final FlywayMigrationStrategy strategy = new FlywayMigrationStrategy() { final FlywayMigrationStrategy strategy = new FlywayMigrationStrategy() {
@Override @Override
public void migrate(final Flyway flyway) { public void migrate(final Flyway flyway) {
if (WebserviceConfig.this.cleanDBOnStartup) {
flyway.clean(); flyway.clean();
}
flyway.migrate(); flyway.migrate();
} }
}; };

View file

@ -53,6 +53,14 @@ public interface PaginationService {
/** Get a Page of specified domain models from given pagination attributes within collection supplier delegate. /** 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 pageNumber the current page number
* @param pageSize the (full) size of the page * @param pageSize the (full) size of the page

View file

@ -294,7 +294,7 @@ public class UserActivityLogDAOImpl implements UserActivityLogDAO {
return all( return all(
filterMap.getInstitutionId(), filterMap.getInstitutionId(),
filterMap.getString(UserActivityLog.FILTER_ATTR_USER_NAME), filterMap.getSQLWildcard(UserActivityLog.FILTER_ATTR_USER_NAME),
filterMap.getUserLogFrom(), filterMap.getUserLogFrom(),
filterMap.getUserLofTo(), filterMap.getUserLofTo(),
filterMap.getString(UserActivityLog.FILTER_ATTR_ACTIVITY_TYPES), filterMap.getString(UserActivityLog.FILTER_ATTR_ACTIVITY_TYPES),
@ -321,14 +321,6 @@ public class UserActivityLogDAOImpl implements UserActivityLogDAO {
? Arrays.asList(StringUtils.split(entityTypes, Constants.LIST_SEPARATOR)) ? Arrays.asList(StringUtils.split(entityTypes, Constants.LIST_SEPARATOR))
: null; : null;
Predicate<UserActivityLog> _predicate = (predicate != null)
? predicate
: model -> true;
if (StringUtils.isNotBlank(userName)) {
_predicate = _predicate.and(model -> model.getUsername().contains(userName));
}
final List<UserActivityLogRecord> records = this.userLogRecordMapper final List<UserActivityLogRecord> records = this.userLogRecordMapper
.selectByExample() .selectByExample()
.leftJoin(UserRecordDynamicSqlSupport.userRecord) .leftJoin(UserRecordDynamicSqlSupport.userRecord)
@ -338,6 +330,9 @@ public class UserActivityLogDAOImpl implements UserActivityLogDAO {
.where( .where(
UserRecordDynamicSqlSupport.institutionId, UserRecordDynamicSqlSupport.institutionId,
SqlBuilder.isEqualToWhenPresent(institutionId)) SqlBuilder.isEqualToWhenPresent(institutionId))
.and(
UserRecordDynamicSqlSupport.username,
SqlBuilder.isLikeWhenPresent(userName))
.and( .and(
UserActivityLogRecordDynamicSqlSupport.timestamp, UserActivityLogRecordDynamicSqlSupport.timestamp,
SqlBuilder.isGreaterThanOrEqualToWhenPresent(from)) SqlBuilder.isGreaterThanOrEqualToWhenPresent(from))
@ -355,7 +350,7 @@ public class UserActivityLogDAOImpl implements UserActivityLogDAO {
return this.toDomainModel(institutionId, records) return this.toDomainModel(institutionId, records)
.stream() .stream()
.filter(_predicate) .filter(predicate)
.collect(Collectors.toList()); .collect(Collectors.toList());
}); });
} }

View file

@ -10,7 +10,7 @@ spring.datasource.url=jdbc:mariadb://localhost:3306/SEBServer?createDatabaseIfNo
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.flyway.enabled=true spring.flyway.enabled=true
spring.flyway.locations=classpath:config/sql/base,classpath:config/sql/dev 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.initializationFailTimeout=30000
spring.datasource.hikari.connectionTimeout=30000 spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.idleTimeout=600000 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.connection-request-timeout=10000
sebserver.http.client.read-timeout=20000 sebserver.http.client.read-timeout=20000
sebserver.webservice.clean-db-on-startup=false
# webservice configuration # webservice configuration
sebserver.init.adminaccount.gen-on-init=false sebserver.init.adminaccount.gen-on-init=false
sebserver.webservice.distributed=false sebserver.webservice.distributed=false

View file

@ -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.datasource.url=jdbc:mariadb://${datastore.mariadb.server.address}:${datastore.mariadb.server.port}/SEBServer?useSSL=false&createDatabaseIfNotExist=true
spring.flyway.enabled=true spring.flyway.enabled=true
spring.flyway.locations=classpath:config/sql/base spring.flyway.locations=classpath:config/sql/base
spring.flyway.cleanDisabled=true
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.hikari.initializationFailTimeout=3000 spring.datasource.hikari.initializationFailTimeout=3000
spring.datasource.hikari.connectionTimeout=30000 spring.datasource.hikari.connectionTimeout=30000