SEBSERV-412 fixed

This commit is contained in:
anhefti 2023-04-06 09:46:15 +02:00
parent 191b10b8be
commit cbc54fb3d0
4 changed files with 36 additions and 30 deletions

View file

@ -49,19 +49,14 @@ public interface ExamConfigService {
* *
* @param out The output stream to write the plain XML text to. * @param out The output stream to write the plain XML text to.
* @param institutionId The identifier of the institution of the requesting user * @param institutionId The identifier of the institution of the requesting user
* @param configurationNodeId the identifier of the ConfigurationNode to export */ * @param configurationNodeId the identifier of the ConfigurationNode to export
void exportPlainXML(OutputStream out, Long institutionId, Long configurationNodeId); * @param followup indicates if the follow-up configuration entry shall be used or otherwise the last stable
* to export SEB Settings */
/** Used to export a specified SEB Exam Configuration as plain JSON void exportPlainXML(
* This exports the values of the follow-up configuration defined by a given OutputStream out,
* ConfigurationNode (configurationNodeId) and sorts the attributes recording to Long institutionId,
* the SEB configuration JSON specification to create a Config-Key as Long configurationNodeId,
* described here: https://www.safeexambrowser.org/developer/seb-config-key.html boolean followup);
*
* @param out The output stream to write the plain JSON text to.
* @param institutionId The identifier of the institution of the requesting user
* @param configurationNodeId the identifier of the ConfigurationNode to export */
void exportPlainJSON(OutputStream out, Long institutionId, Long configurationNodeId);
/** Used to export the default SEB Exam Configuration for a given exam identifier. /** Used to export the default SEB Exam Configuration for a given exam identifier.
* either with encryption if defined or as plain text within the SEB Configuration format * either with encryption if defined or as plain text within the SEB Configuration format
@ -102,7 +97,7 @@ public interface ExamConfigService {
* *
* @param institutionId the institutional id * @param institutionId the institutional id
* @param configurationNodeId the configurationNodeId * @param configurationNodeId the configurationNodeId
* @param stable indicates if the follow-up configuration entey shall be used or otherwise the last stable * @param followup indicates if the follow-up configuration entry shall be used or otherwise the last stable
* to calculate the config key * to calculate the config key
* @return Result refer to the generated Config-Key or to an error if happened. */ * @return Result refer to the generated Config-Key or to an error if happened. */
Result<String> generateConfigKey( Result<String> generateConfigKey(

View file

@ -104,6 +104,17 @@ public class ExamConfigIO {
exportPlain(exportFormat, out, institutionId, configurationNodeId, null); exportPlain(exportFormat, out, institutionId, configurationNodeId, null);
} }
@Async(AsyncServiceSpringConfig.EXECUTOR_BEAN_NAME)
void exportForConfig(
final ConfigurationFormat exportFormat,
final OutputStream out,
final Long institutionId,
final Long configurationNodeId,
final Long configId) throws Exception {
exportPlain(exportFormat, out, institutionId, configurationNodeId, configId);
}
@Async(AsyncServiceSpringConfig.EXECUTOR_BEAN_NAME) @Async(AsyncServiceSpringConfig.EXECUTOR_BEAN_NAME)
void exportForConfig( void exportForConfig(
final OutputStream out, final OutputStream out,

View file

@ -146,18 +146,14 @@ public class ExamConfigServiceImpl implements ExamConfigService {
public void exportPlainXML( public void exportPlainXML(
final OutputStream out, final OutputStream out,
final Long institutionId, final Long institutionId,
final Long configurationNodeId) { final Long configurationNodeId,
final boolean followup) {
this.exportPlainOnly(ConfigurationFormat.XML, out, institutionId, configurationNodeId); Long configId = null;
} if (followup) {
configId = this.configurationDAO.getFollowupConfigurationId(configurationNodeId).getOr(null);
@Override }
public void exportPlainJSON( this.exportPlainOnly(ConfigurationFormat.XML, out, institutionId, configurationNodeId, configId);
final OutputStream out,
final Long institutionId,
final Long configurationNodeId) {
this.exportPlainOnly(ConfigurationFormat.JSON, out, institutionId, configurationNodeId);
} }
public Result<Long> getDefaultConfigurationIdForExam(final Long examId) { public Result<Long> getDefaultConfigurationIdForExam(final Long examId) {
@ -264,7 +260,7 @@ public class ExamConfigServiceImpl implements ExamConfigService {
} }
} else { } else {
// just export in plain text XML format // just export in plain text XML format
this.exportPlainXML(out, institutionId, configurationNodeId); this.exportPlainXML(out, institutionId, configurationNodeId, false);
} }
return configurationNodeId; return configurationNodeId;
@ -505,7 +501,8 @@ public class ExamConfigServiceImpl implements ExamConfigService {
final ConfigurationFormat exportFormat, final ConfigurationFormat exportFormat,
final OutputStream out, final OutputStream out,
final Long institutionId, final Long institutionId,
final Long configurationNodeId) { final Long configurationNodeId,
final Long configId) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Start to stream plain text SEB Configuration data"); log.debug("Start to stream plain text SEB Configuration data");
@ -517,11 +514,12 @@ public class ExamConfigServiceImpl implements ExamConfigService {
pout = new PipedOutputStream(); pout = new PipedOutputStream();
pin = new PipedInputStream(pout); pin = new PipedInputStream(pout);
this.examConfigIO.exportPlain( this.examConfigIO.exportForConfig(
exportFormat, exportFormat,
pout, pout,
institutionId, institutionId,
configurationNodeId); configurationNodeId,
configId);
IOUtils.copyLarge(pin, out); IOUtils.copyLarge(pin, out);

View file

@ -275,10 +275,12 @@ public class ConfigurationNodeController extends EntityController<ConfigurationN
final ServletOutputStream outputStream = response.getOutputStream(); final ServletOutputStream outputStream = response.getOutputStream();
try { try {
this.sebExamConfigService.exportPlainXML( this.sebExamConfigService.exportPlainXML(
outputStream, outputStream,
institutionId, institutionId,
modelId); modelId,
true);
response.setStatus(HttpStatus.OK.value()); response.setStatus(HttpStatus.OK.value());
} catch (final Exception e) { } catch (final Exception e) {