diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/SEBRestrictionAPI.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/SEBRestrictionAPI.java index a88786ee..2438d8f0 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/SEBRestrictionAPI.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/SEBRestrictionAPI.java @@ -47,7 +47,10 @@ public interface SEBRestrictionAPI { return false; } - final SEBRestriction sebRestriction = sebClientRestriction.get(); + return hasSEBClientRestriction(sebClientRestriction.get()); + } + + default boolean hasSEBClientRestriction(final SEBRestriction sebRestriction) { return !sebRestriction.configKeys.isEmpty() || !sebRestriction.browserExamKeys.isEmpty(); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPITemplateAdapter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPITemplateAdapter.java index 9a647c34..e613beb3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPITemplateAdapter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPITemplateAdapter.java @@ -404,8 +404,7 @@ public class LmsAPITemplateAdapter implements LmsAPITemplate { return false; } - final SEBRestriction sebRestriction = sebClientRestriction.get(); - return !sebRestriction.configKeys.isEmpty() || !sebRestriction.browserExamKeys.isEmpty(); + return this.sebRestrictionAPI.hasSEBClientRestriction(sebClientRestriction.get()); } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/edx/OpenEdxCourseRestriction.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/edx/OpenEdxCourseRestriction.java index 56050745..23b91b85 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/edx/OpenEdxCourseRestriction.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/edx/OpenEdxCourseRestriction.java @@ -38,6 +38,7 @@ public class OpenEdxCourseRestriction implements SEBRestrictionAPI { private static final Logger log = LoggerFactory.getLogger(OpenEdxCourseRestriction.class); + private static final SEBRestriction NO_RESTRICTION_MARKER = new SEBRestriction(null, null, null, null); private static final String OPEN_EDX_DEFAULT_COURSE_RESTRICTION_API_INFO = "/seb-openedx/seb-info"; private static final String OPEN_EDX_DEFAULT_COURSE_RESTRICTION_API_PATH = "/seb-openedx/api/v1/course/%s/configuration/"; @@ -104,13 +105,8 @@ public class OpenEdxCourseRestriction implements SEBRestrictionAPI { } @Override - public boolean hasSEBClientRestriction(final Exam exam) { - final Result sebClientRestriction = getSEBClientRestriction(exam); - if (sebClientRestriction.hasError()) { - return false; - } - - return true; + public boolean hasSEBClientRestriction(final SEBRestriction sebRestriction) { + return NO_RESTRICTION_MARKER != sebRestriction; } @Override @@ -142,8 +138,8 @@ public class OpenEdxCourseRestriction implements SEBRestrictionAPI { return SEBRestriction.from(exam.id, data); } catch (final HttpClientErrorException ce) { if (ce.getStatusCode() == HttpStatus.NOT_FOUND) { - // No SEB restriction is set for the specified exam, return an empty one - return new SEBRestriction(exam.id, null, null, null); + // No SEB restriction is set for the specified exam, return NO_RESTRICTION_MARKER + return NO_RESTRICTION_MARKER; } throw ce; }