11// Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
3- import { Uri , l10n , workspace } from "vscode" ;
3+ import { Uri , authentication , l10n , workspace } from "vscode" ;
44
5+ import axios , { AxiosInstance } from "axios" ;
56import { basename } from "path" ;
67import { v4 } from "uuid" ;
78
8- import SASContentAdapter from "../../connection/rest/SASContentAdapter" ;
99import {
1010 associateFlowObject ,
1111 createStudioSession ,
1212} from "../../connection/studio" ;
13+ import { SASAuthProvider } from "../AuthProvider" ;
1314import { ContentModel } from "./ContentModel" ;
1415import { MYFOLDER_TYPE , Messages } from "./const" ;
15- import { ContentItem } from "./types" ;
16+ import { ContentItem , ContentSourceType } from "./types" ;
1617import { isContentItem } from "./utils" ;
1718
1819const stepRef : Record < string , string > = {
@@ -339,10 +340,13 @@ export function convertNotebookToFlow(
339340
340341export class NotebookToFlowConverter {
341342 protected studioSessionId : string ;
343+ protected connection : AxiosInstance ;
344+
342345 public constructor (
343346 protected readonly resource : ContentItem | Uri ,
344347 protected readonly contentModel : ContentModel ,
345348 protected readonly viyaEndpoint : string ,
349+ protected readonly sourceType : ContentSourceType ,
346350 ) { }
347351
348352 public get inputName ( ) {
@@ -351,13 +355,6 @@ export class NotebookToFlowConverter {
351355 : basename ( this . resource . fsPath ) ;
352356 }
353357
354- private get connection ( ) {
355- return (
356- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
357- ( this . contentModel . getAdapter ( ) as SASContentAdapter ) . getConnection ( )
358- ) ;
359- }
360-
361358 private async parent ( ) {
362359 const parentItem = isContentItem ( this . resource )
363360 ? await this . contentModel . getParent ( this . resource )
@@ -385,9 +382,11 @@ export class NotebookToFlowConverter {
385382 }
386383
387384 public async establishConnection ( ) {
388- if ( ! this . contentModel . connected ( ) ) {
389- await this . contentModel . connect ( this . viyaEndpoint ) ;
390- }
385+ this . connection = axios . create ( { baseURL : this . viyaEndpoint } ) ;
386+ const session = await authentication . getSession ( SASAuthProvider . id , [ ] , {
387+ createIfNone : true ,
388+ } ) ;
389+ this . connection . defaults . headers . common . Authorization = `Bearer ${ session . accessToken } ` ;
391390
392391 try {
393392 const result = await createStudioSession ( this . connection ) ;
@@ -422,6 +421,14 @@ export class NotebookToFlowConverter {
422421 ) ;
423422 }
424423
424+ // We don't need to associate the flow object if it's stored in sas server
425+ if ( this . sourceType === ContentSourceType . SASServer ) {
426+ return {
427+ parentItem,
428+ folderName : parentItem . uri . split ( "/" ) . pop ( ) . replace ( / ~ f s ~ / g, "/" ) ,
429+ } ;
430+ }
431+
425432 // associate the new .flw file with SAS Studio
426433 const folderName = await associateFlowObject (
427434 outputName ,
0 commit comments