From d6e65eb8ad55bac5fe9dc36252403fe9bc5e2f17 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 4 Jun 2024 12:09:31 +0200 Subject: [PATCH 1/2] manually picked changes from pull-request: Integrate SEB Server in OLAT again #121 --- .../lms/impl/olat/OlatLmsAPITemplate.java | 27 ++++++++++--------- .../lms/impl/olat/OlatLmsData.java | 22 ++++++++------- .../lms/impl/olat/OlatLmsRestTemplate.java | 11 ++++---- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsAPITemplate.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsAPITemplate.java index 589f6763..922a0900 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsAPITemplate.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsAPITemplate.java @@ -275,7 +275,7 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm final DateTime quizFromTime = (filterMap != null) ? filterMap.getQuizFromTime() : null; final long fromCutTime = (quizFromTime != null) ? Utils.toUnixTimeInSeconds(quizFromTime) : -1; - String url = "/restapi/assessment_modes/seb?"; + String url = "/restapi/repo/assessmentmodes?"; if (fromCutTime != -1) { url = String.format("%sdateFrom=%s&", url, fromCutTime); } @@ -295,8 +295,8 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm lmsSetup.getLmsType(), a.name, a.description, - Utils.toDateTimeUTC(a.dateFrom), - Utils.toDateTimeUTC(a.dateTo), + Utils.toDateTimeUTC(a.begin - a.leadTime * 1000 * 60), + Utils.toDateTimeUTC(a.end + a.followupTime * 1000 * 60), examUrl(a.repositoryEntryKey), new HashMap()); }) @@ -316,7 +316,7 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm private QuizData quizById(final OlatLmsRestTemplate restTemplate, final String id) { final LmsSetup lmsSetup = this.apiTemplateDataSupplier.getLmsSetup(); - final String url = String.format("/restapi/assessment_modes/%s", id); + final String url = String.format("/restapi/repo/assessmentmodes/%s", id); final AssessmentData a = this.apiGet(restTemplate, url, AssessmentData.class); return new QuizData( String.format("%d", a.key), @@ -325,26 +325,26 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm lmsSetup.getLmsType(), a.name, a.description, - Utils.toDateTimeUTC(a.dateFrom), - Utils.toDateTimeUTC(a.dateTo), + Utils.toDateTimeUTC(a.begin - a.leadTime * 1000 * 60), + Utils.toDateTimeUTC(a.end + a.followupTime * 1000 * 60), examUrl(a.repositoryEntryKey), new HashMap()); } private ExamineeAccountDetails getExamineeById(final RestTemplate restTemplate, final String id) { - final String url = String.format("/restapi/users/%s/name_username", id); + final String url = String.format("/restapi/users/%s", id); final UserData u = this.apiGet(restTemplate, url, UserData.class); final Map attrs = new HashMap<>(); return new ExamineeAccountDetails( String.valueOf(u.key), u.lastName + ", " + u.firstName, - u.username, - "OLAT API does not provide email addresses", + u.login, + u.email, attrs); } private SEBRestriction getRestrictionForAssignmentId(final RestTemplate restTemplate, final String id) { - final String url = String.format("/restapi/assessment_modes/%s/seb_restriction", id); + final String url = String.format("/restapi/repo/assessmentmodes/%s/seb", id); final RestrictionData r = this.apiGet(restTemplate, url, RestrictionData.class); final HashMap additionalAttributes = new HashMap<>(); if (StringUtils.isNotBlank(r.quitLink)) { @@ -362,7 +362,7 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm final String id, final SEBRestriction restriction) { - final String url = String.format("/restapi/assessment_modes/%s/seb_restriction", id); + final String url = String.format("/restapi/repo/assessmentmodes/%s/seb", id); final RestrictionDataPost post = new RestrictionDataPost(); post.browserExamKeys = new ArrayList<>(restriction.browserExamKeys); post.configKeys = new ArrayList<>(restriction.configKeys); @@ -377,7 +377,7 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm } private SEBRestriction deleteRestrictionForAssignmentId(final RestTemplate restTemplate, final String id) { - final String url = String.format("/restapi/assessment_modes/%s/seb_restriction", id); + final String url = String.format("/restapi/repo/assessmentmodes/%s/seb", id); final RestrictionData r = this.apiDelete(restTemplate, url, RestrictionData.class); // OLAT returns RestrictionData with null values upon deletion. // We return it here for consistency, even though SEB server does not need it @@ -473,7 +473,7 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm .getOrThrow(); final ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails(); - details.setAccessTokenUri(lmsSetup.lmsApiUrl + "/restapi/auth/"); + details.setAccessTokenUri(lmsSetup.lmsApiUrl + "/restapi/auth/{username}?password={password}"); details.setClientId(plainClientId.toString()); details.setClientSecret(plainClientSecret.toString()); @@ -489,4 +489,5 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm }); } + } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsData.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsData.java index 7a7eeb2d..050e695a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsData.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsData.java @@ -20,22 +20,24 @@ public final class OlatLmsData { /* * OLAT API example: * { - * "courseName": "course 1", - * "dateFrom": 1624420800000, - * "dateTo": 1624658400000, + * "begin": 1624420800000, + * "end": 1624658400000, * "description": "", * "key": 6356992, * “repositoryEntryKey”: 462324, - * "name": "SEB test" + * "name": "SEB test", + * "leadTime": 15, + * "followupTime", 5 * } */ public long key; public long repositoryEntryKey; public String name; public String description; - public String courseName; - public long dateFrom; - public long dateTo; + public Long begin; + public Long end; + public long leadTime; + public long followupTime; } @JsonIgnoreProperties(ignoreUnknown = true) @@ -46,13 +48,15 @@ public final class OlatLmsData { * "firstName": "OpenOLAT", * "key": 360448, * "lastName": "Administrator", - * "username": "administrator" + * "login": "administrator", + * "email": "admin@example.org" * } */ public long key; public String firstName; public String lastName; - public String username; + public String login; + public String email; } @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsRestTemplate.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsRestTemplate.java index 046c6f07..f2fd8601 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsRestTemplate.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/olat/OlatLmsRestTemplate.java @@ -16,6 +16,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; import org.springframework.http.HttpRequest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -116,14 +117,14 @@ public class OlatLmsRestTemplate extends RestTemplate { // Authenticate with OLAT and store the received X-OLAT-TOKEN this.token = "authenticating"; final String authUrl = this.details.getAccessTokenUri(); - final Map credentials = new HashMap<>(); - credentials.put("username", this.details.getClientId()); - credentials.put("password", this.details.getClientSecret()); + final Map parameters = new HashMap<>(); + parameters.put("username", this.details.getClientId()); + parameters.put("password", this.details.getClientSecret()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("content-type", "application/json"); - final HttpEntity> requestEntity = new HttpEntity<>(credentials, httpHeaders); + final HttpEntity> requestEntity = new HttpEntity<>(httpHeaders); try { - final ResponseEntity response = this.postForEntity(authUrl, requestEntity, String.class); + final ResponseEntity response = this.exchange(authUrl, HttpMethod.GET, requestEntity, String.class, parameters); final HttpHeaders responseHeaders = response.getHeaders(); if (log.isDebugEnabled()) { From 1ac7e99be00eeb3331922f075f3fa2c96c5a56da Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 5 Jun 2024 08:49:09 +0200 Subject: [PATCH 2/2] Prepare for patch release 1.6.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a21318e4..c1e57cd2 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ jar - 1.6.1-SNAPSHOT + 1.6.1 ${sebserver-version} ${sebserver-version} UTF-8