diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/BatchActionDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/BatchActionDAOImpl.java index 94b99627..6956dad4 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/BatchActionDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/BatchActionDAOImpl.java @@ -13,6 +13,7 @@ import static org.mybatis.dynamic.sql.SqlBuilder.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -212,14 +213,20 @@ public class BatchActionDAOImpl implements BatchActionDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.batchActionRecordMapper.selectByExample() - .where(BatchActionRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(this::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.batchActionRecordMapper.selectByExample() + .where(BatchActionRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(this::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override @@ -293,6 +300,10 @@ public class BatchActionDAOImpl implements BatchActionDAO { final List ids = extractListOfPKs(all); + if (ids.isEmpty()) { + return Collections.emptyList(); + } + this.batchActionRecordMapper.deleteByExample() .where(BatchActionRecordDynamicSqlSupport.id, isIn(ids)) .build() diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java index e4435cd7..17d73500 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java @@ -141,7 +141,7 @@ public class ClientConnectionDAOImpl implements ClientConnectionDAO { @Transactional(readOnly = true) public Result> allOf(final Set pks) { if (pks == null || pks.isEmpty()) { - return Result.ofRuntimeError("Null or empty set reference"); + return Result.of(Collections.emptyList()); } return Result.tryCatch(() -> this.clientConnectionRecordMapper.selectByExample() .where(ClientConnectionRecordDynamicSqlSupport.id, SqlBuilder.isIn(new ArrayList<>(pks))) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientEventDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientEventDAOImpl.java index 4f45949a..e073bab0 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientEventDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientEventDAOImpl.java @@ -13,6 +13,7 @@ import static org.mybatis.dynamic.sql.SqlBuilder.*; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Set; import java.util.function.Predicate; @@ -186,14 +187,21 @@ public class ClientEventDAOImpl implements ClientEventDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.clientEventRecordMapper.selectByExample() - .where(ClientEventRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(ClientEventDAOImpl::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.clientEventRecordMapper.selectByExample() + .where(ClientEventRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(ClientEventDAOImpl::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override @@ -378,6 +386,10 @@ public class ClientEventDAOImpl implements ClientEventDAO { public Result> delete(final Set all) { return Result.tryCatch(() -> { + if (all == null || all.isEmpty()) { + return Collections.emptyList(); + } + final List pks = all .stream() .map(EntityKey::getModelId) @@ -402,12 +414,20 @@ public class ClientEventDAOImpl implements ClientEventDAO { public Result> deleteClientNotification(final Set keys) { return Result.tryCatch(() -> { + if (keys == null || keys.isEmpty()) { + return Collections.emptyList(); + } + final List pks = keys .stream() .map(EntityKey::getModelId) .map(Long::parseLong) .collect(Collectors.toList()); + if (log.isDebugEnabled()) { + log.debug("Going to delete all client notifications: {}", pks); + } + this.clientNotificationRecordMapper .deleteByExample() .where(ClientNotificationRecordDynamicSqlSupport.id, isIn(pks)) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationAttributeDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationAttributeDAOImpl.java index ea907528..cc3b6697 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationAttributeDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationAttributeDAOImpl.java @@ -12,6 +12,7 @@ import static org.mybatis.dynamic.sql.SqlBuilder.isIn; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Set; import java.util.function.Predicate; @@ -75,14 +76,21 @@ public class ConfigurationAttributeDAOImpl implements ConfigurationAttributeDAO @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.configurationAttributeRecordMapper.selectByExample() - .where(ConfigurationAttributeRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(ConfigurationAttributeDAOImpl::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.configurationAttributeRecordMapper.selectByExample() + .where(ConfigurationAttributeRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(ConfigurationAttributeDAOImpl::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override @@ -191,6 +199,10 @@ public class ConfigurationAttributeDAOImpl implements ConfigurationAttributeDAO final List ids = extractListOfPKs(all); final List result = new ArrayList<>(); + if (ids == null || ids.isEmpty()) { + return result; + } + // if this is a complex attribute that has children, delete the children first final List children = this.configurationAttributeRecordMapper.selectByExample() diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java index af4d7658..a7790ca7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java @@ -552,15 +552,17 @@ class ConfigurationDAOBatchService { .collect(Collectors.toList()); // first delete all old values of this table - this.batchConfigurationValueRecordMapper.deleteByExample() - .where( - ConfigurationValueRecordDynamicSqlSupport.configurationId, - isEqualTo(value.configurationId)) - .and( - ConfigurationValueRecordDynamicSqlSupport.configurationAttributeId, - SqlBuilder.isIn(columnAttributeIds)) - .build() - .execute(); + if (!columnAttributeIds.isEmpty()) { + this.batchConfigurationValueRecordMapper.deleteByExample() + .where( + ConfigurationValueRecordDynamicSqlSupport.configurationId, + isEqualTo(value.configurationId)) + .and( + ConfigurationValueRecordDynamicSqlSupport.configurationAttributeId, + SqlBuilder.isIn(columnAttributeIds)) + .build() + .execute(); + } // then add the new values for (final TableValue tableValue : value.values) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOImpl.java index a76b57a1..5ce765ff 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOImpl.java @@ -8,6 +8,22 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.dao.impl; +import static org.mybatis.dynamic.sql.SqlBuilder.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.BooleanUtils; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + import ch.ethz.seb.sebserver.gbl.api.EntityType; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Configuration; import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; @@ -23,20 +39,6 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.dao.DAOLoggingSupport; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ResourceNotFoundException; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.TransactionHandler; -import org.apache.commons.lang3.BooleanUtils; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import static org.mybatis.dynamic.sql.SqlBuilder.*; @Lazy @Component @@ -72,14 +74,21 @@ public class ConfigurationDAOImpl implements ConfigurationDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.configurationRecordMapper.selectByExample() - .where(ConfigurationRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(ConfigurationDAOImpl::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.configurationRecordMapper.selectByExample() + .where(ConfigurationRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(ConfigurationDAOImpl::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java index 489c511b..f55032d5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java @@ -91,14 +91,21 @@ public class ConfigurationNodeDAOImpl implements ConfigurationNodeDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.configurationNodeRecordMapper.selectByExample() - .where(ConfigurationNodeRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(ConfigurationNodeDAOImpl::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.configurationNodeRecordMapper.selectByExample() + .where(ConfigurationNodeRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(ConfigurationNodeDAOImpl::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override @@ -225,6 +232,10 @@ public class ConfigurationNodeDAOImpl implements ConfigurationNodeDAO { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } + // find all configurations for this configuration node final List configurationIds = this.configurationRecordMapper.selectIdsByExample() .where(ConfigurationRecordDynamicSqlSupport.configurationNodeId, isIn(ids)) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationValueDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationValueDAOImpl.java index a405c450..1bfbcc7c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationValueDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationValueDAOImpl.java @@ -11,7 +11,17 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.dao.impl; import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo; import static org.mybatis.dynamic.sql.SqlBuilder.isIn; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -115,14 +125,21 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.configurationValueRecordMapper.selectByExample() - .where(ConfigurationValueRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(ConfigurationValueDAOImpl::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.configurationValueRecordMapper.selectByExample() + .where(ConfigurationValueRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(ConfigurationValueDAOImpl::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override @@ -248,6 +265,9 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO { .flatMap(this::getAttributeMapping) .map(attributeMapping -> { // get all values of the table + final ArrayList attrs = (attributeMapping != null && !attributeMapping.isEmpty()) + ? new ArrayList<>(attributeMapping.keySet()) + : null; final List values = this.configurationValueRecordMapper.selectByExample() .where( ConfigurationValueRecordDynamicSqlSupport.institutionId, @@ -257,7 +277,7 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO { isEqualTo(configurationId)) .and( ConfigurationValueRecordDynamicSqlSupport.configurationAttributeId, - SqlBuilder.isIn(new ArrayList<>(attributeMapping.keySet()))) + SqlBuilder.isInWhenPresent(attrs)) .build() .execute() .stream() @@ -329,13 +349,13 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO { rows.sort(Comparator.naturalOrder()); rows.forEach(i -> { - final Map rowValuesMapping = indexMapping.get(i); - final List rowValues = attributes - .stream() - .map(attr -> rowValuesMapping.get(attr.getId())) - .collect(Collectors.toList()); - result.add(rowValues); - }); + final Map rowValuesMapping = indexMapping.get(i); + final List rowValues = attributes + .stream() + .map(attr -> rowValuesMapping.get(attr.getId())) + .collect(Collectors.toList()); + result.add(rowValues); + }); return result; }); @@ -362,7 +382,9 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO { final Set tableValues = new HashSet<>(); if (attributeMapping != null && !attributeMapping.isEmpty()) { - + final ArrayList attrs = (attributeMapping != null && !attributeMapping.isEmpty()) + ? new ArrayList<>(attributeMapping.keySet()) + : null; tableValues.addAll(this.configurationValueRecordMapper.selectByExample() .where( ConfigurationValueRecordDynamicSqlSupport.institutionId, @@ -372,7 +394,7 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO { isEqualTo(configurationId)) .and( ConfigurationValueRecordDynamicSqlSupport.configurationAttributeId, - SqlBuilder.isIn(new ArrayList<>(attributeMapping.keySet()))) + SqlBuilder.isInWhenPresent(attrs)) .build() .execute() .stream() diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamConfigurationMapDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamConfigurationMapDAOImpl.java index 358ed409..75554471 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamConfigurationMapDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamConfigurationMapDAOImpl.java @@ -98,14 +98,21 @@ public class ExamConfigurationMapDAOImpl implements ExamConfigurationMapDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.examConfigurationMapRecordMapper.selectByExample() - .where(ExamConfigurationMapRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(this::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.examConfigurationMapRecordMapper.selectByExample() + .where(ExamConfigurationMapRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(this::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override @@ -268,6 +275,9 @@ public class ExamConfigurationMapDAOImpl implements ExamConfigurationMapDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } // get all involved configurations final List configIds = this.examConfigurationMapRecordMapper.selectByExample() diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java index 1354e23d..b9d997e4 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java @@ -217,6 +217,10 @@ public class ExamDAOImpl implements ExamDAO { final Result> tryCatch = Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } + final ExamRecord examRecord = new ExamRecord(null, null, null, null, null, null, null, null, null, null, null, null, null, BooleanUtils.toInteger(active), null, Utils.getMillisecondsNow()); @@ -484,6 +488,9 @@ public class ExamDAOImpl implements ExamDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } // notify exam deletion listener about following deletion, to cleanup stuff before deletion this.applicationEventPublisher.publishEvent(new ExamDeletionEvent(ids)); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java index 45afbbb0..e02aa7eb 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java @@ -12,6 +12,7 @@ import static org.mybatis.dynamic.sql.SqlBuilder.*; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -330,10 +331,17 @@ public class ExamRecordDAO { @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.examRecordMapper.selectByExample() - .where(ExamRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute()); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.examRecordMapper.selectByExample() + .where(ExamRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute(); + }); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamTemplateDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamTemplateDAOImpl.java index 7d369aca..ce75daa1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamTemplateDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamTemplateDAOImpl.java @@ -117,14 +117,21 @@ public class ExamTemplateDAOImpl implements ExamTemplateDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.examTemplateRecordMapper.selectByExample() - .where(IndicatorRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(this::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.examTemplateRecordMapper.selectByExample() + .where(IndicatorRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(this::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override @@ -247,6 +254,9 @@ public class ExamTemplateDAOImpl implements ExamTemplateDAO { log.info("Delete exam templates: {}", all); final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } ids.stream() .forEach(id -> { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/IndicatorDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/IndicatorDAOImpl.java index 9d465923..82f92564 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/IndicatorDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/IndicatorDAOImpl.java @@ -105,14 +105,21 @@ public class IndicatorDAOImpl implements IndicatorDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.indicatorRecordMapper.selectByExample() - .where(IndicatorRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(this::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.indicatorRecordMapper.selectByExample() + .where(IndicatorRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(this::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override @@ -193,6 +200,9 @@ public class IndicatorDAOImpl implements IndicatorDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } // first delete all thresholds of indicators this.thresholdRecordMapper.deleteByExample() diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/InstitutionDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/InstitutionDAOImpl.java index a0bcedc7..15dcbf30 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/InstitutionDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/InstitutionDAOImpl.java @@ -170,6 +170,10 @@ public class InstitutionDAOImpl implements InstitutionDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } + final InstitutionRecord institutionRecord = new InstitutionRecord( null, null, null, null, BooleanUtils.toInteger(active), null); @@ -204,6 +208,9 @@ public class InstitutionDAOImpl implements InstitutionDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } this.institutionRecordMapper.deleteByExample() .where(InstitutionRecordDynamicSqlSupport.id, isIn(ids)) @@ -226,14 +233,21 @@ public class InstitutionDAOImpl implements InstitutionDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.institutionRecordMapper.selectByExample() - .where(InstitutionRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(InstitutionDAOImpl::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.institutionRecordMapper.selectByExample() + .where(InstitutionRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(InstitutionDAOImpl::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } private Result recordById(final Long id) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/LmsSetupDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/LmsSetupDAOImpl.java index 153a83a5..4a69787c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/LmsSetupDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/LmsSetupDAOImpl.java @@ -241,6 +241,10 @@ public class LmsSetupDAOImpl implements LmsSetupDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } + final LmsSetupRecord lmsSetupRecord = new LmsSetupRecord( null, null, null, null, null, null, null, null, null, null, null, null, System.currentTimeMillis(), @@ -277,6 +281,9 @@ public class LmsSetupDAOImpl implements LmsSetupDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } this.lmsSetupRecordMapper.deleteByExample() .where(LmsSetupRecordDynamicSqlSupport.id, isIn(ids)) @@ -303,14 +310,21 @@ public class LmsSetupDAOImpl implements LmsSetupDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.lmsSetupRecordMapper.selectByExample() - .where(LmsSetupRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(this::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.lmsSetupRecordMapper.selectByExample() + .where(LmsSetupRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(this::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/OrientationDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/OrientationDAOImpl.java index aff14a17..65e8dd36 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/OrientationDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/OrientationDAOImpl.java @@ -13,6 +13,7 @@ import static org.mybatis.dynamic.sql.SqlBuilder.isIn; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -68,14 +69,21 @@ public class OrientationDAOImpl implements OrientationDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.orientationRecordMapper.selectByExample() - .where(OrientationRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(OrientationDAOImpl::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.orientationRecordMapper.selectByExample() + .where(OrientationRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(OrientationDAOImpl::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override @@ -227,6 +235,9 @@ public class OrientationDAOImpl implements OrientationDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } this.orientationRecordMapper.deleteByExample() .where(OrientationRecordDynamicSqlSupport.id, isIn(ids)) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/SEBClientConfigDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/SEBClientConfigDAOImpl.java index 8175572e..3ef769f6 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/SEBClientConfigDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/SEBClientConfigDAOImpl.java @@ -196,6 +196,10 @@ public class SEBClientConfigDAOImpl implements SEBClientConfigDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } + final SebClientConfigRecord record = new SebClientConfigRecord( null, null, null, null, null, null, null, BooleanUtils.toIntegerObject(active)); @@ -278,6 +282,9 @@ public class SEBClientConfigDAOImpl implements SEBClientConfigDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } this.sebClientConfigRecordMapper.deleteByExample() .where(SebClientConfigRecordDynamicSqlSupport.id, isIn(ids)) @@ -293,14 +300,21 @@ public class SEBClientConfigDAOImpl implements SEBClientConfigDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.sebClientConfigRecordMapper.selectByExample() - .where(SebClientConfigRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(this::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.sebClientConfigRecordMapper.selectByExample() + .where(SebClientConfigRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(this::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override 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 a511c5df..23c6f586 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 @@ -324,6 +324,9 @@ public class UserActivityLogDAOImpl implements UserActivityLogDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } this.userLogRecordMapper.deleteByExample() .where(UserActivityLogRecordDynamicSqlSupport.id, isIn(ids)) @@ -438,12 +441,19 @@ public class UserActivityLogDAOImpl implements UserActivityLogDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.toDomainModel( - this.userService.getCurrentUser().institutionId(), - this.userLogRecordMapper.selectByExample() - .where(UserActivityLogRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.toDomainModel( + this.userService.getCurrentUser().institutionId(), + this.userLogRecordMapper.selectByExample() + .where(UserActivityLogRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute()); + }); } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java index fec7fb1a..fb0a9f82 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java @@ -324,6 +324,10 @@ public class UserDAOImpl implements UserDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } + final UserRecord userRecord = new UserRecord( null, null, null, null, null, null, null, null, null, null, null, BooleanUtils.toIntegerObject(active)); @@ -363,6 +367,9 @@ public class UserDAOImpl implements UserDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } // get all user records for later processing final List users = this.userRecordMapper.selectByExample() @@ -413,14 +420,21 @@ public class UserDAOImpl implements UserDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.userRecordMapper.selectByExample() - .where(InstitutionRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(this::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.userRecordMapper.selectByExample() + .where(InstitutionRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(this::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override @@ -429,6 +443,11 @@ public class UserDAOImpl implements UserDAO { return UserDAO.super.extractPKsFromKeys(keys); } else { try { + + if (keys == null || keys.isEmpty()) { + return Collections.emptySet(); + } + final List uuids = keys.stream() .map(key -> key.modelId) .collect(Collectors.toList()); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ViewDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ViewDAOImpl.java index 49f8d02c..02e7ab4c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ViewDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ViewDAOImpl.java @@ -12,6 +12,7 @@ import static org.mybatis.dynamic.sql.SqlBuilder.isIn; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -65,14 +66,21 @@ public class ViewDAOImpl implements ViewDAO { @Override @Transactional(readOnly = true) public Result> allOf(final Set pks) { - return Result.tryCatch(() -> this.viewRecordMapper.selectByExample() - .where(ViewRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) - .build() - .execute() - .stream() - .map(ViewDAOImpl::toDomainModel) - .flatMap(DAOLoggingSupport::logAndSkipOnError) - .collect(Collectors.toList())); + return Result.tryCatch(() -> { + + if (pks == null || pks.isEmpty()) { + return Collections.emptyList(); + } + + return this.viewRecordMapper.selectByExample() + .where(ViewRecordDynamicSqlSupport.id, isIn(new ArrayList<>(pks))) + .build() + .execute() + .stream() + .map(ViewDAOImpl::toDomainModel) + .flatMap(DAOLoggingSupport::logAndSkipOnError) + .collect(Collectors.toList()); + }); } @Override @@ -212,6 +220,9 @@ public class ViewDAOImpl implements ViewDAO { return Result.tryCatch(() -> { final List ids = extractListOfPKs(all); + if (ids == null || ids.isEmpty()) { + return Collections.emptyList(); + } this.viewRecordMapper.deleteByExample() .where(ViewRecordDynamicSqlSupport.id, isIn(ids)) diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 109637e6..54a35747 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -282,7 +282,7 @@ sebserver.useraccount.delete.form.deleteExams.tooltip=This includes all Exams wh sebserver.useraccount.delete.form.action.delete=Delete sebserver.useraccount.delete.form.action.report=Show Report sebserver.useraccount.delete.confirm.title=Deletion Successful -sebserver.useraccount.delete.confirm.message=The User Account ({0}) was successfully deleted.
Also the following number dependencies where successfully deleted: {1}.

And there where {2} errors. +sebserver.useraccount.delete.confirm.message=The User Account ({0}) was successfully deleted.
Also the following number of dependencies where successfully deleted: {1}.

And there where {2} errors. sebserver.useraccount.delete.confirm.message.noDeps=The User Account ({0}) was successfully deleted. ################################ # LMS Setup