-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.R
More file actions
61 lines (52 loc) · 1.57 KB
/
utils.R
File metadata and controls
61 lines (52 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
library(tercenApi)
upload_file_to_folder <- function(file_path, ctx, filename, output_folder, output_folder_id) {
project <- ctx$client$projectService$get(ctx$schema$projectId)
folder <- NULL
if (!is.null(output_folder_id)) {
folder <- ctx$client$folderService$get(id = output_folder_id)
} else if (output_folder != "") {
folder <- ctx$client$folderService$getOrCreate(project$id, output_folder)
}
bytes <- readBin(file_path, what = "raw", n = file.info(file_path)$size)
fileDoc <- FileDocument$new()
fileDoc$name <- filename
fileDoc$projectId <- project$id
fileDoc$acl$owner <- project$acl$owner
if (!is.null(folder)) fileDoc$folderId <- folder$id
ctx$client$fileService$upload(fileDoc, bytes)
return(NULL)
}
get_workflow_id <- function(ctx) {
if (is.null(ctx$task)) {
return(ctx$workflowId)
} else {
workflowIdPair <-
Find(function(pair)
identical(pair$key, "workflow.id"),
ctx$task$environment)
workflowId <- workflowIdPair$value
return(workflowId)
}
}
get_step_id <- function(ctx) {
if (is.null(ctx$task)) {
return(ctx$stepId)
} else {
stepIdPair <-
Find(function(pair)
identical(pair$key, "step.id"),
ctx$task$environment)
stepId <- stepIdPair$value
return(stepId)
}
}
get_names <- function(ctx) {
wf <- ctx$client$workflowService$get(get_workflow_id(ctx))
ds <-
Find(function(s)
identical(s$id, get_step_id(ctx)), wf$steps)
grp <-
Find(function(s)
identical(s$id, ds$groupId), wf$steps)
return(list(WF = wf$name, DS = ds$name, GRP = grp$name))
}