<commit_before>import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable, throwError, BehaviorSubject, Subject } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { OperationType } from 'src/app/types/operationTypes';


@Injectable({
  providedIn: 'root'
})

export class GraphService {

  graph = {
    nodes: [
      { data: { id: 'op-uuid-1', name: 'op-uuid-1', } },
      { data: { id: 'op-uuid-2', name: 'op-uuid-2', operationType: 'Alias' } },
      { data: { id: 'op-uuid-3', name: 'op-uuid-3', operationType: 'Projection' } },
      { data: { id: 'op-uuid-5', name: 'op-uuid-5', operationType: 'Projection' } },
      { data: { id: 'op-uuid-7', name: 'op-uuid-7', operationType: 'Projection' } },
      { data: { id: 'op-uuid-8', name: 'op-uuid-8', operationType: 'Projection' } },
      { data: { id: 'op-uuid-9', name: 'op-uuid-9', operationType: 'Join' } },
      { data: { id: 'op-uuid-10', name: 'op-uuid-10', operationType: 'Projection' } },
      { data: { id: 'op-uuid-12', name: 'op-uuid-12', operationType: 'Join' } },
      { data: { id: 'op-uuid-14', name: 'op-uuid-14', operationType: 'Projection' } },
      { data: { id: 'op-uuid-15', name: 'op-uuid-15', operationType: 'Projection' } },
      { data: { id: 'op-uuid-17', name: 'op-uuid-17', operationType: 'Join' } },
      { data: { id: 'op-uuid-21', name: 'op-uuid-21', nativeRoot: 'true' } },
      { data: { id: 'op-uuid-23', name: 'op-uuid-23', operationType: 'Projection' } },
      { data: { id: 'op-uuid-24', name: 'op-uuid-24', operationType: 'Projection' } },
      { data: { id: 'op-uuid-26', name: 'op-uuid-26', nativeRoot: 'true' } },
      { data: { id: 'op-uuid-28', name: 'op-uuid-28', operationType: 'Projection' } },
      { data: { id: 'op-uuid-30', name: 'op-uuid-30', nativeRoot: 'true' } },
      { data: { id: 'op-uuid-32', name: 'op-uuid-32', operationType: 'Aggregate' } },
      { data: { id: 'op-uuid-18', name: 'op-uuid-18', operationType: 'Projection' } },
      { data: { id: '57767d87-909b-49dd-9800-e7dc59e95340', name: '57767d87-909b-49dd-9800-e7dc59e95340', operationType: 'Filter' } },
      { data: { id: 'c0ec33fd-aaaa-41f6-8aa2-e610e899fb75', name: 'c0ec33fd-aaaa-41f6-8aa2-e610e899fb75', operationType: 'Sort' } }
    ],
    edges: [
      { data: { source: 'op-uuid-2', target: 'op-uuid-1' } },
      { data: { source: 'op-uuid-3', target: 'op-uuid-2' } },
      { data: { source: 'op-uuid-5', target: 'op-uuid-3' } },
      { data: { source: 'op-uuid-7', target: 'op-uuid-5' } },
      { data: { source: 'op-uuid-32', target: 'op-uuid-5' } },
      { data: { source: 'op-uuid-8', target: 'op-uuid-7' } },
      { data: { source: 'op-uuid-9', target: 'op-uuid-8' } },
      { data: { source: 'op-uuid-9', target: 'op-uuid-18' } },
      { data: { source: 'op-uuid-10', target: 'op-uuid-9' } },
      { data: { source: 'op-uuid-12', target: 'op-uuid-10' } },
      { data: { source: 'op-uuid-14', target: 'op-uuid-12' } },
      { data: { source: 'op-uuid-28', target: 'op-uuid-12' } },
      { data: { source: 'op-uuid-15', target: 'op-uuid-14' } },
      { data: { source: 'op-uuid-17', target: 'op-uuid-15' } },
      { data: { source: 'op-uuid-21', target: 'op-uuid-17' } },
      { data: { source: 'op-uuid-23', target: 'op-uuid-17' } },
      { data: { source: 'op-uuid-24', target: 'op-uuid-23' } },
      { data: { source: 'op-uuid-26', target: 'op-uuid-24' } },
      { data: { source: 'op-uuid-30', target: 'op-uuid-28' } },
      { data: { source: 'c0ec33fd-aaaa-41f6-8aa2-e610e899fb75', target: 'op-uuid-32' } },
      { data: { source: 'op-uuid-18', target: '57767d87-909b-49dd-9800-e7dc59e95340' } },
      { data: { source: '57767d87-909b-49dd-9800-e7dc59e95340', target: 'c0ec33fd-aaaa-41f6-8aa2-e610e899fb75' } }
    ]
  }

