Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/rel-1.5.2' into development
Browse files Browse the repository at this point in the history
Conflicts:
	pom.xml
	src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java
	src/main/resources/config/ehcache.xml
	src/main/resources/messages.properties
  • Loading branch information
anhefti committed Oct 3, 2023
2 parents 60bdb38 + 5103338 commit 1cbc97e
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 19 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>


<!-- NOTE: There currently are two profiles, a default one to build on
Java 11 (from eclipse and command-line) and one to build still on Java 8
to support the Jenkins build on CI-Server that still no Java 11 installed -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
Expand Down Expand Up @@ -451,31 +452,28 @@ private String toAdditionalValue(final String name, final String value) {
}
}

private Composite warningPanel = null;

private void handelPageReload(
final Composite notePanel,
final EntityTable<QuizData> table) {

if (table.isComplete()) {
PageService.clearComposite(notePanel);
if (this.warningPanel != null) {
this.warningPanel.dispose();
}
this.warningPanel = null;
} else {
if (this.warningPanel != null && !this.warningPanel.isDisposed()) {
this.warningPanel.dispose();

final Control[] children = notePanel.getChildren();
if (children != null && children.length > 0) {
return;
}

this.warningPanel = this.widgetFactory.createWarningPanel(notePanel, 15, true);
final Composite warningPanel = this.widgetFactory.createWarningPanel(notePanel, 15, true);
warningPanel.setData("warningPanel", "TRUE");
this.widgetFactory.imageButton(
ImageIcon.SWITCH,
this.warningPanel,
warningPanel,
TEXT_FETCH_NOTE_TOOLTIP,
event -> table.applyFilter());

final Label text = new Label(this.warningPanel, SWT.NONE);
final Label text = new Label(warningPanel, SWT.NONE);
text.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);
text.setText(this.pageService.getI18nSupport().getText(TEXT_FETCH_NOTE));
final GridData gridData = new GridData(SWT.LEFT, SWT.FILL, true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void changePasswordView() {
final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
passwordInput.setLayoutData(gridData);
passwordInput.setText(value != null
? Utils.escapeHTML_XML_EcmaScript(value)
? value
: StringUtils.EMPTY);
if (!buildPassword) {
passwordInput.setEditable(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,10 @@ private List<QuizData> getQuizzesForIds(
lmsSetup);
}

final Set<String> qIdSet = internalIds.stream()
.map(MoodleUtils::getQuizId)
.collect(Collectors.toSet());

return getCoursesForIds(restTemplate, moodleCourseIds)
.stream()
.filter(courseData -> !courseData.quizzes.isEmpty())
Expand All @@ -540,7 +544,7 @@ private List<QuizData> getQuizzesForIds(
urlPrefix,
this.prependShortCourseName)
.stream()
.filter(q -> internalIds.contains(q.id)))
.filter(q -> qIdSet.contains(MoodleUtils.getQuizId(q.id))))
.collect(Collectors.toList());

} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ private LmsSetupTestResult testLmsSetupSettings() {
"lmsSetup:lmsClientsecret:notNull"));
}

final Result<OlatLmsRestTemplate> restTemplateResult = getRestTemplate();
if (restTemplateResult.hasError()) {
missingAttrs.add(APIMessage.fieldValidationError(
LMS_SETUP.ATTR_LMS_URL,
"lmsSetup:lmsUrl:url.noservice"));
} else {
final OlatLmsRestTemplate olatLmsRestTemplate = restTemplateResult.get();
try {
olatLmsRestTemplate.testAuthentication();
} catch (final Exception e) {
log.error("Failed to test Authentication: {}", e.getMessage());
missingAttrs.add(APIMessage.fieldValidationError(
LMS_SETUP.ATTR_LMS_URL,
"lmsSetup:lmsUrl:url.noaccess"));
}
}

