R/handleProject.R

#
#  These functions handle user input for a project.  If its a character or numeric
#  then it assumes its a synapse entity id, downlods it and returns it.
#  If its not a valid id then it throws an error.
#  If its a project, then it tries to build the project in synapse if need be.
#  Both return the project.  There's no logic to test here that doesn't require
#  downloading something from synapse, so I won't build a unit test.
#

setMethod(
		f = "handleProject",
		signature = signature("character"),
		definition = function(project) {
			tmpProj <- project
			project <- try(getEntity(project),silent=TRUE)
			if(class(project) != "Project" & class(project) != "Folder"){
				# We could create the project for the user instead of stopping the session.  Requires more input
        # like a name, etc.
				stop("User provided project id ", tmpProj, " does not exist.\nPlease provide a valid Synapse ID or object of class project.")
			}
			return(project)
		}
)

setMethod(
		f = "handleProject",
		signature = signature("numeric"),
		definition = function(project) {
			handleProject( as.character( project ))
		}
)



setMethod(
		f = "handleProject",
		signature = signature("Project"),
		definition = function(project) {
			userProjectID <- propertyValue(project,"id")
			qryString <- sprintf("select * from project ")
			qryResult <- synapseQuery(qryString)		
			qry <- which(qryResult$project.id == userProjectID)
			if(length(qry) > 0) { 
				# Project exists
				project <- updateEntity(project)
			}else{
				# Project does not exist, so create it.
				project <- createEntity(project)
			}
			return(project)
		}
)


setMethod(
		f = "handleProject",
		signature = signature("NULL"),
		definition = function(project) {
			# We assume the user has supplied a file.
			return(NULL)
		}
)
Sage-Bionetworks/rSCR documentation built on May 9, 2019, 12:13 p.m.