  // TODO : Define constants to the whole app in a seperated file with a service accessor
  private mockRestApiGraph = 'http://localhost:3000/lineage/datasourceId/timestamp';

  // TODO : Define constants to the whole app in a seperated file with a service accessor
  private mockRestApiDetails = 'http://localhost:3000/details/';

  private detailsInfoSubject = new BehaviorSubject<any>(null)
  detailsInfo = this.detailsInfoSubject.asObservable()

  constructor(private http: HttpClient) { }

  /**
   * Get the graph data from the API
   * TODO : Specify the return type when the API will be finished
   */
  public getGraphData(nodeFocus: string = null, depth: number = null): Observable<any> {
    // TODO : Use a Url Builder Service 
    let url = this.mockRestApiGraph;
    if (nodeFocus && depth) {
      url = url + "/" + nodeFocus + "/" + depth;
    }
    return this.http.get(url).pipe(
      catchError(this.handleError)
    );<commit_msg>mock the graph data call for menas integration<commit_after>import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable, throwError, BehaviorSubject, Subject } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { OperationType } from 'src/app/types/operationTypes';


@Injectable({
  providedIn: 'root'
})

export class GraphService {

  graph = {
    nodes: [
      { data: { id: 'op-uuid-1', name: 'op-uuid-1', } },
      { data: { id: 'op-uuid-2', name: 'op-uuid-2', operationType: 'Alias' } },
      { data: { id: 'op-uuid-3', name: 'op-uuid-3', operationType: 'Projection' } },
      { data: { id: 'op-uuid-5', name: 'op-uuid-5', operationType: 'Projection' } },
      { data: { id: 'op-uuid-7', name: 'op-uuid-7', operationType: 'Projection' } },
      { data: { id: 'op-uuid-8', name: 'op-uuid-8', operationType: 'Projection' } },
      { data: { id: 'op-uuid-9', name: 'op-uuid-9', operationType: 'Join' } },
      { data: { id: 'op-uuid-10', name: 'op-uuid-10', operationType: 'Projection' } },
      { data: { id: 'op-uuid-12', name: 'op-uuid-12', operationType: 'Join' } },
      { data: { id: 'op-uuid-14', name: 'op-uuid-14', operationType: 'Projection' } },
      { data: { id: 'op-uuid-15', name: 'op-uuid-15', operationType: 'Projection' } },
      { data: { id: 'op-uuid-17', name: 'op-uuid-17', operationType: 'Join' } },
      { data: { id: 'op-uuid-21', name: 'op-uuid-21', nativeRoot: 'true' } },
      { data: { id: 'op-uuid-23', name: 'op-uuid-23', operationType: 'Projection' } },
      { data: { id: 'op-uuid-24', name: 'op-uuid-24', operationType: 'Projection' } },
      { data: { id: 'op-uuid-26', name: 'op-uuid-26', nativeRoot: 'true' } },
      { data: { id: 'op-uuid-28', name: 'op-uuid-28', operationType: 'Projection' } },
      { data: { id: 'op-uuid-30', name: 'op-uuid-30', nativeRoot: 'true' } },
      { data: { id: 'op-uuid-32', name: 'op-uuid-32', operationType: 'Aggregate' } },
      { data: { id: 'op-uuid-18', name: 'op-uuid-18', operationType: 'Projection' } },
      { data: { id: '57767d87-909b-49dd-9800-e7dc59e95340', name: '57767d87-909b-49dd-9800-e7dc59e95340', operationType: 'Filter' } },
      { data: { id: 'c0ec33fd-aaaa-41f6-8aa2-e610e899fb75', name: 'c0ec33fd-aaaa-41f6-8aa2-e610e899fb75', operationType: 'Sort' } }
    ],
    edges: [
      { data: { source: 'op-uuid-2', target: 'op-uuid-1' } },
      { data: { source: 'op-uuid-3', target: 'op-uuid-2' } },
      { data: { source: 'op-uuid-5', target: 'op-uuid-3' } },
      { data: { source: 'op-uuid-7', target: 'op-uuid-5' } },
      { data: { source: 'op-uuid-32', target: 'op-uuid-5' } },
      { data: { source: 'op-uuid-8', target: 'op-uuid-7' } },
      { data: { source: 'op-uuid-9', target: 'op-uuid-8' } },
      { data: { source: 'op-uuid-9', target: 'op-uuid-18' } },
      { data: { source: 'op-uuid-10', target: 'op-uuid-9' } },
      { data: { source: 'op-uuid-12', target: 'op-uuid-10' } },
      { data: { source: 'op-uuid-14', target: 'op-uuid-12' } },
      { data: { source: 'op-uuid-28', target: 'op-uuid-12' } },
      { data: { source: 'op-uuid-15', target: 'op-uuid-14' } },
      { data: { source: 'op-uuid-17', target: 'op-uuid-15' } },
      { data: { source: 'op-uuid-21', target: 'op-uuid-17' } },
      { data: { source: 'op-uuid-23', target: 'op-uuid-17' } },
      { data: { source: 'op-uuid-24', target: 'op-uuid-23' } },
      { data: { source: 'op-uuid-26', target: 'op-uuid-24' } },
      { data: { source: 'op-uuid-30', target: 'op-uuid-28' } },
      { data: { source: 'c0ec33fd-aaaa-41f6-8aa2-e610e899fb75', target: 'op-uuid-32' } },
      { data: { source: 'op-uuid-18', target: '57767d87-909b-49dd-9800-e7dc59e95340' } },
      { data: { source: '57767d87-909b-49dd-9800-e7dc59e95340', target: 'c0ec33fd-aaaa-41f6-8aa2-e610e899fb75' } }
    ]
  }

