<commit_before>import { Injectable } from '@angular/core';
import { EMPTY, Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { AlertService } from '../../shared/alert/state/alert.service';
import { EntriesService } from '../../shared/openapi';
import { WorkflowQuery } from '../../shared/state/workflow.query';
import { WorkflowService } from '../../shared/state/workflow.service';
import { Workflow, WorkflowsService, WorkflowVersion } from '../../shared/swagger';

@Injectable({
  providedIn: 'root',
})
export class SnapshotExporterModalService {
  constructor(
    private alertService: AlertService,
    private workflowService: WorkflowService,
    private workflowsService: WorkflowsService,
    private workflowQuery: WorkflowQuery,
    private entriesService: EntriesService
  ) {}

  public snapshotWorkflowVersion(workflow: Workflow, version: WorkflowVersion): Observable<void> {
    this.alertService.start(`Snapshotting workflow ${workflow.workflowName} version ${version.name}`);
    const snapshot: WorkflowVersion = { ...version, frozen: true };
    return this.workflowsService.updateWorkflowVersion(workflow.id, [snapshot]).pipe(
      map((workflowVersions: Array<WorkflowVersion>) => {
        this.alertService.detailedSuccess(`A snapshot was created for workflow
                                       "${workflow.workflowName}" version "${version.name}"!`);
        const selectedWorkflow = { ...this.workflowQuery.getActive() };
        if (selectedWorkflow.id === workflow.id) {
          this.workflowService.setWorkflow({ ...selectedWorkflow, workflowVersions: workflowVersions });
        }
      }),
      catchError((error) => {
        if (error) {
          this.alertService.detailedError(error);
        } else {
          this.alertService.simpleError();
        }
        return EMPTY;
      })
    );
  }

  public requestDOI(workflow: Workflow, version: WorkflowVersion): Observable<void> {
    this.alertService.start(`A Digital Object Identifier (DOI) is being requested for workflow
                                       "${workflow.workflowName}" version "${version.name}"!`);
    return this.workflowsService.requestDOIForWorkflowVersion(workflow.id, version.id).pipe(
      map((versions) => {
        const selectedWorkflow = { ...this.workflowQuery.getActive() };
        if (selectedWorkflow.id === workflow.id) {
          this.workflowService.setWorkflow({ ...selectedWorkflow, workflowVersions: versions });
        }

        const workflowName: string = workflow.workflowName || workflow.repository;

        this.alertService.detailedSuccess(`A Digital Object Identifier (DOI) was created for workflow
                                       "${workflowName}" version "${version.name}"!`);
      }),
      catchError((error) => {
        return EMPTY;
      })
    );
  }

  public exportToOrcid(workflow: Workflow, version: WorkflowVersion): Observable<void> {
    this.alertService.start(`Exporting workflow ${workflow.workflowName} version ${version.name} to ORCID`);
    return this.entriesService.exportToORCID(workflow.id, version.id).pipe(
      map((result) => {
        this.alertService.detailedSuccess(`Exported workflow ${workflow.workflowName} version ${version.name} to ORCID`);
      }),
      catchError((error) => {
        this.alertService.detailedError(error);
        return EMPTY;
      })
    );
  }
}
<commit_msg>Fall back to repository (#1332)<commit_after>import { Injectable } from '@angular/core';
import { EMPTY, Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { AlertService } from '../../shared/alert/state/alert.service';
import { EntriesService } from '../../shared/openapi';
import { WorkflowQuery } from '../../shared/state/workflow.query';
import { WorkflowService } from '../../shared/state/workflow.service';
import { Workflow, WorkflowsService, WorkflowVersion } from '../../shared/swagger';

@Injectable({
  providedIn: 'root',
})
export class SnapshotExporterModalService {
  constructor(
    private alertService: AlertService,
    private workflowService: WorkflowService,
    private workflowsService: WorkflowsService,
    private workflowQuery: WorkflowQuery,
    private entriesService: EntriesService
  ) {}

  public snapshotWorkflowVersion(workflow: Workflow, version: WorkflowVersion): Observable<void> {
    const workflowName: string = workflow.workflowName || workflow.repository;
    this.alertService.start(`Snapshotting workflow ${workflowName} version ${version.name}`);
    const snapshot: WorkflowVersion = { ...version, frozen: true };
    return this.workflowsService.updateWorkflowVersion(workflow.id, [snapshot]).pipe(
      map((workflowVersions: Array<WorkflowVersion>) => {
        this.alertService.detailedSuccess(`A snapshot was created for workflow
                                       "${workflowName}" version "${version.name}"!`);
        const selectedWorkflow = { ...this.workflowQuery.getActive() };
        if (selectedWorkflow.id === workflow.id) {
          this.workflowService.setWorkflow({ ...selectedWorkflow, workflowVersions: workflowVersions });
        }
      }),
      catchError((error) => {
        if (error) {
          this.alertService.detailedError(error);
        } else {
          this.alertService.simpleError();
        }
        return EMPTY;
      })
    );
  }

  public requestDOI(workflow: Workflow, version: WorkflowVersion): Observable<void> {
    const workflowName: string = workflow.workflowName || workflow.repository;
    this.alertService.start(`A Digital Object Identifier (DOI) is being requested for workflow
                                       "${workflowName}" version "${version.name}"!`);
    return this.workflowsService.requestDOIForWorkflowVersion(workflow.id, version.id).pipe(
      map((versions) => {
        const selectedWorkflow = { ...this.workflowQuery.getActive() };
        if (selectedWorkflow.id === workflow.id) {
          this.workflowService.setWorkflow({ ...selectedWorkflow, workflowVersions: versions });
        }
        this.alertService.detailedSuccess(`A Digital Object Identifier (DOI) was created for workflow
                                       "${workflowName}" version "${version.name}"!`);
      }),
      catchError((error) => {
        return EMPTY;
      })
    );
  }

  public exportToOrcid(workflow: Workflow, version: WorkflowVersion): Observable<void> {
    const workflowName: string = workflow.workflowName || workflow.repository;
    this.alertService.start(`Exporting workflow ${workflowName} version ${version.name} to ORCID`);
    return this.entriesService.exportToORCID(workflow.id, version.id).pipe(
      map((result) => {
        this.alertService.detailedSuccess(`Exported workflow ${workflowName} version ${version.name} to ORCID`);
      }),
      catchError((error) => {
        this.alertService.detailedError(error);
        return EMPTY;
      })
    );
  }
}

{'fraction_non_alphanumeric': 0.129967006168412, 'fraction_numerical': 0.0005738057667479559, 'mean_word_length': 3.179856115107914, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6891692', 'n_tokens_mistral': 1920, 'n_tokens_neox': 1889, 'n_words': 390}