Implemented custom print functions for all public classes
authorFuad Muhic <fmuhic@capeannenterprises.com>
Mon, 29 Jan 2018 11:33:49 +0000 (12:33 +0100)
committerFuad Muhic <fmuhic@capeannenterprises.com>
Mon, 29 Jan 2018 11:33:49 +0000 (12:33 +0100)
Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic@capeannenterprises.com>

sdk/R/NAMESPACE
sdk/R/R/Arvados.R
sdk/R/R/ArvadosFile.R
sdk/R/R/Collection.R
sdk/R/R/CollectionTree.R
sdk/R/R/Subcollection.R
sdk/R/R/util.R
sdk/R/README
sdk/R/tests/testthat/test-Collection.R
sdk/R/tests/testthat/test-HttpRequest.R

index 1c94e716bfd03321b8909feb8559c0cf42addee4..d4c143cdba9ce424908873433b3517496209a340 100644 (file)
@@ -3,5 +3,8 @@
 export(Arvados)
 export(ArvadosFile)
 export(Collection)
-export(CollectionTree)
 export(Subcollection)
+export(print.Arvados)
+export(print.ArvadosFile)
+export(print.Collection)
+export(print.Subcollection)
index 18b42f6df2cae4824c36b44c8d526cb4519eb919..b21c6046356b1eb73503a4cd846ed4cd43b81312 100644 (file)
@@ -165,3 +165,11 @@ Arvados <- R6::R6Class(
 
     cloneable = FALSE
 )
+
+#' @export print.Arvados
+print.Arvados = function(arvados)
+{
+    cat(paste0("Type:  ", "\"", "Arvados", "\""), sep = "\n")
+    cat(paste0("Host:  ", "\"", arvados$getHostName(), "\""), sep = "\n")
+    cat(paste0("Token: ", "\"", arvados$getToken(), "\"") , sep = "\n")
+}
index ffb9a6b848727c1ef81322b610210e1c3f6c30e6..7ffcb294183c55c6216f396cdce1995153cb0058 100644 (file)
@@ -202,3 +202,21 @@ ArvadosFile <- R6::R6Class(
 
     cloneable = FALSE
 )
+
+#' @export print.ArvadosFile
+print.ArvadosFile = function(arvadosFile)
+{
+    collection   <- NULL
+    relativePath <- arvadosFile$getRelativePath()
+
+    if(!is.null(arvadosFile$getCollection()))
+    {
+        collection <- arvadosFile$getCollection()$uuid
+        relativePath <- paste0("/", relativePath)
+    }
+
+    cat(paste0("Type:          ", "\"", "ArvadosFile", "\""), sep = "\n")
+    cat(paste0("Name:          ", "\"", arvadosFile$getName(), "\""), sep = "\n")
+    cat(paste0("Relative path: ", "\"", relativePath, "\"") , sep = "\n")
+    cat(paste0("Collection:    ", "\"", collection, "\""), sep = "\n")
+}
index 8d49cd0decbf8cdcd93473ba11b8cf9ddfc97c2a..210762043526396446f9cf92e389e54ddf43f392 100644 (file)
@@ -50,7 +50,6 @@ Collection <- R6::R6Class(
                "Subcollection" %in% class(content))
             {
                 subcollection$add(content)
-
                 content
             }
             else
@@ -137,7 +136,7 @@ Collection <- R6::R6Class(
             elementToMove <- self$get(content)
 
             if(is.null(elementToMove))
-                stop("Element you want to move doesn't exist in the collection.")
+                stop("Content you want to move doesn't exist in the collection.")
 
             elementToMove$move(newLocation)
         },
@@ -161,18 +160,15 @@ Collection <- R6::R6Class(
 
         REST        = NULL,
         tree        = NULL,
-        fileContent = NULL,
-
-        generateTree = function(content)
-        {
-            treeBranches <- sapply(collectionContent, function(filePath)
-            {
-                splitPath <- unlist(strsplit(filePath$name, "/", fixed = TRUE))
-
-                branch = private$createBranch(splitPath, filePath$fileSize)      
-            })
-        }
+        fileContent = NULL
     ),
 
     cloneable = FALSE
 )
+
+#' @export print.Collection
+print.Collection = function(collection)
+{
+    cat(paste0("Type: ", "\"", "Arvados Collection", "\""), sep = "\n")
+    cat(paste0("uuid: ", "\"", collection$uuid, "\""), sep = "\n")
+}
index fcc5dbece5727a35656700169130677af744158d..4194be95dd46e343b02abb4708f781acf1beef8f 100644 (file)
@@ -7,7 +7,6 @@ source("./R/util.R")
 #' Update description
 #'
 #' @examples arv = Collection$new(api, uuid)
