Search in sources :

Example 6 with StudyObject

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

the class StepikPyProjectGenerator method fireStateChanged.

@Override
public void fireStateChanged() {
    if (!keepLocation && getLocationField() != null) {
        StudyObject studyObject = wizardStep.getSelectedStudyObject();
        String projectDirectory = new File(getLocation()).getParent();
        String projectName = ProjectWizardUtils.getProjectDefaultName(projectDirectory, studyObject);
        setLocation(projectDirectory + "/" + projectName);
    }
    super.fireStateChanged();
}
Also used : StudyObject(org.stepik.api.objects.StudyObject) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 7 with StudyObject

use of org.stepik.api.objects.StudyObject 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)

Example 8 with StudyObject

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

the class StepHelper method solvedLesson.

public boolean solvedLesson() {
    try {
        StudyNode lesson = stepNode.getParent();
        if (lesson == null) {
            return false;
        }
        StudyObject data = lesson.getData();
        if (data == null) {
            return false;
        }
        String progressId = data.getProgress();
        StepikApiClient stepikApiClient = authAndGetStepikApiClient();
        Progresses progresses = stepikApiClient.progresses().get().id(progressId).execute();
        return !progresses.isEmpty() && progresses.getFirst().isPassed();
    } catch (StepikClientException e) {
        logger.warn(e);
    }
    return false;
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) Progresses(org.stepik.api.objects.progresses.Progresses) StudyObject(org.stepik.api.objects.StudyObject) StepikClientException(org.stepik.api.exceptions.StepikClientException) StudyNode(org.stepik.core.courseFormat.StudyNode)

Aggregations

StudyObject (org.stepik.api.objects.StudyObject)8 StepikApiClient (org.stepik.api.client.StepikApiClient)3 StepikClientException (org.stepik.api.exceptions.StepikClientException)3 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)3 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 StudyNode (org.stepik.core.courseFormat.StudyNode)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Course (org.stepik.api.objects.courses.Course)1 Progresses (org.stepik.api.objects.progresses.Progresses)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 SupportedLanguages (org.stepik.core.SupportedLanguages)1