Skip to content

Commit

Permalink
Merge 8c74173 into 57a1f2e
Browse files Browse the repository at this point in the history
  • Loading branch information
nathandunn committed Oct 30, 2019
2 parents 57a1f2e + 8c74173 commit e61cf4e
Show file tree
Hide file tree
Showing 2 changed files with 1,314 additions and 1,288 deletions.
35 changes: 26 additions & 9 deletions grails-app/controllers/org/bbop/apollo/OrganismController.groovy
Expand Up @@ -50,7 +50,7 @@ class OrganismController {
@RestApiParams(params = [
@RestApiParam(name = "username", type = "email", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "password", type = "password", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "organism", type = "json", paramType = RestApiParamType.QUERY, description = "Pass an Organism JSON object with an 'id' that corresponds to the organism to be removed")
, @RestApiParam(name = "id", type = "string", paramType = RestApiParamType.QUERY, description = "Pass an Organism database `id` or `commonName` that corresponds to the organism to be removed")
])
@Transactional
def deleteOrganism() {
Expand All @@ -59,10 +59,18 @@ class OrganismController {
JSONObject organismJson = permissionService.handleInput(request, params)
log.debug "deleteOrganism ${organismJson}"
//if (permissionService.isUserBetterOrEqualRank(currentUser, GlobalPermissionEnum.INSTRUCTOR)){
log.debug "organism ID: ${organismJson.id} vs ${organismJson.organism}"
Organism organism = Organism.findById(organismJson.id as Long) ?: Organism.findByCommonName(organismJson.organism)
log.debug "organism ID: ${organismJson.id}"
// backporting a bug here:
Organism organism = Organism.findByCommonName(organismJson.id as String)
if(!organism){
organism = Organism.findById(organismJson.id as Long)
}
// backport a bug so that it doesn't break existing code
if(!organism){
organism = Organism.findByCommonName(organismJson.organism as String)
}
if (!organism) {
def error = [error: "Organism ${organismJson.organism} not found"]
def error = [error: "Organism ${organismJson.id} not found"]
log.error(error.error)
render error as JSON
return
Expand Down Expand Up @@ -104,19 +112,25 @@ class OrganismController {
@RestApiParam(name = "username", type = "email", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "password", type = "password", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "organism", type = "string", paramType = RestApiParamType.QUERY, description = "ID or commonName that can be used to uniquely identify an organism")
, @RestApiParam(name = "id", type = "string", paramType = RestApiParamType.QUERY, description = "ID or commonName that can be used to uniquely identify an organism")
])
@Transactional
def deleteOrganismWithSequence() {

JSONObject requestObject = permissionService.handleInput(request, params)
JSONObject responseObject = new JSONObject()
log.debug "deleteOrganism ${requestObject}"
log.debug "deleteOrganismWithSequence ${requestObject}"

try {
//if (permissionService.isUserGlobalAdmin(permissionService.getCurrentUser(requestObject))) {
// use hasGolbalPermssions instead, which can validate the authentication
if (permissionService.hasGlobalPermissions(requestObject, GlobalPermissionEnum.ADMIN)) {
Organism organism = preferenceService.getOrganismForTokenInDB(requestObject.organism)
println "found organism to remove ${organism} from ${requestObject.organism}"
if(!organism){
organism = preferenceService.getOrganismForTokenInDB(requestObject.id)
println "found organism to remove ${organism} from ${requestObject.id}"
}
if (organism) {
boolean dataAddedViaWebServices = organism.dataAddedViaWebServices == null ? false : organism.dataAddedViaWebServices
String organismDirectory = organism.directory
Expand Down Expand Up @@ -1249,6 +1263,7 @@ class OrganismController {
, @RestApiParam(name = "nonDefaultTranslationTable", type = "string", paramType = RestApiParamType.QUERY, description = "non-default translation table")
, @RestApiParam(name = "metadata", type = "string", paramType = RestApiParamType.QUERY, description = "organism metadata")
, @RestApiParam(name = "organismData", type = "file", paramType = RestApiParamType.QUERY, description = "zip or tar.gz compressed data directory (if other options not used). Blat data should include a .2bit suffix and be in a directory 'searchDatabaseData'")
, @RestApiParam(name = "noReloadSequences", type = "boolean", paramType = RestApiParamType.QUERY, description = "(default false) If set to true, then sequences will not be reloaded if the organism directory changes.")
])
@Transactional
def updateOrganismInfo() {
Expand All @@ -1257,6 +1272,7 @@ class OrganismController {
permissionService.checkPermissions(organismJson, PermissionEnum.ADMINISTRATE)
Organism organism = Organism.findById(organismJson.id)
Boolean madeObsolete
Boolean doReloadIfOrganismChanges = organismJson.noReloadSequences ? Boolean.valueOf(organismJson.noReloadSequences as String) : false
if (organism) {
String oldOrganismDirectory = organism.directory

Expand All @@ -1267,9 +1283,9 @@ class OrganismController {
//if the organismJson.metadata is null, remain the old metadata
organism.metadata = organismJson.metadata ? organismJson.metadata.toString() : organism.metadata
organism.directory = organismJson.directory ?: organism.directory
organism.publicMode = organismJson.publicMode ?: false
madeObsolete = !organism.obsolete && organismJson.obsolete
organism.obsolete = organismJson.obsolete ?: false
organism.publicMode = organismJson.containsKey("publicMode") ? Boolean.valueOf(organismJson.publicMode as String) : false
madeObsolete = !organism.obsolete && (organismJson.containsKey("obsolete") ? Boolean.valueOf(organismJson.obsolete as String) : false)
organism.obsolete = organismJson.containsKey("obsolete") ? Boolean.valueOf(organismJson.obsolete as String) : false
organism.nonDefaultTranslationTable = organismJson.nonDefaultTranslationTable ?: organism.nonDefaultTranslationTable
if (organism.genomeFasta) {
// update location of genome fasta
Expand Down Expand Up @@ -1306,7 +1322,8 @@ class OrganismController {
permissionService.removeAllPermissions(organism)
}
organism.save(flush: true, insert: false, failOnError: true)
if (oldOrganismDirectory!=organism.directory) {

if (oldOrganismDirectory!=organism.directory && !doReloadIfOrganismChanges) {
// we need to reload
sequenceService.loadRefSeqs(organism)
}
Expand Down

0 comments on commit e61cf4e

Please sign in to comment.