From 191b10b8be8913d7b5d423db050f61ee52de8ff3 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 5 Apr 2023 15:44:19 +0200 Subject: [PATCH] SEBSERV-412 fixed config key --- .../ch/ethz/seb/sebserver/gbl/api/API.java | 1 + .../content/configs/SEBExamConfigForm.java | 8 ++++++-- .../gui/content/exam/ExamFormConfigs.java | 2 +- .../sebconfig/ExamConfigService.java | 9 +++++++-- .../sebconfig/impl/ExamConfigIO.java | 4 ++-- .../sebconfig/impl/ExamConfigServiceImpl.java | 19 +++++++++++++------ .../api/ConfigurationNodeController.java | 9 +++++++-- 7 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/API.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/API.java index fc8c70f2..bea28beb 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/API.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/API.java @@ -174,6 +174,7 @@ public final class API { public static final String CONFIGURATION_NODE_ENDPOINT = "/configuration-node"; public static final String CONFIGURATION_FOLLOWUP_PATH_SEGMENT = "/followup"; + public static final String PARAM_FOLLOWUP = "followup"; public static final String CONFIGURATION_CONFIG_KEY_PATH_SEGMENT = "/configkey"; public static final String CONFIGURATION_SETTINGS_PUBLISHED_PATH_SEGMENT = "/settings_published"; public static final String CONFIGURATION_ENDPOINT = "/configuration"; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigForm.java index b4957ff1..e8ceddc4 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigForm.java @@ -336,7 +336,7 @@ public class SEBExamConfigForm implements TemplateComposer { .newAction(ActionDefinition.SEB_EXAM_CONFIG_GET_CONFIG_KEY) .withEntityKey(entityKey) - .withExec(SEBExamConfigForm.getConfigKeyFunction(this.pageService)) + .withExec(SEBExamConfigForm.getConfigKeyFunction(this.pageService, true)) .noEventPropagation() .publishIf(() -> modifyGrant && isReadonly) @@ -504,11 +504,15 @@ public class SEBExamConfigForm implements TemplateComposer { return null; } - public static Function getConfigKeyFunction(final PageService pageService) { + public static Function getConfigKeyFunction( + final PageService pageService, + final boolean followup) { + final RestService restService = pageService.getResourceService().getRestService(); return action -> { final ConfigKey configKey = restService.getBuilder(ExportConfigKey.class) .withURIVariable(API.PARAM_MODEL_ID, action.getEntityKey().modelId) + .withQueryParam(API.PARAM_FOLLOWUP, String.valueOf(followup)) .call() .getOrThrow(); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamFormConfigs.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamFormConfigs.java index c994c9e3..7132c693 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamFormConfigs.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamFormConfigs.java @@ -227,7 +227,7 @@ public class ExamFormConfigs implements TemplateComposer { if (examConfigMappingKey != null) { action.withEntityKey(examConfigMappingKey); return SEBExamConfigForm - .getConfigKeyFunction(this.pageService) + .getConfigKeyFunction(this.pageService, false) .apply(action); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/ExamConfigService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/ExamConfigService.java index 3255a62a..552533f3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/ExamConfigService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/ExamConfigService.java @@ -44,7 +44,7 @@ public interface ExamConfigService { Result getFollowupConfigurationId(final Long examConfigNodeId); /** Used to export a specified SEB Exam Configuration as plain XML - * This exports the values of the follow-up configuration defined by a given + * This exports the values of the last published changes of a given * ConfigurationNode (configurationNodeId) * * @param out The output stream to write the plain XML text to. @@ -102,8 +102,13 @@ public interface ExamConfigService { * * @param institutionId the institutional id * @param configurationNodeId the configurationNodeId + * @param stable indicates if the follow-up configuration entey shall be used or otherwise the last stable + * to calculate the config key * @return Result refer to the generated Config-Key or to an error if happened. */ - Result generateConfigKey(Long institutionId, Long configurationNodeId); + Result generateConfigKey( + Long institutionId, + Long configurationNodeId, + boolean followup); /** Generates a list of Config-Key from a given Exam by collecting all the SEB Exam Configurations that are attached * to this Exam diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigIO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigIO.java index 0adc714e..3ffd726e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigIO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigIO.java @@ -105,7 +105,7 @@ public class ExamConfigIO { } @Async(AsyncServiceSpringConfig.EXECUTOR_BEAN_NAME) - void exportForConfigKeyGeneration( + void exportForConfig( final OutputStream out, final Long institutionId, final Long configurationNodeId, @@ -122,7 +122,7 @@ public class ExamConfigIO { final Long configId) throws Exception { if (log.isDebugEnabled()) { - log.debug("Start export SEB plain XML configuration asynconously"); + log.debug("Start export SEB plain XML configuration asynchronously"); } try { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigServiceImpl.java index 84457059..b7950998 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigServiceImpl.java @@ -273,11 +273,18 @@ public class ExamConfigServiceImpl implements ExamConfigService { @Override public Result generateConfigKey( final Long institutionId, - final Long configurationNodeId) { + final Long configurationNodeId, + final boolean followup) { - return this.configurationDAO - .getConfigurationLastStableVersion(configurationNodeId) - .flatMap(config -> generateConfigKey(institutionId, configurationNodeId, config.id)); + if (followup) { + return this.configurationDAO + .getFollowupConfiguration(configurationNodeId) + .flatMap(config -> generateConfigKey(institutionId, configurationNodeId, config.id)); + } else { + return this.configurationDAO + .getConfigurationLastStableVersion(configurationNodeId) + .flatMap(config -> generateConfigKey(institutionId, configurationNodeId, config.id)); + } } private Result generateConfigKey( @@ -295,7 +302,7 @@ public class ExamConfigServiceImpl implements ExamConfigService { pout = new PipedOutputStream(); pin = new PipedInputStream(pout); - this.examConfigIO.exportForConfigKeyGeneration( + this.examConfigIO.exportForConfig( pout, institutionId, configurationNodeId, @@ -335,7 +342,7 @@ public class ExamConfigServiceImpl implements ExamConfigService { return this.examConfigurationMapDAO.getConfigurationNodeIds(examId) .map(ids -> ids .stream() - .map(id -> generateConfigKey(institutionId, id) + .map(id -> generateConfigKey(institutionId, id, false) .getOrThrow()) .collect(Collectors.toList())); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ConfigurationNodeController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ConfigurationNodeController.java index d426bda4..beb2624e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ConfigurationNodeController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ConfigurationNodeController.java @@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.mybatis.dynamic.sql.SqlTable; import org.slf4j.Logger; @@ -239,13 +240,17 @@ public class ConfigurationNodeController extends EntityController