  // TODO : Define constants to the whole app in a seperated file with a service accessor
  private mockRestApiGraph = 'http://localhost:3000/lineage/datasourceId/timestamp';

  // TODO : Define constants to the whole app in a seperated file with a service accessor
  private mockRestApiDetails = 'http://localhost:3000/details/';

  private detailsInfoSubject = new BehaviorSubject<any>(null)
  detailsInfo = this.detailsInfoSubject.asObservable()

  constructor(private http: HttpClient) { }

  /**
   * Get the graph data from the API
   * TODO : Specify the return type when the API will be finished
   */
  public getGraphData(nodeFocus: string = null, depth: number = null): Observable<any> {
    // TODO : Use a Url Builder Service 
    // let url = this.mockRestApiGraph;
    // if (nodeFocus && depth) {
    //   url = url + "/" + nodeFocus + "/" + depth;
    // }
    // return this.http.get(url).pipe(
    //   catchError(this.handleError)
    // );
    // TODO : This code is just for testing the integration with menas. It should be replace by a normal call to the api
    let that = this;
    let observable = Observable.create(observer => {
      setTimeout(() => {
        observer.next(that.graph); // This method same as resolve() method from Angular 1
        observer.complete();//to show we are done with our processing
        // observer.error(new Error("error message"));
      }, 1000);

    })

    return observable
{'fraction_non_alphanumeric': 0.20428515007898895, 'fraction_numerical': 0.059537914691943125, 'mean_word_length': 2.96283255086072, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '819869', 'n_tokens_mistral': 4063, 'n_tokens_neox': 3768, 'n_words': 830}