[ARVADOS] updated: 1.1.1-172-gc886439
Git user
git at public.curoverse.com
Thu Dec 7 10:41:36 EST 2017
Summary of changes:
sdk/R/.RData | Bin 140128 -> 162592 bytes
sdk/R/R/ArvadosFile.R | 3 +-
sdk/R/R/Collection.R | 88 ++++++++++++++++++++++++++++++++----------------
sdk/R/R/Subcollection.R | 5 +--
4 files changed, 64 insertions(+), 32 deletions(-)
via c88643983aeb511eca21e1d9e36b919a63482fb8 (commit)
from c1d564b0e5f95c54d822d39cf1715d93d293c70b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit c88643983aeb511eca21e1d9e36b919a63482fb8
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date: Thu Dec 7 16:38:57 2017 +0100
Added ability to extract Subcollection from collection content tree.
Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic at capeannenterprises.com>
diff --git a/sdk/R/.RData b/sdk/R/.RData
index 8695f3f..626630b 100644
Binary files a/sdk/R/.RData and b/sdk/R/.RData differ
diff --git a/sdk/R/R/ArvadosFile.R b/sdk/R/R/ArvadosFile.R
index ab9938a..45aee1e 100644
--- a/sdk/R/R/ArvadosFile.R
+++ b/sdk/R/R/ArvadosFile.R
@@ -9,7 +9,8 @@
ArvadosFile <- setRefClass(
"ArvadosFile",
fields = list(
- name = "character"
+ name = "character",
+ relativePath = "character"
),
methods = list(
initialize = function(subcollectionName)
diff --git a/sdk/R/R/Collection.R b/sdk/R/R/Collection.R
index 9a0cdfd..e261a25 100644
--- a/sdk/R/R/Collection.R
+++ b/sdk/R/R/Collection.R
@@ -59,7 +59,8 @@ Collection <- setRefClass(
trash_at = "ANY",
is_trashed = "ANY",
- getCollectionContent = "function"
+ getCollectionContent = "function",
+ get = "function"
),
methods = list(
@@ -90,7 +91,8 @@ Collection <- setRefClass(
trash_at <<- result$trash_at
is_trashed <<- result$is_trashed
- # Private methods
+ # Public methods
+
getCollectionContent <<- function()
{
#TODO(Fudo): Use proper URL here.
@@ -107,47 +109,75 @@ Collection <- setRefClass(
HttpParser()$parseWebDAVResponse(response, uri)
}
- createCollectionContentTree <- function(fileStructure)
+ get <<- function(pathToTheFile)
{
- #Todo(Fudo): Refactor this.
- treeBranches <- sapply(fileStructure, function(filePath)
+ fileWithPath <- unlist(stringr::str_split(pathToTheFile, "/"))
+ fileWithPath <- fileWithPath[fileWithPath != ""]
+
+ findFileIfExists <- function(name, node)
+ {
+ matchPosition <- match(name, sapply(node$content, function(nodeInSubcollection) {nodeInSubcollection$name}), -1)
+ if(matchPosition != -1)
+ {
+ return(node$content[[matchPosition]])
+ }
+ else
+ {
+ return(NULL)
+ }
+ }
+
+ nodeToCheck = .self$items
+ for(fileNameIndex in 1:length(fileWithPath))
{
- fileWithPath <- unlist(stringr::str_split(filePath, "/"))
+ nodeToCheck <- findFileIfExists(fileWithPath[fileNameIndex], nodeToCheck)
+ if(is.null(nodeToCheck))
+ stop("File or folder you asked for is not part of the collection.")
+ }
+ nodeToCheck
+ }
+
+
+ # Private methods
+ .createCollectionContentTree <- function(fileStructure)
+ {
+ #TODO(Fudo): Refactot this.
+ treeBranches <- sapply(fileStructure, function(filePath)
+ {
+ fileWithPath <- unlist(str_split(filePath, "/"))
file <- fileWithPath[length(fileWithPath), drop = T]
- file <- ArvadosFile(file)
+
+ if(file != "")
+ {
+ file <- ArvadosFile(file)
+ file$relativePath <- filePath
+ }
+ else
+ {
+ file <- NULL
+ }
folders <- fileWithPath[-length(fileWithPath)]
subcollections <- sapply(folders, function(folder)
{
folder <- Subcollection(folder)
+ unname(folder)
})
- if(length(subcollections) > 0)
- {
- bottomFolder <- subcollections[[length(subcollections)]]
- bottomFolder$add(file)
+ if(!is.null(file))
+ subcollections <- c(subcollections, file)
- if(length(subcollections) == 1)
- {
- return(bottomFolder)
- }
- else
+ if(length(subcollections) > 1)
+ {
+ for(subcollectionIndex in 1:(length(subcollections) - 1))
{
- # Link folders in hierarchy. At the bottom will always be a file.
- for(subcollectionIndex in 1:(length(subcollections) - 1))
- {
- subcollections[[subcollectionIndex]]$add(subcollections[[subcollectionIndex + 1]])
- }
-
- subcollections[[1]]
+ subcollections[[subcollectionIndex]]$relativePath <- paste(folders[1:(subcollectionIndex)], collapse = "/")
+ subcollections[[subcollectionIndex]]$add(subcollections[[subcollectionIndex + 1]])
}
}
- else
- {
- file
- }
+ subcollections[[1]]
})
root <- Subcollection(".")
@@ -181,13 +211,13 @@ Collection <- setRefClass(
}
#Todo(Fudo): This is dummy data. Real content will come from WebDAV server.
- testFileStructure <- c("math.h", "main.cpp",
+ testFileStructure <- c("math.h", "main.cpp", "emptyFolder/",
"java/render.java", "java/test/observer.java",
"java/test/observable.java",
"csharp/this.cs", "csharp/is.cs",
"csharp/dummy.cs", "csharp/file.cs")
#items <<- getCollectionContent()
- items <<- createCollectionContentTree(testFileStructure)
+ items <<- .createCollectionContentTree(testFileStructure)
}
)
)
diff --git a/sdk/R/R/Subcollection.R b/sdk/R/R/Subcollection.R
index e4b132b..bc986bb 100644
--- a/sdk/R/R/Subcollection.R
+++ b/sdk/R/R/Subcollection.R
@@ -9,8 +9,9 @@
Subcollection <- setRefClass(
"Subcollection",
fields = list(
- name = "character",
- content = "list"
+ name = "character",
+ relativePath = "character",
+ content = "list"
),
methods = list(
initialize = function(subcollectionName)
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list