Skip to content

Commit

Permalink
small adjustments for functional tests (#2610)
Browse files Browse the repository at this point in the history
* fixed return types for functional tests

* redid the image

* reverted

* added support for annotator tests

* removed error if no organisms found

* fixed organism service tests

* removed adding owner to a deleted exon

* fixed update

* redid REST docs
  • Loading branch information
nathandunn committed Apr 21, 2021
1 parent 2f54601 commit 1a24955
Show file tree
Hide file tree
Showing 7 changed files with 1,411 additions and 1,263 deletions.
49 changes: 46 additions & 3 deletions grails-app/controllers/org/bbop/apollo/AnnotatorController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -846,23 +846,66 @@ class AnnotatorController {
render annotatorService.getAppState(params.get(FeatureStringEnum.CLIENT_TOKEN.value).toString()) as JSON
}

@RestApiMethod(description = "Update common path and return system info", path = "/updateCommonPath", verb = RestApiVerb.POST)
@RestApiParams(params =[
@RestApiParam(name = "username", type = "email", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "password", type = "password", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "directory", type = "string", paramType = RestApiParamType.QUERY, description = "Relative or absolute common path directory")
])
@Transactional
String updateCommonPath(String directory) {
log.debug "Updating the common path for ${directory}"
String updateCommonPath() {
JSONObject dataObject = permissionService.handleInput(request, params)
JSONObject returnObject = new JSONObject()
String directory = dataObject.directory

try {
if (!permissionService.hasGlobalPermissions(dataObject, GlobalPermissionEnum.ADMIN)) {
render status: HttpStatus.UNAUTHORIZED
return
}
String returnString = trackService.updateCommonDataDirectory(directory) as String
log.info "Returning common data directory ${returnString}"
if (returnString) {
returnObject.error = returnString
}
render getSystemInfo()
return
} catch (e) {
returnObject.error = e.getMessage()
}
render returnObject as JSON
}

@RestApiMethod(description = "Get system info", path = "/getSystemInfo", verb = RestApiVerb.POST)
@Transactional(readOnly = true )
String getSystemInfo() {
log.debug "Getting the common data path"
JSONObject returnObject = new JSONObject()

try {
String returnString = trackService.getCommonDataDirectory()
log.debug "Returning common data directory ${returnString}"
if (returnString) {
returnObject.error = returnString
}
File file = new File(returnString)
returnObject.put("relativePath",returnString)
returnObject.put("absolutePath",file.absolutePath)
returnObject.put("absolute",file.absolute)
returnObject.put("exists",file.exists())
returnObject.put("writable",file.canWrite())
returnObject.put("readable",file.canRead())
returnObject.put("directory",file.isDirectory())
returnObject.put("executable",file.canExecute())
returnObject.put("freeSpace",file.getFreeSpace())
returnObject.put("totalSpace",file.getTotalSpace())
returnObject.put("usableSpace",file.getUsableSpace())
returnObject.put("root",new File("").absolutePath)
returnObject.put("realPath",servletContext.getRealPath("/"))
} catch (e) {
returnObject.error = e.getMessage()
}
render returnObject as JSON
}
/**
*/
@Transactional
Expand Down
19 changes: 11 additions & 8 deletions grails-app/controllers/org/bbop/apollo/OrganismController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ class OrganismController {
File rawDirectory = new File(directory.absolutePath + "/seq")
assert rawDirectory.mkdir()
assert rawDirectory.setWritable(true)
File archiveFile = new File(rawDirectory.absolutePath + File.separator + organismName + "." + sequenceTypeEnum.suffix)
File archiveFile = new File(rawDirectory.absolutePath + File.separator + organismName + "." + sequenceTypeEnum.correctedSuffix)
sequenceDataFile.transferTo(archiveFile)
organism.directory = directory.absolutePath

String fastaPath = rawDirectory.absolutePath + File.separator + organismName + ".fa"
String fastaPath = rawDirectory.absolutePath + File.separator + organismName + "." + SequenceTypeEnum.FA.suffix
// decompress if need be
if (sequenceTypeEnum.compression != null) {
List<String> fileNames = fileService.decompress(archiveFile, rawDirectory.absolutePath)
Expand All @@ -380,10 +380,10 @@ class OrganismController {
oldFile.renameTo(newFile)
}

log.info "search db file : ${searchDatabaseDataFile.name} ${searchDatabaseDataFile.size} ${searchDatabaseDataFile.originalFilename} ${searchDatabaseDataFile.contentType}"


if (searchDatabaseDataFile != null && searchDatabaseDataFile.size > 0) {
log.info "search db file : ${searchDatabaseDataFile.name} ${searchDatabaseDataFile.size} ${searchDatabaseDataFile.originalFilename} ${searchDatabaseDataFile.contentType}"
File searchDirectory = new File(directory.absolutePath + "/search")
assert searchDirectory.mkdir()
assert searchDirectory.setWritable(true)
Expand Down Expand Up @@ -1565,11 +1565,12 @@ class OrganismController {
organismList = organismList.findAll{ o -> o.publicMode }
}

if (!organismList) {
def error = [error: 'Not authorized for any organisms']
render error as JSON
return
}
// should just return an empty array
// if (!organismList) {
// def error = [error: 'Not authorized for any organisms']
// render error as JSON
// return
// }

UserOrganismPreference userOrganismPreference = UserOrganismPreference.findByUserAndCurrentOrganism(permissionService.getCurrentUser(requestObject), true, [max: 1, sort: "lastUpdated", order: "desc"])
Long defaultOrganismId = userOrganismPreference ? userOrganismPreference.organism.id : null
Expand Down Expand Up @@ -1598,6 +1599,8 @@ class OrganismController {
id : organism.id,
commonName : organism.commonName,
blatdb : organism.blatdb,
genomeFasta : organism.genomeFasta,
genomeFastaIndex : organism.genomeFastaIndex,
directory : organism.directory,
annotationCount : annotationCount,
sequences : sequenceCount,
Expand Down
21 changes: 17 additions & 4 deletions grails-app/controllers/org/bbop/apollo/UserController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.bbop.apollo

import grails.converters.JSON
import grails.transaction.Transactional
import org.apache.shiro.authc.UsernamePasswordToken
import org.apache.shiro.crypto.hash.Sha256Hash
import org.bbop.apollo.gwt.shared.FeatureStringEnum
import org.bbop.apollo.gwt.shared.GlobalPermissionEnum
Expand Down Expand Up @@ -414,7 +413,14 @@ class UserController {

log.info "Added user ${user.username} with role ${role.name}"

render new JSONObject() as JSON
JSONObject jsonObject = user.properties
log.debug "json object ${jsonObject as JSON}"
jsonObject.email = user.username
jsonObject.username = user.username
jsonObject.id = user.id
jsonObject.userId = user.id
log.debug "rendering json object "
render jsonObject as JSON
} catch (e) {
log.error(e.fillInStackTrace())
JSONObject jsonObject = new JSONObject()
Expand Down Expand Up @@ -588,11 +594,18 @@ class UserController {
UserTrackPermission.deleteAll(UserTrackPermission.findAllByUser(user))
UserOrganismPermission.deleteAll(UserOrganismPermission.findAllByUser(user))
UserOrganismPreference.deleteAll(UserOrganismPreference.findAllByUser(user))
user.delete(flush: true)

log.info "Removed user ${user.username}"

render new JSONObject() as JSON
JSONObject jsonObject = user.properties
log.debug "json object ${jsonObject as JSON}"
jsonObject.email = user.username
jsonObject.username = user.username
jsonObject.id = user.id
jsonObject.userId = user.id
log.debug "rendering json object "
render jsonObject as JSON
user.delete(flush: true)
} catch (e) {
log.error(e.fillInStackTrace())
JSONObject jsonObject = new JSONObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1979,9 +1979,7 @@ class RequestHandlingService {
JSONObject jsonExon = features.getJSONObject(i)
Exon exon = Exon.findByUniqueName(jsonExon.getString(FeatureStringEnum.UNIQUENAME.value));
checkOwnersDelete(exon, inputObject)

exonService.deleteExon(transcript, exon);
featureService.addOwnersByString(inputObject.username, exon)
}
def transcriptsToUpdate = featureService.handleDynamicIsoformOverlap(transcript)
if (transcriptsToUpdate.size() > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/gwt/org/bbop/apollo/gwt/shared/FeatureStringEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public enum FeatureStringEnum {
SYNONYMS,
STRUCTURAL_EDIT,
HIGHLIGHTED_REGION("highlighted region"),
UNIQUENAME,
UNIQUENAME("uniquename"),
// TODO: move these to a SequenceTypeEnum
TYPE_PEPTIDE("peptide"),
TYPE_CDS("cds"),
Expand Down
13 changes: 11 additions & 2 deletions src/gwt/org/bbop/apollo/gwt/shared/track/SequenceTypeEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
public enum SequenceTypeEnum {

FA("fa"),
FASTA("fasta"),
FNA("fna"),
FA_GZ("fa.gz","gz"),
FASTA_GZ("fasta.gz","gz"),
FNA_GZ("fna.gz","gz"),
FA_ZIP("fa.zip","zip"),
FASTA_ZIP("fasta.zip","zip"),
FNA_ZIP("fna.zip","zip"),
FA_TGZ("fa.tgz","tar.gz"),
FASTA_TGZ("fasta.tgz","tar.gz"),
FNA_TGZ("fna.tgz","tar.gz"),
FA_TAR_GZ("fa.tar.gz","tar.gz"),
FASTA_TAR_GZ("fasta.tar.gz","tar.gz"),
FNA_TAR_GZ("fna.tar.gz","tar.gz");

private String suffix ;
private String compression;
private final String suffix ;
private final String compression;

SequenceTypeEnum(String suffix){
this(suffix,null);
Expand All @@ -34,6 +39,10 @@ public String getCompression() {
return compression;
}

public String getCorrectedSuffix(){
return FA.suffix + (compression!=null ? "." + compression : "") ;
}

public static SequenceTypeEnum getSequenceTypeForFile(String fileName){
for(SequenceTypeEnum sequenceTypeEnum : values()){
if(fileName.endsWith(sequenceTypeEnum.suffix)){
Expand Down

0 comments on commit 1a24955

Please sign in to comment.