Search in sources :

Example 1 with StepikProjectManager

use of org.stepik.core.StepikProjectManager in project intellij-plugins by StepicOrg.

the class Metrics method postMetrics.

private static void postMetrics(@NotNull Project project, @NotNull Metric metric, @NotNull MetricsStatus status) {
    executor.schedule(() -> {
        StepikApiClient stepikApiClient;
        stepikApiClient = authAndGetStepikApiClient();
        if (!isAuthenticated()) {
            return;
        }
        final StepikMetricsPostQuery query = stepikApiClient.metrics().post().timestamp(System.currentTimeMillis() / 1000L).tags(metric.getTags()).data(metric.getData()).name("ide_plugin").tags("name", "S_Union").tags("ide_name", ApplicationInfo.getInstance().getVersionName()).data("ide_version", ApplicationInfo.getInstance().getBuild().toString()).data("plugin_version", PluginUtils.getVersion()).data("session", session).tags("status", status);
        StepikProjectManager projectManager = StepikProjectManager.getInstance(project);
        if (projectManager != null) {
            query.data("project_id", projectManager.getUuid()).tags("project_programming_language", projectManager.getDefaultLang().getName()).data("project_manager_version", projectManager.getVersion());
            StudyNode projectRoot = projectManager.getProjectRoot();
            if (projectRoot != null) {
                Class<? extends StudyNode> projectRootClass = projectRoot.getClass();
                query.tags("project_root_class", projectRootClass.getSimpleName()).data("project_root_id", projectRoot.getId());
                query.data("course_id", projectRoot.getCourseId(stepikApiClient));
            }
        }
        query.executeAsync().exceptionally((e) -> {
            String message = String.format("Failed post metric: %s", query.toString());
            logger.warn(message, e);
            return null;
        });
    }, 500, TimeUnit.MILLISECONDS);
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) StepikProjectManager(org.stepik.core.StepikProjectManager) StepikMetricsPostQuery(org.stepik.api.queries.metrics.StepikMetricsPostQuery) StudyNode(org.stepik.core.courseFormat.StudyNode)

Example 2 with StepikProjectManager

use of org.stepik.core.StepikProjectManager in project intellij-plugins by StepicOrg.

the class StepikPyProjectGenerator method createCourseFromGenerator.

private void createCourseFromGenerator(@NotNull Project project) {
    generator.generateProject(project);
    FileUtil.createDirectory(new File(project.getBasePath(), EduNames.SANDBOX_DIR));
    StepikProjectManager projectManager = StepikProjectManager.getInstance(project);
    if (projectManager == null) {
        logger.warn("failed to generate builders: StepikProjectManager is null");
        return;
    }
    projectManager.setDefaultLang(generator.getDefaultLang());
    StudyNode root = projectManager.getProjectRoot();
    if (root == null) {
        logger.warn("failed to generate builders: Root is null");
        return;
    }
    if (root instanceof StepNode) {
        getOrCreateSrcDirectory(project, (StepNode) root, true);
    } else {
        createSubDirectories(project, generator.getDefaultLang(), root, null);
        VirtualFileManager.getInstance().syncRefresh();
    }
    Application application = ApplicationManager.getApplication();
    application.invokeLater(() -> DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, () -> application.runWriteAction(() -> {
        StudyProjectComponent.getInstance(project).registerStudyToolWindow();
        StepikProjectManager.updateAdaptiveSelected(project);
    })));
}
Also used : StepikProjectManager(org.stepik.core.StepikProjectManager) StepNode(org.stepik.core.courseFormat.StepNode) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Application(com.intellij.openapi.application.Application) StudyNode(org.stepik.core.courseFormat.StudyNode)

Example 3 with StepikProjectManager

use of org.stepik.core.StepikProjectManager in project intellij-plugins by StepicOrg.

the class StepikProjectGenerator method generateProject.

public void generateProject(@NotNull Project project) {
    StepikProjectManager stepikProjectManager = StepikProjectManager.getInstance(project);
    if (stepikProjectManager == null) {
        Metrics.createProject(project, TARGET_NOT_FOUND);
        return;
    }
    stepikProjectManager.setRootNode(projectRoot);
    stepikProjectManager.setDefaultLang(getDefaultLang());
    stepikProjectManager.setCreatedBy(getCurrentUser().getId());
    Metrics.createProject(project, SUCCESSFUL);
}
Also used : StepikProjectManager(org.stepik.core.StepikProjectManager)

Example 4 with StepikProjectManager

use of org.stepik.core.StepikProjectManager in project intellij-plugins by StepicOrg.

the class InsertStepikDirectives method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) {
        return;
    }
    StudyNode selectedNode = StepikProjectManager.getSelected(project);
    if (!(selectedNode instanceof StepNode) || ((StepNode) selectedNode).getType() != CODE) {
        return;
    }
    StepNode targetStepNode = (StepNode) selectedNode;
    FileDocumentManager documentManager = FileDocumentManager.getInstance();
    for (VirtualFile file : FileEditorManager.getInstance(project).getOpenFiles()) {
        Document document = documentManager.getDocument(file);
        if (document != null)
            documentManager.saveDocument(document);
    }
    SupportedLanguages currentLang = targetStepNode.getCurrentLang();
    VirtualFile src = getOrCreateSrcDirectory(project, targetStepNode, true);
    if (src == null) {
        return;
    }
    VirtualFile file = src.findChild(currentLang.getMainFileName());
    if (file == null) {
        return;
    }
    String text = getFileText(file);
    StepikProjectManager projectManager = StepikProjectManager.getInstance(project);
    boolean showHint = projectManager != null && projectManager.getShowHint();
    boolean needInsert = !containsDirectives(text, currentLang);
    if (needInsert) {
        text = insertAmbientCode(text, currentLang, showHint);
        Metrics.insertAmbientCodeAction(project, targetStepNode, SUCCESSFUL);
    } else {
        text = removeAmbientCode(text, showHint, currentLang, true);
        Metrics.removeAmbientCodeAction(project, targetStepNode, SUCCESSFUL);
    }
    writeInToFile(text, file, project);
    if (needInsert) {
        final Document document = FileDocumentManager.getInstance().getDocument(file);
        if (document != null) {
            ReformatUtils.reformatSelectedEditor(project, document);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SupportedLanguages(org.stepik.core.SupportedLanguages) Project(com.intellij.openapi.project.Project) StepikProjectManager(org.stepik.core.StepikProjectManager) StepNode(org.stepik.core.courseFormat.StepNode) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document) StudyNode(org.stepik.core.courseFormat.StudyNode)

Aggregations

StepikProjectManager (org.stepik.core.StepikProjectManager)4 StudyNode (org.stepik.core.courseFormat.StudyNode)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 StepNode (org.stepik.core.courseFormat.StepNode)2 Application (com.intellij.openapi.application.Application)1 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 Project (com.intellij.openapi.project.Project)1 File (java.io.File)1 StepikApiClient (org.stepik.api.client.StepikApiClient)1 StepikMetricsPostQuery (org.stepik.api.queries.metrics.StepikMetricsPostQuery)1 SupportedLanguages (org.stepik.core.SupportedLanguages)1 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)1