src/app/services/sas-viya.service.ts

Metadata

Index

Properties
Methods

Constructor

constructor(http: HttpClient, appStoreService: AppStoreService)
Parameters :
Name Type Optional
http HttpClient No
appStoreService AppStoreService No

Methods

get
get<T>(url: string, options?: { headers?: HttpHeaders | literal type; context?: HttpContext; observe?: body; params?: HttpParams | literal type; reportProgress?: boolean; responseType?: json; withCredentials?: boolean; transferCache?: literal type | boolean })
Type parameters :
  • T
Returns : Observable<T>
getAdminGroups
getAdminGroups(limit: number)
Parameters :
Name Type Optional Default value
limit number No 5000
getAllCollections
getAllCollections()
Returns : ViyaApis

All Viya API collections that we support

getByCollection
getByCollection(apiCollection: string)

We refer collection as starting point /jobs /folders etc.

Parameters :
Name Type Optional
apiCollection string No
Returns : Observable<Collection>
getByUrl
getByUrl(url: string)

Used for clicking trough collections / apis

Parameters :
Name Type Optional Description
url string No

collection/api endpoint url

Returns : Observable<Collection>
getComputeContextById
getComputeContextById(id: string)
Parameters :
Name Type Optional
id string No
getComputeContexts
getComputeContexts()
getCurrentUser
getCurrentUser()
Returns : Observable<ViyaApiCurrentUser>
getCurrentUserGroupMemberships
getCurrentUserGroupMemberships(limit: number)
Parameters :
Name Type Optional Default value
limit number No 10000

The groups the current user is a member of

getFolderByPath
getFolderByPath(path: string)
Parameters :
Name Type Optional Description
path string No

Path to the folder

The folder info object

getFolderMembers
getFolderMembers(folderId: string, limit: number)
Parameters :
Name Type Optional Default value
folderId string No
limit number No 500
Returns : Observable<ViyaApiFolderMembers>
setup
setup()

This function is replacing the constructor. The reason for this is timing issues, other services eg. sas.service, app-store.service must be initialized before this bit of code is executed. This function is being called by sas.service

Returns : void

Properties

Private serverUrl
Type : string
Default value : ''
Public viyaApis
Type : ViyaApis
Default value : { Analytics_Insights: { insights: '/insights' }, Visualisation: { reports: '/reports', reportImages: '/reportImages', reportTransforms: '/reportTransforms', visualAnalytics: '/visualAnalytics' }, Compute: { jobs: '/jobDefinitions', jobExecution: '/jobExecution', contexts: '/compute/contexts' }, Decision_Management: { modelManagement: '/modelManagement', modelRepository: '/modelRepository', modelPublish: '/modelPublish', microanalyticScore: '/microanalyticScore', dataMining: '/dataMining', businessRules: '/businessRules', referenceData: '/referenceData', treatmentDefinitions: '/treatmentDefinitions', subjectContacts: '/subjectContacts', decisionsRuntimeBuilder: '/decisionsRuntimeBuilder' }, Core_Services: { folders: '/folders', files: '/files', annotations: '/annotations', authorization: '/authorization', relationships: '/relationships', SASLogon: '/SASLogon' }, Automated_Machine_Learning: { mlPipelineAutomation: '/mlPipelineAutomation' }, Other: { identities: '/identities' } }
import {
  HttpClient,
  HttpContext,
  HttpErrorResponse,
  HttpHeaders,
  HttpParams
} from '@angular/common/http'
import { Injectable } from '@angular/core'
import { catchError, Observable, throwError } from 'rxjs'
import { Collection } from '../viya-api-explorer/models/collection.model'
import { AppStoreService } from './app-store.service'
import { ViyaApis } from '../viya-api-explorer/models/viya-apis.models'
import { ViyaApiFolderMembers } from '../viya-api-explorer/models/viya-api-folder-content.model'
import { ViyaApiFolder } from '../viya-api-explorer/models/viya-api-folder.model'
import { ViyaApiIdentities } from '../viya-api-explorer/models/viya-api-identities.model'
import { ViyaApiCurrentUser } from '../viya-api-explorer/models/viya-api-current-user.model'
import { ViyaComputeContexts } from '../viya-api-explorer/models/viya-compute-contexts.model'
import { ComputeContextDetails } from '../viya-api-explorer/models/viya-compute-context-details.model'

