Skip to content

Commit

Permalink
SEBSERV-553 fixed show quit link and improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
anhefti committed Jun 25, 2024
1 parent 485273d commit 8b30771
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ch/ethz/seb/sebserver/gbl/api/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private BatchActionType(final EntityType entityType) {
public static final String LMS_FULL_INTEGRATION_EXAM_TEMPLATE_ID = "exam_template_id";
public static final String LMS_FULL_INTEGRATION_EXAM_DATA = "exam_data";
public static final String LMS_FULL_INTEGRATION_QUIT_PASSWORD = "quit_password";
public static final String LMS_FULL_INTEGRATION_QUIT_LINK = "quit_link";
public static final String LMS_FULL_INTEGRATION_QUIT_LINK = "show_quit_link";
public static final String LMS_FULL_INTEGRATION_USER_ID = "user_id";
public static final String LMS_FULL_INTEGRATION_USER_NAME = "user_username";
public static final String LMS_FULL_INTEGRATION_USER_EMAIL = "user_email";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,6 @@ Result<Set<EntityKey>> setDefaultValues(
* @param pwd The hashed quit password
* @return Result refer to void or to an error when happened*/
Result<Void> saveQuitPassword(Long configurationId, String pwd);

Result<ConfigurationValue> saveForce(ConfigurationValue configurationValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,41 +268,17 @@ public Result<ConfigurationValue> createNew(final ConfigurationValue data) {
public Result<ConfigurationValue> save(final ConfigurationValue data) {
return checkInstitutionalIntegrity(data)
.map(this::checkFollowUpIntegrity)
.flatMap(this::attributeRecord)
.map(attributeRecord -> {

final Long id;
if (data.id == null) {

id = getByProperties(data)
.orElseGet(() -> {
log.debug("Missing SEB exam configuration attrribute value for: {}", data);
log.debug("Use self-healing strategy to recover from missing SEB exam "
+ "configuration attrribute value\n**** Create new AttributeValue for: {}",
data);
.map(this::saveData)
.flatMap(ConfigurationValueDAOImpl::toDomainModel)
.onError(TransactionHandler::rollback);
}

createNew(data);
return getByProperties(data)
.orElseThrow(() -> new ResourceNotFoundException(
EntityType.CONFIGURATION_VALUE,
String.valueOf(data.attributeId)));

});
} else {
id = data.id;
}

final ConfigurationValueRecord newRecord = new ConfigurationValueRecord(
id,
null,
null,
null,
data.listIndex,
data.value);

this.configurationValueRecordMapper.updateByPrimaryKeySelective(newRecord);
return this.configurationValueRecordMapper.selectByPrimaryKey(id);
})
@Override
public Result<ConfigurationValue> saveForce(final ConfigurationValue data) {
return checkInstitutionalIntegrity(data)
.map(this::saveData)
.flatMap(ConfigurationValueDAOImpl::toDomainModel)
.onError(TransactionHandler::rollback);
}
Expand Down Expand Up @@ -708,4 +684,38 @@ private Optional<Long> getByProperties(final ConfigurationValue data) {
.findFirst();
}

private ConfigurationValueRecord saveData(final ConfigurationValue data) {
final Long id;
if (data.id == null) {

id = getByProperties(data)
.orElseGet(() -> {
log.debug("Missing SEB exam configuration attrribute value for: {}", data);
log.debug("Use self-healing strategy to recover from missing SEB exam "
+ "configuration attrribute value\n**** Create new AttributeValue for: {}",
data);

createNew(data);
return getByProperties(data)
.orElseThrow(() -> new ResourceNotFoundException(
EntityType.CONFIGURATION_VALUE,
String.valueOf(data.attributeId)));

});
} else {
id = data.id;
}

final ConfigurationValueRecord newRecord = new ConfigurationValueRecord(
id,
null,
null,
null,
data.listIndex,
data.value);

this.configurationValueRecordMapper.updateByPrimaryKeySelective(newRecord);
return this.configurationValueRecordMapper.selectByPrimaryKey(id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,25 @@ default boolean isScreenProctoringEnabled(final Exam exam) {
/** Updates needed additional attributes from assigned exam configuration for the exam
*
* @param examId The exam identifier */
void updateAdditionalExamConfigAttributes(final Long examId);
void updateAdditionalExamConfigAttributes(Long examId);

/** This indicates if proctoring is set and enabled for a certain exam.
*
* @param examId the exam identifier
* @return Result refer to proctoring is enabled flag or to an error when happened. */
Result<Boolean> isProctoringEnabled(final Long examId);
Result<Boolean> isProctoringEnabled(Long examId);

/** This indicates if screen proctoring is set and enabled for a certain exam.
*
* @param examId the exam identifier
* @return Result refer to screen proctoring is enabled flag or to an error when happened. */
Result<Boolean> isScreenProctoringEnabled(final Long examId);
Result<Boolean> isScreenProctoringEnabled(Long examId);

/** Get the exam proctoring service implementation for specified exam.
*
* @param examId the exam identifier
* @return ExamProctoringService instance */
Result<RemoteProctoringService> getExamProctoringService(final Long examId);
Result<RemoteProctoringService> getExamProctoringService(Long examId);

/** This resets the proctoring settings for a given exam and stores the default settings.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ String getMappedDefaultConfigAttributeValue(
*/
Result<Long> applyQuitPasswordToConfigs(Long examId, String quitPassword);

/** Used to apply the quit pass given from the exam to all exam configuration for the exam.
*
* @param examId The exam identifier
* @param quitLink The quit link to set to all exam configuration of the given exam
* @return Result to the given exam id or to an error when happened
*/
Result<Long> applyQuitURLToConfigs(Long examId, String quitLink);

/** Get the quitLink SEB Setting from the Exam Configuration that is applied to the given exam.
*
* @param examId Exam identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,52 +152,24 @@ public Result<Long> applyQuitPasswordToConfigs(final Long examId, final String q
return examId;
}

final Long configNodeId = this.examConfigurationMapDAO
.getDefaultConfigurationNode(examId)
.getOr(null);
return saveSEBAttributeValueToConfig(examId, CONFIG_ATTR_NAME_QUIT_SECRET, quitSecret);
});
}

if (configNodeId == null) {
log.info("No Exam Configuration found for exam {} to apply quitPassword", examId);
return examId;
}
@Override
public Result<Long> applyQuitURLToConfigs(final Long examId, final String quitLink) {
return Result.tryCatch(() -> {

final Long attrId = getAttributeId(CONFIG_ATTR_NAME_QUIT_SECRET);
if (attrId == null) {
final String oldQuitLink = this.getQuitLink(examId);
if (Objects.equals(oldQuitLink, quitLink)) {
return examId;
}

final Configuration followupConfig = this.configurationDAO.getFollowupConfiguration(configNodeId)
.onError(error -> log.warn("Failed to get followup config for {} cause {}",
configNodeId,
error.getMessage()))
.getOr(null);

final ConfigurationValue configurationValue = new ConfigurationValue(
null,
followupConfig.institutionId,
followupConfig.id,
attrId,
0,
quitSecret
);

this.configurationValueDAO
.save(configurationValue)
.onError(err -> log.error(
"Failed to save quit password to config value: {}",
configurationValue,
err));

// TODO possible without save to history?
this.configurationDAO
.saveToHistory(configNodeId)
.onError(error -> log.warn("Failed to save to history for exam: {} cause: {}",
examId, error.getMessage()));

return examId;
return saveSEBAttributeValueToConfig(examId, CONFIG_ATTR_NAME_QUIT_LINK, quitLink);
});
}


@Override
public String getQuitLink(final Long examId) {
try {
Expand Down Expand Up @@ -236,4 +208,67 @@ private Long getAttributeId(final String configAttributeName) {
.getOr(null);
}

private Long saveSEBAttributeValueToConfig(
final Long examId,
final String attrName,
final String attrValue) {

final Long configNodeId = this.examConfigurationMapDAO
.getDefaultConfigurationNode(examId)
.getOr(null);

if (configNodeId == null) {
log.info("No Exam Configuration found for exam {} to apply SEB Setting: {}", examId, attrName);
return examId;
}

final Long attrId = getAttributeId(attrName);
if (attrId == null) {
return examId;
}

final Configuration lastStable = this.configurationDAO
.getConfigurationLastStableVersion(configNodeId)
.getOrThrow();
final Long followupId = configurationDAO
.getFollowupConfigurationId(configNodeId)
.getOrThrow();

// save to last sable version
this.configurationValueDAO
.saveForce(new ConfigurationValue(
null,
lastStable.institutionId,
lastStable.id,
attrId,
0,
attrValue
))
.onError(err -> log.error(
"Failed to save SEB Setting: {} to config: {}",
attrName,
lastStable,
err));

if (!Objects.equals(followupId, lastStable.id)) {
// save also to followup version
this.configurationValueDAO
.saveForce(new ConfigurationValue(
null,
lastStable.institutionId,
followupId,
attrId,
0,
attrValue
))
.onError(err -> log.error(
"Failed to save SEB Setting: {} to config: {}",
attrName,
lastStable,
err));
}

return examId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Result<Exam> importExam(
String quizId,
String examTemplateId,
String quitPassword,
String quitLink,
boolean showQuitLink,
final String examData);

Result<EntityKey> deleteExam(
Expand Down Expand Up @@ -117,7 +117,7 @@ final class ExamData {
@JsonProperty("template_id")
public final String template_id;
@JsonProperty("show_quit_link")
public final Boolean show_quit_link;
public final String quit_link;
@JsonProperty("quit_password")
public final String quit_password;

Expand All @@ -127,15 +127,15 @@ public ExamData(
final String quiz_id,
final Boolean exam_created,
final String template_id,
final Boolean show_quit_link,
final String quit_link,
final String quit_password) {

this.id = id;
this.course_id = course_id;
this.quiz_id = quiz_id;
this.exam_created = exam_created;
this.template_id = template_id;
this.show_quit_link = show_quit_link;
this.quit_link = quit_link;
this.quit_password = quit_password;
}
}
Expand Down
Loading

0 comments on commit 8b30771

Please sign in to comment.