diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/CourseAccess.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/CourseAccess.java index 9d12a54b..a4467257 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/CourseAccess.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/CourseAccess.java @@ -31,18 +31,27 @@ import ch.ethz.seb.sebserver.gbl.model.user.ExamineeAccountDetails; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap; +/** A partial course access API implementation that uses CircuitBreaker to apply LMS + * API requests in a protected environment. + * + * Extend this to implement a concrete course access API for a given type of LMS. */ public abstract class CourseAccess { private static final Logger log = LoggerFactory.getLogger(CourseAccess.class); + /** Fetch status that indicates an asynchronous quiz data fetch status if the + * concrete implementation has such. */ public enum FetchStatus { ALL_FETCHED, ASYNC_FETCH_RUNNING, FETCH_ERROR } + /** CircuitBreaker for protected quiz and course data requests */ protected final CircuitBreaker> quizzesRequest; + /** CircuitBreaker for protected chapter data requests */ protected final CircuitBreaker chaptersRequest; + /** CircuitBreaker for protected examinee account details requests */ protected final CircuitBreaker accountDetailRequest; protected CourseAccess( @@ -134,6 +143,10 @@ public abstract class CourseAccess { return this.accountDetailRequest.protectedRun(accountDetailsSupplier(examineeSessionId)); } + /** Default implementation that uses getExamineeAccountDetails to geht the examinee name + * + * @param examineeSessionId + * @return The examinee account name for the given examineeSessionId */ public String getExamineeName(final String examineeSessionId) { return getExamineeAccountDetails(examineeSessionId) .map(ExamineeAccountDetails::getDisplayName) @@ -159,17 +172,29 @@ public abstract class CourseAccess { Collections.emptyMap()); } + /** Provides a supplier for the quiz data request to use within the circuit breaker */ protected abstract Supplier> quizzesSupplier(final Set ids); + /** Provides a AllQuizzesSupplier to supply quiz data either form cache or from LMS */ protected abstract AllQuizzesSupplier allQuizzesSupplier(); + /** Provides a supplier for the course chapter data request to use within the circuit breaker */ protected abstract Supplier getCourseChaptersSupplier(final String courseId); + /** Gives a fetch status if asynchronous quiz data fetching is part of the underling implementation */ protected abstract FetchStatus getFetchStatus(); + /** Uses to supply quiz data */ protected interface AllQuizzesSupplier { + /** Get all currently cached quiz data if supported by the underling implementation + * + * @return List containing all cached quiz data objects */ List getAllCached(); + /** Get a list of all quiz data filtered by the given filter map from LMS. + * + * @param filterMap Map containing the filter criteria + * @return Result refer to the list of filtered quiz data or to an error when happened */ Result> getAll(final FilterMap filterMap); }