diff BiodbConn.R @ 1:45e985cd8e9e draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8-dirty
author prog
date Tue, 31 Jan 2017 05:27:24 -0500
parents 3afe41d3e9e7
children
line wrap: on
line diff
--- a/BiodbConn.R	Mon Jul 11 09:12:03 2016 -0400
+++ b/BiodbConn.R	Tue Jan 31 05:27:24 2017 -0500
@@ -1,78 +1,80 @@
-if ( ! exists('BiodbConn')) { # Do not load again if already loaded
+#####################
+# CLASS DECLARATION #
+#####################
 
-	source(file.path('UrlRequestScheduler.R'), chdir = TRUE)
-	source('biodb-common.R')
+BiodbConn <- methods::setRefClass("BiodbConn", contains = "BiodbObject", fields = list( .debug = "logical" ))
 
-	#####################
-	# CLASS DECLARATION #
-	#####################
-	
-	BiodbConn <- setRefClass("BiodbConn", fields = list(.scheduler = "UrlRequestScheduler"))
+###############
+# CONSTRUCTOR #
+###############
 
-	###############
-	# CONSTRUCTOR #
-	###############
+BiodbConn$methods( initialize = function(debug = FALSE, ...) {
+	.debug <<- debug
+})
 
-	BiodbConn$methods( initialize = function(useragent = NA_character_, scheduler = NULL, ...) {
+#######################
+# PRINT DEBUG MESSAGE #
+#######################
 
-		# Check useragent
-		! is.null(useragent) && ! is.na(useragent) || stop("You must specify a valid useragent.")
+BiodbConn$methods( .print.debug.msg = function(msg) {
+	if (.self$.debug)
+		.print.msg(msg = msg, class = class(.self))
+})
+
+##########################
+# GET ENTRY CONTENT TYPE #
+##########################
 
-		# Set scheduler
-		if (is.null(scheduler))
-			scheduler <- UrlRequestScheduler$new(n = 3)
-		inherits(scheduler, "UrlRequestScheduler") || stop("The scheduler instance must inherit from UrlRequestScheduler class.")
-		scheduler$setUserAgent(useragent) # set agent
-		.scheduler <<- scheduler
-	
-		callSuper(...) # calls super-class initializer with remaining parameters
-	})
-	
-	######################
-	# HANDLES ENTRY TYPE #
-	######################
+BiodbConn$methods( getEntryContentType = function() {
+	.self$.abstract.method()
+})
 
-	BiodbConn$methods( handlesEntryType = function(type) {
-		return( ! is.null(.self$getEntryContentType(type)))
-	})
+#############
+# GET ENTRY #
+#############
+
+BiodbConn$methods( getEntry = function(id, drop = TRUE) {
+	content <- .self$getEntryContent(id)
+	return(.self$createEntry(content, drop = drop))
+})
 
-	##########################
-	# GET ENTRY CONTENT TYPE #
-	##########################
-
-	BiodbConn$methods( getEntryContentType = function(type) {
-		stop("Method getEntryContentType() is not implemented in concrete class.")
-	})
+#####################
+# GET ENTRY CONTENT #
+#####################
 
-	#############
-	# GET ENTRY #
-	#############
+# Download entry content from the public database.
+# type      The entry type.
+# id        The ID of the entry to get.
+# RETURN    An entry content downloaded from database.
+BiodbConn$methods( getEntryContent = function(id) {
+	.self$.abstract.method()
+})
 
-	BiodbConn$methods( getEntry = function(type, id, drop = TRUE) {
-		content <- .self$getEntryContent(type, id)
-		return(.self$createEntry(type, content, drop = drop))
-	})
+#############################
+# CREATE ENTRY FROM CONTENT #
+#############################
 
-	#####################
-	# GET ENTRY CONTENT #
-	#####################
-	
-	# Download entry content from the public database.
-	# type      The entry type.
-	# id        The ID of the enttry to get.
-	# RETURN    An entry content downloaded from database.
-	BiodbConn$methods( getEntryContent = function(type, id) {
-		stop("Method getCompound() is not implemented in concrete class.")
-	})
-	
-	#############################
-	# CREATE ENTRY FROM CONTENT #
-	#############################
-	
-	# Creates a Compound instance from file content.
-	# content       A file content, downloaded from the public database.
-	# RETURN        A compound instance.
-	BiodbConn$methods( createEntry = function(type, content, drop = TRUE) {
-		stop("Method createEntry() is not implemented in concrete class.")
-	})
-}
+# Creates a Compound instance from file content.
+# content       A file content, downloaded from the public database.
+# RETURN        A compound instance.
+BiodbConn$methods( createEntry = function(content, drop = TRUE) {
+	.self$.abstract.method()
+})
+
+#################
+# GET ENTRY IDS #
+#################
+
+# Get a list of IDs of all entries contained in this database.
+BiodbConn$methods( getEntryIds = function(max.results = NA_integer_) {
+	.self$.abstract.method()
+})
+
+##################
+# GET NB ENTRIES #
+##################
+
+# Get the number of entries contained in this database.
+BiodbConn$methods( getNbEntries = function() {
+	.self$.abstract.method()
+})