From a1f0df6d5d86e72a91be8bc731d135c2475804f0 Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 4 Mar 2024 13:05:41 +0100 Subject: [PATCH] added list of active SEB Settings for version --- .../examconfig/impl/AttributeMapping.java | 19 ---------- .../impl/ConfigurationAttributeDAOImpl.java | 36 ++++++++++++++++--- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AttributeMapping.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AttributeMapping.java index 73fd23b7..739d7ee7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AttributeMapping.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AttributeMapping.java @@ -48,28 +48,9 @@ public class AttributeMapping { Objects.requireNonNull(attributes); Objects.requireNonNull(orientations); - Set _config_attrs_ids = null; - try { - final ClassPathResource configFileResource = new ClassPathResource("config/examConfigAttrVersionTable"); - final String ids_comma_separated = IOUtils.toString(configFileResource.getInputStream()); - final String[] split = StringUtils.split(ids_comma_separated, Constants.LIST_SEPARATOR_CHAR); - _config_attrs_ids = Arrays.stream(split).map(s -> { - try { - return Long.valueOf(s.trim()); - } catch (Exception e) { - return 0L; - } - }).collect(Collectors.toSet()); - } catch (final Exception e) { - log.error("Failed to get exam config attribute version infos: ", e); - } - - final Set config_attrs_ids = _config_attrs_ids; this.templateId = templateId; - this.orientationAttributeMapping = Utils.immutableMapOf(orientations .stream() - .filter(o -> config_attrs_ids == null || config_attrs_ids.contains(o.attributeId)) .collect(Collectors.toMap( o -> o.attributeId, Function.identity()))); 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 907379da..570b1156 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 @@ -10,16 +10,16 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.dao.impl; 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.*; import java.util.function.Predicate; import java.util.stream.Collectors; +import ch.ethz.seb.sebserver.gbl.Constants; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.mybatis.dynamic.sql.SqlBuilder; import org.springframework.context.annotation.Lazy; +import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -50,6 +50,7 @@ public class ConfigurationAttributeDAOImpl implements ConfigurationAttributeDAO private final ConfigurationAttributeRecordMapper configurationAttributeRecordMapper; private final ConfigurationValueRecordMapper configurationValueRecordMapper; private final OrientationRecordMapper orientationRecordMapper; + private final Set config_attrs_ids; protected ConfigurationAttributeDAOImpl( final ConfigurationAttributeRecordMapper configurationAttributeRecordMapper, @@ -59,6 +60,25 @@ public class ConfigurationAttributeDAOImpl implements ConfigurationAttributeDAO this.configurationAttributeRecordMapper = configurationAttributeRecordMapper; this.configurationValueRecordMapper = configurationValueRecordMapper; this.orientationRecordMapper = orientationRecordMapper; + + Set _config_attrs_ids = null; + try { + final ClassPathResource configFileResource = new ClassPathResource("config/examConfigAttrVersionTable"); + final String ids_comma_separated = IOUtils.toString(configFileResource.getInputStream()); + final String[] split = StringUtils.split(ids_comma_separated, Constants.LIST_SEPARATOR_CHAR); + _config_attrs_ids = Arrays.stream(split).map(s -> { + try { + return Long.valueOf(s.trim()); + } catch (Exception e) { + return 0L; + } + }).collect(Collectors.toSet()); + } catch (final Exception e) { + log.error("Failed to get exam config attribute version infos: ", e); + _config_attrs_ids = null; + } + + config_attrs_ids = _config_attrs_ids; } @Override @@ -123,6 +143,7 @@ public class ConfigurationAttributeDAOImpl implements ConfigurationAttributeDAO .build() .execute() .stream() + .filter(this::settingsVersionFilter) .map(ConfigurationAttributeDAOImpl::toDomainModel) .flatMap(DAOLoggingSupport::logAndSkipOnError) .filter(predicate) @@ -156,11 +177,16 @@ public class ConfigurationAttributeDAOImpl implements ConfigurationAttributeDAO .build() .execute() .stream() + .filter(this::settingsVersionFilter) .map(ConfigurationAttributeDAOImpl::toDomainModel) .flatMap(DAOLoggingSupport::logAndSkipOnError) .collect(Collectors.toList())); } + private boolean settingsVersionFilter(final ConfigurationAttributeRecord record) { + return config_attrs_ids == null || config_attrs_ids.contains(record.getId()); + } + @Override @Transactional public Result createNew(final ConfigurationAttribute data) {