From fc7ac4c4e0cba466494a3586bd4a5a462797f58d Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 4 Jun 2024 09:43:09 +0200 Subject: [PATCH] SEBSERV-417 better connection init --- .../impl/FullLmsIntegrationServiceImpl.java | 8 +++++--- .../lms/impl/LmsAPIServiceImpl.java | 20 ++++++++----------- .../plugin/MoodlePluginFullIntegration.java | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/FullLmsIntegrationServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/FullLmsIntegrationServiceImpl.java index 7e754e1e..b7541bfd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/FullLmsIntegrationServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/FullLmsIntegrationServiceImpl.java @@ -166,9 +166,11 @@ public class FullLmsIntegrationServiceImpl implements FullLmsIntegrationService } if (lmsSetup.active) { - applyFullLmsIntegration(lmsSetup.id) - .onError(error -> log.warn("Failed to update LMS integration for: {}", lmsSetup, error)) - .onSuccess(data -> log.debug("Successfully updated LMS integration for: {} data: {}", lmsSetup, data)); + if (!lmsSetup.integrationActive) { + applyFullLmsIntegration(lmsSetup.id) + .onError(error -> log.warn("Failed to update LMS integration for: {}", lmsSetup, error)) + .onSuccess(data -> log.debug("Successfully updated LMS integration for: {} data: {}", lmsSetup, data)); + } } else if (lmsSetup.integrationActive) { deleteFullLmsIntegration(lmsSetup.id) .onError(error -> log.warn("Failed to delete LMS integration for: {}", lmsSetup, error)) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java index f948d504..5d0a333f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java @@ -53,7 +53,7 @@ public class LmsAPIServiceImpl implements LmsAPIService { private final ClientCredentialService clientCredentialService; private final QuizLookupService quizLookupService; private final EnumMap templateFactories; - private final ApplicationEventPublisher applicationEventPublisher; + private final FullLmsIntegrationService fullLmsIntegrationService; private final Map cache = new ConcurrentHashMap<>(); @@ -62,14 +62,14 @@ public class LmsAPIServiceImpl implements LmsAPIService { final LmsSetupDAO lmsSetupDAO, final ClientCredentialService clientCredentialService, final QuizLookupService quizLookupService, - final ApplicationEventPublisher applicationEventPublisher, + final FullLmsIntegrationService fullLmsIntegrationService, final Collection lmsAPITemplateFactories) { this.webserviceInfo = webserviceInfo; this.lmsSetupDAO = lmsSetupDAO; this.clientCredentialService = clientCredentialService; this.quizLookupService = quizLookupService; - this.applicationEventPublisher = applicationEventPublisher; + this.fullLmsIntegrationService = fullLmsIntegrationService; final Map factories = lmsAPITemplateFactories .stream() @@ -170,15 +170,11 @@ public class LmsAPIServiceImpl implements LmsAPIService { .onError(er -> log.error("Failed to mark LMS integration inactive", er)); return lmsSetupTestResult; } else { - // try to apply full integration with a change LMSSetup notification - try { - applicationEventPublisher.publishEvent(new LmsSetupChangeEvent(template.lmsSetup())); - return lmsSetupTestResult; - } catch (final Exception e) { - log.warn( - "Failed to apply full LMS integration on test attempt: lms: {} error: {}", - template.lmsSetup(), - e.getMessage()); + + final Result integrationDataResult = fullLmsIntegrationService + .applyFullLmsIntegration(template.lmsSetup().id); + + if (integrationDataResult.hasError()) { return LmsSetupTestResult.ofFullIntegrationAPIError( template.lmsSetup().lmsType, "Failed to apply full LMS integration"); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginFullIntegration.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginFullIntegration.java index 0bb1e261..bc93b77c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginFullIntegration.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginFullIntegration.java @@ -111,7 +111,7 @@ public class MoodlePluginFullIntegration implements FullLmsIntegrationAPI { log.warn( "Failed to apply SEB Server connection details to Moodle for full integration. Moodle error {}, lmsSetup: {} data: {}", response, - lmsSetup, + lmsSetup.name, data );