-#' @export CollectionTree
 CollectionTree <- R6::R6Class(
     "CollectionTree",
     public = list(
@@ -96,8 +95,8 @@ CollectionTree <- R6::R6Class(
             }
             else
             {
-                # Note: REST always returns folder name alone before other folder content
-                # (for some reason), so in first iteration we don't know if it's a file
+                # Note: REST always returns folder name alone before other folder 
+                # content, so in first iteration we don't know if it's a file
                 # or folder since its just a name, so we assume it's a file. 
                 # If we encounter that same name again we know 
                 # it's a folder so we need to replace ArvadosFile with Subcollection.
index a1f83f51bf81213531df7679e68736443b21ccfc..7eb4381edaa151b2ef1053a78c039dfd7af4150d 100644 (file)
@@ -13,7 +13,7 @@ Subcollection <- R6::R6Class(
 
         initialize = function(name)
         {
-            private$name       <- name
+            private$name <- name
         },
 
         getName = function() private$name,
@@ -101,21 +101,7 @@ Subcollection <- R6::R6Class(
 
         getFileListing = function(fullPath = TRUE)
         {
-            content <- NULL
-
-            if(fullPath)
-            {
-                for(child in private$children)
-                    content <- c(content, child$getFileListing())
-
-                if(private$name != "")
-                    content <- unlist(paste0(private$name, "/", content))
-            }
-            else
-            {
-                for(child in private$children)
-                    content <- c(content, child$getName())
-            }
+            content <- private$getContentAsCharVector(fullPath)
 
             content[order(tolower(content))]
         },
@@ -250,8 +236,50 @@ Subcollection <- R6::R6Class(
             parent$remove(private$name)
 
             parent$setCollection(parentsCollection, setRecursively = FALSE)
+        },
+
+        getContentAsCharVector = function(fullPath = TRUE)
+        {
+            content <- NULL
+
+            if(fullPath)
+            {
+                for(child in private$children)
+                    content <- c(content, child$getFileListing())
+
+                if(private$name != "")
+                    content <- unlist(paste0(private$name, "/", content))
+            }
+            else
+            {
+                for(child in private$children)
+                    content <- c(content, child$getName())
+            }
+
+            content
+
         }
     ),
     
     cloneable = FALSE
 )
+
+#' @export print.Subcollection
+print.Subcollection = function(subCollection)
+{
+    collection   <- NULL
+    relativePath <- subCollection$getRelativePath()
+
+    if(!is.null(subCollection$getCollection()))
+    {
+        collection <- subCollection$getCollection()$uuid
+
+        if(!subCollection$getName() == "")
+            relativePath <- paste0("/", relativePath)
+    }
+
+    cat(paste0("Type:          ", "\"", "Arvados Subcollection", "\""), sep = "\n")
+    cat(paste0("Name:          ", "\"", subCollection$getName(), "\""), sep = "\n")
+    cat(paste0("Relative path: ", "\"", relativePath, "\"") , sep = "\n")
+    cat(paste0("Collection:    ", "\"", collection, "\""), sep = "\n")
+}
index 65b5a4e52f8da088e3236d2bb44f362e5eb4e9d2..d9af8b057bbb00b42611894fe2186aa6f87b0caf 100644 (file)
@@ -49,6 +49,6 @@ splitToPathAndName = function(path)
     nameAndPath$name <- components[length(components)]
     nameAndPath$path <- trimFromStart(paste0(components[-length(components)], collapse = "/"),
                                       "/")
-    
+
     nameAndPath
 }
index 6b8cd3f46dc63aff7ce6df4c71f2b60413ad687b..8a0c31dce6131ec30dc8f1d66fbc00b7b4531aa7 100644 (file)
@@ -57,7 +57,7 @@ deletedCollection <- arv$deleteCollection("uuid")
 
 #Update a collection's metadata:
 
-updatedCollection <- arv$updateCollection("uuid", list(name = "My new name", description = "a brand new description"))
+updatedCollection <- arv$updateCollection("uuid", list(name = "New name", description = "New description"))
 
 --------------------------------------------------------------------------------------------------------------------------------
 
@@ -189,7 +189,7 @@ file$move("newDestination/file.cpp")
 subcollection <- collection$get("location/to/folder")
 subcollection$move("newDestination/folder")
 
-#Make sure to include file name in new destination
+#Make sure to include new file name in destination
 #In second example file$move("newDestination/") will not work
 
 --------------------------------------------------------------------------------------------------------------------------------
index 0c45958ba97e4401caa623560c2a93499b350b77..63a402dba4e358045c4e0f75de0272d19679ece4 100644 (file)
@@ -215,7 +215,7 @@ test_that("move raises exception if new location is not valid", {
     collection <- Collection$new(api, "myUUID")
 
     expect_that(collection$move("fish", "object"),
-                throws_error("Element you want to move doesn't exist in the collection.",
+                throws_error("Content you want to move doesn't exist in the collection.",
                              fixed = TRUE))
 })
 
index 427ec346cd72cd2545eb8ee5a46e91136a679fe9..e85037465b50012051827b83a9d3f4f45f929c60 100644 (file)
@@ -1,4 +1,4 @@
-context("Http Parser")
+context("Http Request")
 
 
 test_that(paste("createQuery generates and encodes query portion of http",