1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-03 10:40:06 +00:00

feat(job-execution): support absolute job paths for JES and web approaches

This commit is contained in:
Krishna Acondy
2020-09-18 09:24:33 +01:00
parent 3a60e6422c
commit 5076ea696c
2 changed files with 31 additions and 15 deletions

View File

@@ -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(

View File

@@ -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
}