From 5076ea696cc243aa5d8d0751ddd470d53f2a4f15 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Fri, 18 Sep 2020 09:24:33 +0100 Subject: [PATCH] feat(job-execution): support absolute job paths for JES and web approaches --- src/SASViyaApiClient.ts | 24 ++++++++++++++---------- src/SASjs.ts | 22 +++++++++++++++++----- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/SASViyaApiClient.ts b/src/SASViyaApiClient.ts index f7360fa..7451910 100644 --- a/src/SASViyaApiClient.ts +++ b/src/SASViyaApiClient.ts @@ -47,12 +47,15 @@ export class SASViyaApiClient { * Returns a list of jobs in the currently set root folder. */ public async getJobsInFolder(folderPath: string) { - if (this.folderMap.get(folderPath)) { - return this.folderMap.get(folderPath) + const path = isRelativePath(folderPath) + ? `${this.rootFolderName}/${folderPath}` + : folderPath + if (this.folderMap.get(path)) { + return this.folderMap.get(path) } - await this.populateFolderMap(folderPath) - return this.folderMap.get(folderPath) + await this.populateFolderMap(path) + return this.folderMap.get(path) } /** @@ -1136,11 +1139,14 @@ export class SASViyaApiClient { } private async populateFolderMap(folderPath: string, accessToken?: string) { - if (this.folderMap.get(folderPath)) { + const path = isRelativePath(folderPath) + ? `${this.rootFolderName}/${folderPath}` + : folderPath + if (this.folderMap.get(path)) { return } - const url = '/folders/folders/@item?path=' + folderPath + const url = '/folders/folders/@item?path=' + path const requestInfo: any = { method: 'GET' } @@ -1152,9 +1158,7 @@ export class SASViyaApiClient { requestInfo ) if (!folder) { - throw new Error( - `The path ${folderPath} does not exist on ${this.serverUrl}` - ) + throw new Error(`The path ${path} does not exist on ${this.serverUrl}`) } const { result: members } = await this.request<{ items: any[] }>( `${this.serverUrl}/folders/folders/${folder.id}/members`, @@ -1162,7 +1166,7 @@ export class SASViyaApiClient { ) const itemsAtRoot = members.items - this.folderMap.set(folderPath, itemsAtRoot) + this.folderMap.set(path, itemsAtRoot) } private async pollJobState( diff --git a/src/SASjs.ts b/src/SASjs.ts index 34a327e..131f05a 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -21,7 +21,8 @@ import { parseGeneratedCode, parseWeboutResponse, needsRetry, - asyncForEach + asyncForEach, + isRelativePath } from './utils' import { SASjsConfig, @@ -791,7 +792,9 @@ export default class SASjs { ? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '') : sasJob const jobUri = - config.serverType === 'SASVIYA' ? await this.getJobUri(sasJob) : '' + config.serverType === ServerType.SASViya + ? await this.getJobUri(sasJob) + : '' const apiUrl = `${config.serverUrl}${this.jobsPath}/?${ jobUri.length > 0 ? '__program=' + program + '&_job=' + jobUri @@ -1063,10 +1066,18 @@ export default class SASjs { if (!this.sasViyaApiClient) return '' let uri = '' - const jobKey = sasJob.split('/')[0] - const jobName = sasJob.split('/')[1] + let folderPath + let jobName: string + if (isRelativePath(sasJob)) { + folderPath = sasJob.split('/')[0] + jobName = sasJob.split('/')[1] + } else { + const folderPathParts = sasJob.split('/') + jobName = folderPathParts.pop() || '' + folderPath = folderPathParts.join('/') + } - const locJobs = await this.sasViyaApiClient.getJobsInFolder(jobKey) + const locJobs = await this.sasViyaApiClient.getJobsInFolder(folderPath) if (locJobs) { const job = locJobs.find( (el: any) => el.name === jobName && el.contentType === 'jobDefinition' @@ -1075,6 +1086,7 @@ export default class SASjs { uri = job.uri } } + console.log('URI', uri) return uri }