Search in sources :

Example 1 with CourseContentNotValidException

use of org.edx.mobile.exception.CourseContentNotValidException in project edx-app-android by edx.

the class CourseUnitWebViewFragmentTest method getHtmlUnit.

/**
 * Method for iterating through the mock course response data, and
 * returning the first video block leaf.
 *
 * @return The first {@link HtmlBlockModel} leaf in the mock course data
 */
private HtmlBlockModel getHtmlUnit() throws CourseContentNotValidException {
    EnrolledCoursesResponse courseData;
    try {
        courseData = executeStrict(courseAPI.getEnrolledCourses()).get(0);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    String courseId = courseData.getCourse().getId();
    CourseStructureV1Model model;
    try {
        model = executeStrict(courseAPI.getCourseStructure(courseId));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    CourseComponent courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
    List<CourseComponent> htmlBlockUnits = new ArrayList<>();
    courseComponent.fetchAllLeafComponents(htmlBlockUnits, EnumSet.of(BlockType.HTML));
    return (HtmlBlockModel) htmlBlockUnits.get(0);
}
Also used : EnrolledCoursesResponse(org.edx.mobile.model.api.EnrolledCoursesResponse) ArrayList(java.util.ArrayList) HtmlBlockModel(org.edx.mobile.model.course.HtmlBlockModel) CourseStructureV1Model(org.edx.mobile.model.course.CourseStructureV1Model) CourseContentNotValidException(org.edx.mobile.exception.CourseContentNotValidException) CourseComponent(org.edx.mobile.model.course.CourseComponent)

Example 2 with CourseContentNotValidException

use of org.edx.mobile.exception.CourseContentNotValidException in project edx-app-android by edx.

the class CourseAPI method normalizeCourseStructure.

/**
 * Mapping from raw data structure from getCourseStructure() API
 * @param courseStructureV1Model
 * @return
 */
@NonNull
public static IBlock normalizeCourseStructure(@NonNull final CourseStructureV1Model courseStructureV1Model, @NonNull final String courseId) throws CourseContentNotValidException {
    BlockModel topBlock = courseStructureV1Model.getBlockById(courseStructureV1Model.root);
    if (topBlock == null) {
        throw new CourseContentNotValidException("Server didn't send a proper response for this course: " + courseStructureV1Model.root);
    }
    CourseComponent course = new CourseComponent(topBlock, null);
    course.setCourseId(courseId);
    for (BlockModel m : courseStructureV1Model.getDescendants(topBlock)) {
        normalizeCourseStructure(courseStructureV1Model, m, course);
    }
    return course;
}
Also used : BlockModel(org.edx.mobile.model.course.BlockModel) DiscussionBlockModel(org.edx.mobile.model.course.DiscussionBlockModel) VideoBlockModel(org.edx.mobile.model.course.VideoBlockModel) HtmlBlockModel(org.edx.mobile.model.course.HtmlBlockModel) CourseContentNotValidException(org.edx.mobile.exception.CourseContentNotValidException) CourseComponent(org.edx.mobile.model.course.CourseComponent) NonNull(android.support.annotation.NonNull)

Example 3 with CourseContentNotValidException

use of org.edx.mobile.exception.CourseContentNotValidException in project edx-app-android by edx.

the class NewCourseOutlineFragment method getCourseComponentFromServer.

public void getCourseComponentFromServer(boolean showProgress) {
    final TaskProgressCallback progressCallback = showProgress ? new TaskProgressCallback.ProgressViewController(loadingIndicator) : null;
    final String courseId = courseData.getCourse().getId();
    getHierarchyCall = courseApi.getCourseStructureWithoutStale(courseId);
    getHierarchyCall.enqueue(new CourseAPI.GetCourseStructureCallback(getActivity(), courseId, progressCallback, errorNotification, null, this) {

        @Override
        protected void onResponse(@NonNull final CourseComponent courseComponent) {
            courseManager.addCourseDataInAppLevelCache(courseId, courseComponent);
            loadData(validateCourseComponent(courseComponent));
        }

        @Override
        protected void onFailure(@NonNull Throwable error) {
            super.onFailure(error);
            if (error instanceof CourseContentNotValidException) {
                errorNotification.showError(getContext(), error);
                logger.error(error, true);
            }
        }

        @Override
        protected void onFinish() {
            if (!EventBus.getDefault().isRegistered(NewCourseOutlineFragment.this)) {
                EventBus.getDefault().registerSticky(NewCourseOutlineFragment.this);
            }
        }
    });
}
Also used : TaskProgressCallback(org.edx.mobile.view.common.TaskProgressCallback) CourseContentNotValidException(org.edx.mobile.exception.CourseContentNotValidException) CourseComponent(org.edx.mobile.model.course.CourseComponent) CourseAPI(org.edx.mobile.course.CourseAPI)

Aggregations

CourseContentNotValidException (org.edx.mobile.exception.CourseContentNotValidException)3 CourseComponent (org.edx.mobile.model.course.CourseComponent)3 HtmlBlockModel (org.edx.mobile.model.course.HtmlBlockModel)2 NonNull (android.support.annotation.NonNull)1 ArrayList (java.util.ArrayList)1 CourseAPI (org.edx.mobile.course.CourseAPI)1 EnrolledCoursesResponse (org.edx.mobile.model.api.EnrolledCoursesResponse)1 BlockModel (org.edx.mobile.model.course.BlockModel)1 CourseStructureV1Model (org.edx.mobile.model.course.CourseStructureV1Model)1 DiscussionBlockModel (org.edx.mobile.model.course.DiscussionBlockModel)1 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)1 TaskProgressCallback (org.edx.mobile.view.common.TaskProgressCallback)1