minor cleanups

This commit is contained in:
Carol Alexandru 2021-08-03 07:27:57 +02:00
parent 0029cd4ec3
commit 8376a1c3fd
2 changed files with 6 additions and 7 deletions

View file

@ -118,7 +118,8 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm
this.getRestTemplate().get(); this.getRestTemplate().get();
} }
catch (Exception e) { catch (Exception e) {
return LmsSetupTestResult.ofQuizAccessAPIError(LmsType.OPEN_OLAT, "Unspecific error connecting to OLAT API"); log.error("Failed to access OLAT course API: ", e);
return LmsSetupTestResult.ofQuizAccessAPIError(LmsType.OPEN_OLAT, e.getMessage());
} }
return LmsSetupTestResult.ofOkay(LmsType.OPEN_OLAT); return LmsSetupTestResult.ofOkay(LmsType.OPEN_OLAT);
} }
@ -349,9 +350,7 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm
@Override @Override
public Result<Exam> releaseSEBClientRestriction(final Exam exam) { public Result<Exam> releaseSEBClientRestriction(final Exam exam) {
@SuppressWarnings("unused")
final String quizId = exam.externalId; final String quizId = exam.externalId;
return getRestTemplate() return getRestTemplate()
.map(t -> this.deleteRestrictionForAssignmentId(t, exam.externalId)) .map(t -> this.deleteRestrictionForAssignmentId(t, exam.externalId))
.map(x -> exam); .map(x -> exam);
@ -403,6 +402,7 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm
private Result<OlatLmsRestTemplate> getRestTemplate() { private Result<OlatLmsRestTemplate> getRestTemplate() {
return Result.tryCatch(() -> { return Result.tryCatch(() -> {
if (this.cachedRestTemplate != null) { return this.cachedRestTemplate; } if (this.cachedRestTemplate != null) { return this.cachedRestTemplate; }
final LmsSetup lmsSetup = this.apiTemplateDataSupplier.getLmsSetup(); final LmsSetup lmsSetup = this.apiTemplateDataSupplier.getLmsSetup();
final ClientCredentials credentials = this.apiTemplateDataSupplier.getLmsClientCredentials(); final ClientCredentials credentials = this.apiTemplateDataSupplier.getLmsClientCredentials();
final ProxyData proxyData = this.apiTemplateDataSupplier.getProxyData(); final ProxyData proxyData = this.apiTemplateDataSupplier.getProxyData();
@ -425,7 +425,6 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm
template.setRequestFactory(clientHttpRequestFactory); template.setRequestFactory(clientHttpRequestFactory);
this.cachedRestTemplate = template; this.cachedRestTemplate = template;
return this.cachedRestTemplate; return this.cachedRestTemplate;
}); });
} }

View file

@ -28,7 +28,7 @@ public class OlatLmsRestTemplate extends RestTemplate {
private static final Logger log = LoggerFactory.getLogger(OlatLmsRestTemplate.class); private static final Logger log = LoggerFactory.getLogger(OlatLmsRestTemplate.class);
public String token; private String token;
private ClientCredentialsResourceDetails details; private ClientCredentialsResourceDetails details;
public OlatLmsRestTemplate(ClientCredentialsResourceDetails details) { public OlatLmsRestTemplate(ClientCredentialsResourceDetails details) {
@ -68,8 +68,8 @@ public class OlatLmsRestTemplate extends RestTemplate {
details.getClientId(), details.getClientId(),
details.getClientSecret()); details.getClientSecret());
try { try {
ResponseEntity<String> response = this.getForEntity(authUrl, String.class); final ResponseEntity<String> response = this.getForEntity(authUrl, String.class);
HttpHeaders responseHeaders = response.getHeaders(); final HttpHeaders responseHeaders = response.getHeaders();
log.debug("OLAT [authenticate] {} Headers: {}", response.getStatusCode(), responseHeaders); log.debug("OLAT [authenticate] {} Headers: {}", response.getStatusCode(), responseHeaders);
token = responseHeaders.getFirst("X-OLAT-TOKEN"); token = responseHeaders.getFirst("X-OLAT-TOKEN");
} }