@Injectable({
  providedIn: 'root'
})
export class SasViyaService {
  // Viya APIs
  public viyaApis: ViyaApis = {
    Analytics_Insights: {
      insights: '/insights'
    },
    Visualisation: {
      reports: '/reports',
      reportImages: '/reportImages',
      reportTransforms: '/reportTransforms',
      visualAnalytics: '/visualAnalytics'
    },
    Compute: {
      jobs: '/jobDefinitions',
      jobExecution: '/jobExecution',
      contexts: '/compute/contexts'
    },
    Decision_Management: {
      modelManagement: '/modelManagement',
      modelRepository: '/modelRepository',
      modelPublish: '/modelPublish',
      microanalyticScore: '/microanalyticScore',
      dataMining: '/dataMining',
      businessRules: '/businessRules',
      referenceData: '/referenceData',
      treatmentDefinitions: '/treatmentDefinitions',
      subjectContacts: '/subjectContacts',
      decisionsRuntimeBuilder: '/decisionsRuntimeBuilder'
    },
    Core_Services: {
      folders: '/folders',
      files: '/files',
      annotations: '/annotations',
      authorization: '/authorization',
      relationships: '/relationships',
      SASLogon: '/SASLogon'
    },
    Automated_Machine_Learning: {
      mlPipelineAutomation: '/mlPipelineAutomation'
    },
    Other: {
      identities: '/identities'
    }
  }

  private serverUrl: string = ''

  constructor(
    private http: HttpClient,
    private appStoreService: AppStoreService
  ) {}

  /**
   * This function is replacing the constructor.
   * The reason for this is timing issues, other services eg. sas.service, app-store.service
   * must be initialized before this bit of code is executed.
   * This function is being called by `sas.service`
   */
  setup() {
    const adapterConfig = this.appStoreService.getDcAdapterSettings()

    this.serverUrl = adapterConfig?.serverUrl || ''

    // example collection request
    // this.getByCollection('jobs').subscribe((res) => {
    //   console.log('res', res)
    // })
  }

  /**
   *
   * @returns All Viya API collections that we support
   */
  getAllCollections() {
    return this.viyaApis
  }

  /**
   * Used for clicking trough collections / apis
   * @param url collection/api endpoint url
   * @returns
   */
  getByUrl(url: string): Observable<Collection> {
    return this.get<Collection>(`${this.serverUrl}${url}`, {
      withCredentials: true
    })
  }

  /**
   * We refer collection as starting point /jobs /folders etc.
   * @param apiCollection
   * @returns
   */
  getByCollection(apiCollection: string): Observable<Collection> {
    return this.get<Collection>(`${this.serverUrl}${apiCollection}`, {
      withCredentials: true
    })
  }

  getComputeContexts(): Observable<ViyaComputeContexts> {
    return this.get<ViyaComputeContexts>(
      `${this.serverUrl}/compute/contexts?limit=1000`,
      {
        withCredentials: true
      }
    )
  }

  getComputeContextById(id: string): Observable<ComputeContextDetails> {
    return this.get<ComputeContextDetails>(
      `${this.serverUrl}/compute/contexts/${id}`,
      {
        withCredentials: true
      }
    )
  }

  /**
   * @param path Path to the folder
   * @returns The folder info object
   */
  getFolderByPath(path: string): Observable<ViyaApiFolder> {
    return this.get<ViyaApiFolder>(
      `${this.serverUrl}/folders/folders/@item?path=${path}`,
      {
        withCredentials: true
      }
    )
  }

  getFolderMembers(
    folderId: string,
    limit: number = 500
  ): Observable<ViyaApiFolderMembers> {
    return this.get<ViyaApiFolderMembers>(
      `${this.serverUrl}/folders/folders/${folderId}/members?limit=${limit}`,
      {
        withCredentials: true
      }
    )
  }

  getAdminGroups(limit: number = 5000): Observable<ViyaApiIdentities> {
    return this.get<ViyaApiIdentities>(
      `${this.serverUrl}/identities/groups?sortBy=name&limit=${limit}`,
      {
        withCredentials: true
      }
    )
  }

  /**
   * @returns The groups the current user is a member of
   */
  getCurrentUserGroupMemberships(
    limit: number = 10000
  ): Observable<ViyaApiIdentities> {
    return this.get<ViyaApiIdentities>(
      `${this.serverUrl}/identities/users/@currentUser/memberships?limit=${limit}`,
      {
        withCredentials: true
      }
    )
  }

  getCurrentUser(): Observable<ViyaApiCurrentUser> {
    return this.get<ViyaApiCurrentUser>(
      `${this.serverUrl}/identities/users/@currentUser`,
      {
        withCredentials: true
      }
    )
  }

  get<T>(
    url: string,
    options?: {
      headers?:
        | HttpHeaders
        | {
            [header: string]: string | string[]
          }
      context?: HttpContext
      observe?: 'body'
      params?:
        | HttpParams
        | {
            [param: string]:
              | string
              | number
              | boolean
              | ReadonlyArray<string | number | boolean>
          }
      reportProgress?: boolean
      responseType?: 'json'
      withCredentials?: boolean
      transferCache?:
        | {
            includeHeaders?: string[]
          }
        | boolean
    }
  ): Observable<T> {
    return this.http.get<T>(url, options).pipe(
      catchError((err: HttpErrorResponse) => {
        console.log('url', url)
        console.log('err.status', err.status)
        if (err.status === 449 || err.status === 401) {
          // Retry once if we got a 449
          return this.http.get<T>(url, options)
        }
        // Otherwise propagate the error
        return throwError(() => err)
      })
    )
  }
}

results matching ""

    No results matching ""