Skip to content

Commit

Permalink
SEBSERV-616 added number to generated Exam Config name
Browse files Browse the repository at this point in the history
  • Loading branch information
anhefti committed Jan 14, 2025
1 parent ad4f390 commit 7b69f1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
35 changes: 18 additions & 17 deletions src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,15 @@ public List<String> getAttributes() {

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("APIMessage [messageCode=");
builder.append(this.messageCode);
builder.append(", systemMessage=");
builder.append(this.systemMessage);
builder.append(", details=");
builder.append(this.details);
builder.append(", attributes=");
builder.append(this.attributes);
builder.append("]");
return builder.toString();
return "APIMessage [messageCode=" +
this.messageCode +
", systemMessage=" +
this.systemMessage +
", details=" +
this.details +
", attributes=" +
this.attributes +
"]";
}

/** Use this as a conversion from a given FieldError of Spring to a APIMessage
Expand Down Expand Up @@ -255,9 +253,15 @@ public static class APIMessageException extends RuntimeException implements APIM
private final Collection<APIMessage> apiMessages;

public APIMessageException(final Collection<APIMessage> apiMessages) {
super();
super(getMessage(apiMessages));
this.apiMessages = apiMessages;
}

static String getMessage(final Collection<APIMessage> apiMessages) {
if (apiMessages == null || apiMessages.isEmpty())
return "none";
return apiMessages.iterator().next().systemMessage;
}

public APIMessageException(final APIMessage apiMessage) {
super(apiMessage.systemMessage + " " + apiMessage.details);
Expand Down Expand Up @@ -331,16 +335,13 @@ private static String buildHTML(final Collection<APIMessage> messages, final Str
}

public static boolean checkError(final Exception error, final ErrorMessage errorMessage) {
if (!(error instanceof APIMessageError)) {
if (!(error instanceof final APIMessageError _error)) {
return false;
}

final APIMessageError _error = (APIMessageError) error;
return _error.getAPIMessages()
.stream()
.filter(msg -> errorMessage.messageCode.equals(msg.messageCode))
.findFirst()
.isPresent();
.anyMatch(msg -> errorMessage.messageCode.equals(msg.messageCode));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ private ConfigurationNode createOrReuseConfig(final Exam exam, final ExamTemplat
filterMap.putIfAbsent(Entity.FILTER_ATTR_NAME, configName);

// get existing config if available
final ConfigurationNode examConfig = this.configurationNodeDAO
Collection<ConfigurationNode> allConfigs = this.configurationNodeDAO
.allMatching(filterMap)
.getOrThrow()
.stream()
.getOrThrow();
final ConfigurationNode examConfig = allConfigs.stream()
.filter(res -> res.name.equals(configName))
.findFirst()
.orElse(null);
Expand All @@ -354,7 +354,9 @@ private ConfigurationNode createOrReuseConfig(final Exam exam, final ExamTemplat
!Objects.equals(examConfig.templateId, examTemplate.configTemplateId)) {

final String newName = (examConfig != null && examConfig.name.equals(configName))
? examConfig.name + "_" + DateTime.now(DateTimeZone.UTC).toString(Constants.STANDARD_DATE_FORMATTER)
? examConfig.name + "_" +
DateTime.now(DateTimeZone.UTC).toString(Constants.STANDARD_DATE_FORMATTER +
"_(" + allConfigs.size() + ")")
: configName;

final ConfigurationNode config = new ConfigurationNode(
Expand All @@ -372,11 +374,11 @@ private ConfigurationNode createOrReuseConfig(final Exam exam, final ExamTemplat
return this.configurationNodeDAO
.createNew(config)
.onError(error -> log.error(
"Failed to create exam configuration for exam: {} from template: {} examConfig: {}",
"Failed to create exam configuration for exam: {} from template: {} examConfig: {} error: {}",
exam.name,
examTemplate.name,
config,
error))
error.getMessage()))
.getOrThrow(error -> new APIMessageException(
ErrorMessage.EXAM_IMPORT_ERROR_AUTO_CONFIG,
error));
Expand Down

0 comments on commit 7b69f1d

Please sign in to comment.