adds version parsing in data connector
This commit is contained in:
@@ -26,30 +26,54 @@
|
||||
server = parsedUrl[baseUrl],
|
||||
projectId = parsedUrl[projectId],
|
||||
modelId = parsedUrl[modelId],
|
||||
versionId = parsedUrl[versionId],
|
||||
|
||||
// get API key if available
|
||||
apiKey = try Extension.CurrentCredential()[Key] otherwise null,
|
||||
|
||||
// graphql query to get model info including root object id
|
||||
query = "query ($projectId: String!, $modelId: String!) {
|
||||
project(id: $projectId) {
|
||||
model(id: $modelId) {
|
||||
id
|
||||
name
|
||||
versions {
|
||||
items {
|
||||
// includes specific version if provided
|
||||
query = if versionId = null then
|
||||
"query ($projectId: String!, $modelId: String!) {
|
||||
project(id: $projectId) {
|
||||
model(id: $modelId) {
|
||||
id
|
||||
name
|
||||
versions {
|
||||
items {
|
||||
id
|
||||
referencedObject
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}"
|
||||
else
|
||||
"query ($projectId: String!, $modelId: String!, $versionId: String!) {
|
||||
project(id: $projectId) {
|
||||
model(id: $modelId) {
|
||||
id
|
||||
name
|
||||
version(id: $versionId) {
|
||||
id
|
||||
referencedObject
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}",
|
||||
}",
|
||||
|
||||
variables = [
|
||||
projectId = projectId,
|
||||
modelId = modelId
|
||||
],
|
||||
// include versionId in variables if it exists
|
||||
variables = if versionId = null then
|
||||
[
|
||||
projectId = projectId,
|
||||
modelId = modelId
|
||||
]
|
||||
else
|
||||
[
|
||||
projectId = projectId,
|
||||
modelId = modelId,
|
||||
versionId = versionId
|
||||
],
|
||||
|
||||
// make the api request
|
||||
Source = Web.Contents(
|
||||
@@ -71,17 +95,24 @@
|
||||
// parse the response
|
||||
JsonResponse = Json.Document(Source),
|
||||
|
||||
// extract needed information
|
||||
// extract needed information, now handling both version-specific and latest version cases
|
||||
result = if Record.HasFields(JsonResponse, {"errors"}) then
|
||||
error JsonResponse[errors]{0}[message]
|
||||
else if JsonResponse[data]?[project]?[model] = null then
|
||||
error "Model not found or access denied. Please check your authentication and model ID."
|
||||
else
|
||||
else if versionId = null then
|
||||
[
|
||||
modelId = JsonResponse[data][project][model][id],
|
||||
modelName = JsonResponse[data][project][model][name],
|
||||
versionId = JsonResponse[data][project][model][versions][items]{0}[id],
|
||||
rootObjectId = JsonResponse[data][project][model][versions][items]{0}[referencedObject]
|
||||
]
|
||||
else
|
||||
[
|
||||
modelId = JsonResponse[data][project][model][id],
|
||||
modelName = JsonResponse[data][project][model][name],
|
||||
versionId = JsonResponse[data][project][model][version][id],
|
||||
rootObjectId = JsonResponse[data][project][model][version][referencedObject]
|
||||
]
|
||||
in
|
||||
result
|
||||
@@ -4,6 +4,7 @@
|
||||
// import the parser function and getModel
|
||||
Parser = Extension.LoadFunction("Parser.pqm"),
|
||||
GetModel = Extension.LoadFunction("GetModel.pqm"),
|
||||
|
||||
// the logic for importing functions from other files
|
||||
Extension.LoadFunction = (fileName as text) =>
|
||||
let
|
||||
@@ -24,15 +25,22 @@
|
||||
// get parsed URL components and model info
|
||||
parsedUrl = Parser(url),
|
||||
server = parsedUrl[baseUrl],
|
||||
rootId = modelInfo[rootObjectId],
|
||||
modelInfo = GetModel(url),
|
||||
rootId = modelInfo[rootObjectId],
|
||||
versionId = modelInfo[versionId],
|
||||
|
||||
// get API key if available
|
||||
apiKey = try Extension.CurrentCredential()[Key] otherwise null,
|
||||
|
||||
// make the API request to objects endpoint
|
||||
// includes version ID in the path if it exists
|
||||
Source = Web.Contents(
|
||||
Text.Combine({server, "objects", parsedUrl[projectId], modelInfo[rootObjectId]}, "/"),
|
||||
Text.Combine({
|
||||
server,
|
||||
"objects",
|
||||
parsedUrl[projectId],
|
||||
modelInfo[rootObjectId]
|
||||
}, "/"),
|
||||
[
|
||||
Headers = [
|
||||
#"Authorization" = if apiKey = null then "" else Text.Format("Bearer #{0}", {apiKey})
|
||||
@@ -57,6 +65,7 @@
|
||||
FieldsToRemove = {"__closure", "totalChildrenCount", "renderMaterialProxies"},
|
||||
|
||||
// create the final table with cleaned data records
|
||||
// includes version ID in the output
|
||||
FinalTable = Table.FromRecords(
|
||||
List.Transform(
|
||||
TableFromList[Column1],
|
||||
@@ -68,16 +77,15 @@
|
||||
)
|
||||
in
|
||||
[
|
||||
#"Object IDs" = record[id], // Object IDs
|
||||
#"Speckle Type" = record[speckle_type], // Speckle Type
|
||||
#"Object IDs" = record[id],
|
||||
#"Speckle Type" = record[speckle_type],
|
||||
#"Viewer Data ID" = rootId,
|
||||
data = Record.RemoveFields(record, fieldsToRemoveForThisRecord) // Data
|
||||
data = Record.RemoveFields(record, fieldsToRemoveForThisRecord)
|
||||
]
|
||||
)
|
||||
),
|
||||
|
||||
// filter out rows where applicationId is null
|
||||
// we can discuss this further
|
||||
// filter out rows where applicationId is null -- to be discussed
|
||||
FilteredTable = Table.SelectRows(FinalTable, each Record.FieldOrDefault(([data]), "applicationId", null) <> null)
|
||||
in
|
||||
FilteredTable
|
||||
Reference in New Issue
Block a user