if (!missingAttrs.isEmpty()) {
return LmsSetupTestResult.ofMissingAttributes(LmsType.OPEN_OLAT, missingAttrs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public class OlatLmsRestTemplate extends RestTemplate {
private String token;
private ClientCredentialsResourceDetails details;

public void testAuthentication() {
if (this.token == null) {
authenticate();
}
}

public OlatLmsRestTemplate(final ClientCredentialsResourceDetails details) {
super();
this.details = details;
Expand Down Expand Up @@ -59,6 +65,7 @@ else if (OlatLmsRestTemplate.this.token.equals("authenticating")) {

return execution.execute(request, body);
}

// otherwise, add the X-OLAT-TOKEN
request.getHeaders().set("accept", "application/json");
request.getHeaders().set("X-OLAT-TOKEN", OlatLmsRestTemplate.this.token);
Expand All @@ -85,6 +92,7 @@ else if (OlatLmsRestTemplate.this.token.equals("authenticating")) {
log.debug("OLAT [retry API call]: URL {}", request.getURI());
}

response.close();
response = execution.execute(request, body);

if (log.isDebugEnabled()) {
Expand All @@ -97,7 +105,7 @@ else if (OlatLmsRestTemplate.this.token.equals("authenticating")) {

} catch (final Exception e) {
// TODO find a way to better deal with Olat temporary unavailability
log.error("Unexpected error: ", e);
log.error("Unexpected error: {}", e.getMessage());
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import org.joda.time.DateTime;
Expand All @@ -30,6 +31,7 @@
import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamStatus;
import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.Features;
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType;
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
import ch.ethz.seb.sebserver.gbl.util.Result;
import ch.ethz.seb.sebserver.gbl.util.Utils;
Expand All @@ -40,6 +42,7 @@
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPIService;
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPITemplate;
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.SEBRestrictionService;
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.moodle.MoodleUtils;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamFinishedEvent;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamResetEvent;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamStartedEvent;
Expand Down Expand Up @@ -167,7 +170,12 @@ Result<Set<String>> updateExamFromLMS(final Long lmsSetupId, final Map<String, E
.forEach(quiz -> {

try {
final Exam exam = exams.get(quiz.id);
final Exam exam = getExamForQuizWithMoodleSpecialCase(exams, quiz);

if (exam == null) {
log.warn("Failed to find map exam to fetched quiz-data: {}", quiz);
return;
}

if (hasChanges(exam, quiz)) {

Expand Down Expand Up @@ -389,7 +397,8 @@ private boolean hasChanges(final Exam exam, final QuizData quizData) {
!Objects.equals(exam.startTime, quizData.startTime) ||
!Objects.equals(exam.endTime, quizData.endTime) ||
!Utils.isEqualsWithEmptyCheckTruncated(exam.getDescription(), quizData.description) ||
!Utils.isEqualsWithEmptyCheck(exam.getStartURL(), quizData.startURL)) {
!Utils.isEqualsWithEmptyCheck(exam.getStartURL(), quizData.startURL) ||
!Objects.equals(exam.externalId, quizData.id)) {

if (!Utils.isEqualsWithEmptyCheck(exam.name, quizData.name)) {
log.info("Update name difference from LMS. Exam: {}, QuizData: {}", exam.name, quizData.name);
Expand All @@ -409,6 +418,11 @@ private boolean hasChanges(final Exam exam, final QuizData quizData) {
exam.getStartURL(),
quizData.startURL);
}
if (!Objects.equals(exam.externalId, quizData.id)) {
log.info("Update quizId difference from LMS. Exam:{}, QuizData: {}",
exam.externalId,
quizData.id);
}

return true;
}
Expand Down Expand Up @@ -579,4 +593,33 @@ private void controlExamState(final String updateId) {
}
}

/** NOTE: LMS binding for Moodle uses a composed quiz-identifier with also contains the course short name
* for the reason to be able to re-identify a quiz when the main quiz-id changes in case of backup-restore on Moodle
* But since course names also can change this function tries to find old Exam mappings for course-names hat has
* changed */
private Exam getExamForQuizWithMoodleSpecialCase(final Map<String, Exam> exams, final QuizData quiz) {
Exam exam = exams.get(quiz.id);

if (exam == null) {
try {
final LmsAPITemplate lms = this.lmsAPIService
.getLmsAPITemplate(quiz.lmsSetupId)
.getOrThrow();

if (lms.getType() == LmsType.MOODLE || lms.getType() == LmsType.MOODLE_PLUGIN) {
final String quizId = MoodleUtils.getQuizId(quiz.id);
final Optional<String> find =
exams.keySet().stream().filter(key -> key.startsWith(quizId)).findFirst();
if (find.isPresent()) {
exam = exams.get(find.get());
}
}
} catch (final Exception e) {
log.error("Failed to verify changed external Exam id from moodle course: {}", e.getMessage());
}
}

return exam;
}

}
4 changes: 2 additions & 2 deletions src/main/resources/config/ehcache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<expiry>
<ttl unit="hours">24</ttl>
</expiry>
<resources>
<heap unit="entries">100000</heap>
<resources>
<heap unit="entries">100000</heap>
</resources>
</cache>

Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,16 @@ sebserver.form.validation.fieldError.invalidURL=The input does not match the URL
sebserver.form.validation.fieldError.exists=This name already exists. Please choose another one
sebserver.form.validation.fieldError.email=Invalid mail address
sebserver.form.validation.fieldError.serverNotAvailable=No service seems to be available within the given URL
<<<<<<< HEAD
sebserver.form.validation.fieldError.url.invalid=Invalid URL. The given URL cannot be reached
sebserver.form.validation.fieldError.typeInvalid=This type is not implemented yet and cannot be used
sebserver.form.validation.fieldError.url.noservice=The expected service is not available within the given URL and API access
=======
sebserver.form.validation.fieldError.url.invalid=Invalid URL. The given URL cannot be reached.
sebserver.form.validation.fieldError.typeInvalid=This type is not implemented yet and cannot be used.
sebserver.form.validation.fieldError.url.noservice=The expected service is not available within the given URL and API access.
sebserver.form.validation.fieldError.url.noaccess=There has no access been granted by the service. Please check the given access credentials.
>>>>>>> refs/remotes/origin/rel-1.5.2
sebserver.form.validation.fieldError.thresholdDuplicate=There are duplicate threshold values.
sebserver.form.validation.fieldError.thresholdEmpty=There are missing values or colors for the threshold declaration
sebserver.form.validation.fieldError.invalidIP=Invalid IP v4. Please enter a valid IP-address (v4)
Expand Down

0 comments on commit 1cbc97e

Please sign in to comment.