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 317daa03..21b76a4f 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 @@ -277,7 +277,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); } @@ -297,8 +297,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()); }) @@ -318,7 +318,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), @@ -327,26 +327,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)) { @@ -364,7 +364,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); @@ -379,7 +379,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 @@ -500,7 +500,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()); 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()) {