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);
}
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;
}
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);
}
}
});
}
Aggregations