Search in sources :

Example 1 with Recommendations

use of org.stepik.api.objects.recommendations.Recommendations in project intellij-plugins by StepicOrg.

the class StudyUtils method getRecommendation.

@Nullable
public static StudyNode<?, ?> getRecommendation(@NotNull StudyNode root) {
    StudyObject data = root.getData();
    if (data == null || !data.isAdaptive()) {
        return null;
    }
    StudyNode studyNode = null;
    StepikApiClient stepikClient = authAndGetStepikApiClient();
    if (!isAuthenticated()) {
        return null;
    }
    try {
        Recommendations recommendations = stepikClient.recommendations().get().course(root.getId()).execute();
        if (!recommendations.isEmpty()) {
            Recommendation recommendation = recommendations.getFirst();
            long lesson = recommendation.getLesson();
            Steps steps = stepikClient.steps().get().lesson(lesson).execute();
            if (!steps.isEmpty()) {
                long stepId = steps.getFirst().getId();
                studyNode = root.getChildByClassAndId(Step.class, stepId);
            }
        }
    } catch (StepikClientException e) {
        logger.warn(e);
    }
    return studyNode;
}
Also used : Recommendations(org.stepik.api.objects.recommendations.Recommendations) Steps(org.stepik.api.objects.steps.Steps) StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) StudyObject(org.stepik.api.objects.StudyObject) Step(org.stepik.api.objects.steps.Step) StepikClientException(org.stepik.api.exceptions.StepikClientException) Recommendation(org.stepik.api.objects.recommendations.Recommendation) StudyNode(org.stepik.core.courseFormat.StudyNode) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)1 StepikApiClient (org.stepik.api.client.StepikApiClient)1 StepikClientException (org.stepik.api.exceptions.StepikClientException)1 StudyObject (org.stepik.api.objects.StudyObject)1 Recommendation (org.stepik.api.objects.recommendations.Recommendation)1 Recommendations (org.stepik.api.objects.recommendations.Recommendations)1 Step (org.stepik.api.objects.steps.Step)1 Steps (org.stepik.api.objects.steps.Steps)1 StudyNode (org.stepik.core.courseFormat.StudyNode)1 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)1