Skip to content

Commit b2f807d

Browse files
Scott DoverScott Dover
authored andcommitted
chore: update notebook to flow functionality
Signed-off-by: Scott Dover <[email protected]>
1 parent 248d4d8 commit b2f807d

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

client/src/components/ContentNavigator/convert.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
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";
56
import { basename } from "path";
67
import { v4 } from "uuid";
78

8-
import SASContentAdapter from "../../connection/rest/SASContentAdapter";
99
import {
1010
associateFlowObject,
1111
createStudioSession,
1212
} from "../../connection/studio";
13+
import { SASAuthProvider } from "../AuthProvider";
1314
import { ContentModel } from "./ContentModel";
1415
import { MYFOLDER_TYPE, Messages } from "./const";
15-
import { ContentItem } from "./types";
16+
import { ContentItem, ContentSourceType } from "./types";
1617
import { isContentItem } from "./utils";
1718

1819
const stepRef: Record<string, string> = {
@@ -339,10 +340,13 @@ export function convertNotebookToFlow(
339340

340341
export 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(/~fs~/g, "/"),
429+
};
430+
}
431+
425432
// associate the new .flw file with SAS Studio
426433
const folderName = await associateFlowObject(
427434
outputName,

client/src/components/ContentNavigator/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ class ContentNavigator implements SubscriptionProvider {
281281
resource,
282282
this.contentModel,
283283
this.viyaEndpoint(),
284+
this.sourceType,
284285
);
285286

286287
const inputName = notebookToFlowConverter.inputName;

client/src/connection/rest/RestSASServerAdapter.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,15 @@ class RestSASServerAdapter implements ContentAdapter {
264264
public async getParentOfItem(
265265
item: ContentItem,
266266
): Promise<ContentItem | undefined> {
267-
// TODO (sas-server) This is needed for converting a sas
268-
// notebook to flow.
269-
throw new Error("getParentOfItem Method not implemented.");
267+
const parentPathPieces = this.trimComputePrefix(item.uri).split("~fs~");
268+
parentPathPieces.pop();
269+
const fileOrDirectoryPath = parentPathPieces.join("~fs~");
270+
const response = await this.fileSystemApi.getFileorDirectoryProperties({
271+
sessionId: this.sessionId,
272+
fileOrDirectoryPath,
273+
});
274+
275+
return this.filePropertiesToContentItem(response.data);
270276
}
271277

272278
public getRootFolder(): ContentItem | undefined {

0 commit comments

Comments
 (0)