-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlabkey.getQueryLists.R
More file actions
96 lines (81 loc) · 3.04 KB
/
labkey.getQueryLists.R
File metadata and controls
96 lines (81 loc) · 3.04 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
##
# Copyright (c) 2010-2018 LabKey Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
## public function getQueries, returns all queries associated with a specified schema
labkey.getQueries <- function(baseUrl=NULL, folderPath, schemaName)
{
mydata <- getQueryLists(baseUrl=baseUrl, folderPath=folderPath, schemaName=schemaName)
return(mydata)
}
## public function getQueryViews, returns all views associated with a specified query
labkey.getQueryViews <- function(baseUrl=NULL, folderPath, schemaName, queryName)
{
if(is.null(queryName)==FALSE) {char <- nchar(queryName); if(char<1){queryName<-NULL}}
if(missing("queryName")) { stop ("You must provide the query on which the view is based.") }
mydata <- getQueryLists(baseUrl=baseUrl, folderPath=folderPath, schemaName=schemaName, queryName=queryName)
return(mydata)
}
getQueryLists <- function(baseUrl=NULL, folderPath, schemaName, queryName=NULL)
{
baseUrl=labkey.getBaseUrl(baseUrl)
## Validate required parameters
if (missing(folderPath)) stop (paste("A value must be specified for folderPath."))
if (missing(schemaName)) stop (paste("A value must be specified for schemaName."))
params <- list("schemaName"=schemaName, "apiVersion"="8.3")
## now setup the different columns for views vs queries
if (length(queryName)==0)
{
serverAction <- "getQueries.api"
queryObjType <- "queries"
columnNames <- c("queryName", "fieldName")
}
else
{
serverAction <- "getQueryViews.api"
params <- c(params, list("queryName"=queryName))
queryObjType <- "views"
columnNames <- c("viewName", "fieldName")
}
## Construct url
myurl <- labkey.buildURL(baseUrl, "query", serverAction, folderPath, params)
## Execute via our standard GET function
mydata <- labkey.get(myurl);
decode <- fromJSON(mydata, simplifyVector=FALSE, simplifyDataFrame=FALSE)
qs <- decode[[queryObjType]]
dmall <- matrix(nrow=0, ncol=2, byrow=TRUE)
if (length(qs)>0)
{
for (j in 1:length(qs))
{
dmq <- matrix(nrow=0, ncol=2, byrow=TRUE)
nc <- length(qs[[j]]$columns)
##special handling of the default view
objName <- qs[[j]][["name"]]
if (is.null(objName))
{
objName<- "<default view>"
}
for (k in 1:nc)
{
dmqrow<- matrix( cbind(objName, qs[[j]]$columns[[k]]$name),nrow=1, ncol=2, byrow=FALSE)
dmq<-rbind(dmq, dmqrow)
}
dmall <- rbind(dmall,dmq)
}
}
dfall <- as.data.frame(dmall, stringsAsFactors=FALSE)
colnames(dfall)<- columnNames
return(dfall)
}