Skip to content

Commit

Permalink
should fix filtering of statuses (#2543)
Browse files Browse the repository at this point in the history
* should fix filtering of statuses

* udpated change log

* cleaned up

* added get recent

* updated the rest apidoc
  • Loading branch information
nathandunn committed Dec 9, 2020
1 parent 5db4e4d commit d0d5396
Show file tree
Hide file tree
Showing 7 changed files with 1,772 additions and 1,739 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Features
- Added the ability to sync the gene and transcript name with the click of a button [2519](https://github.com/GMOD/Apollo/issues/2519).
- Added organism and species to menus [2537](https://github.com/GMOD/Apollo/pull/2537).
- Added UUID lookup and link [2539](https://github.com/GMOD/Apollo/pull/2539/).
- Added status filter for recent annotations [2543](https://github.com/GMOD/Apollo/pull/2543/).

Bug Fixes

Expand Down
9 changes: 6 additions & 3 deletions docs/web_services/examples/shell/getRecent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ url=$1
username=$2
password=$3
days=$4
status=$5

usage() {
echo "Sample script for exporting features from organism as GFF3 via web services"
echo "Usage: ./getRecent.sh <complete_apollo_URL> <username> <password> <days>"
echo "Usage: ./getRecent.sh <complete_apollo_URL> <username> <password> <days> <status>"
echo "Example: ./getRecent.sh http://localhost:8080/apollo demo demo Finished|InProgress"
echo "Example: ./getRecent.sh http://localhost:8080/apollo demo demo None"
echo "Example: ./getRecent.sh http://localhost:8080/apollo demo demo "
}

Expand All @@ -16,6 +19,6 @@ if [[ ! -n "$url" || ! -n "$username" || ! -n "$password" || ! -n "$days" ]]; th
exit
fi

echo curl "${url}/annotationEditor/getRecentAnnotations" -H 'Content-Type: application/json' --data "{'days':${days}, 'username': '${username}', 'password': '${password}'}"
curl "${url}/annotationEditor/getRecentAnnotations" -H 'Content-Type: application/json' --data "{'days':${days}, 'username': '${username}', 'password': '${password}'}"
echo curl "${url}/annotationEditor/getRecentAnnotations" -H 'Content-Type: application/json' --data "{'days':${days}, 'username': '${username}', 'password': '${password}', 'status':'${status}'}"
curl "${url}/annotationEditor/getRecentAnnotations" -H 'Content-Type: application/json' --data "{'days':${days}, 'username': '${username}', 'password': '${password}', 'status':'${status}'}"

Original file line number Diff line number Diff line change
Expand Up @@ -1222,10 +1222,10 @@ class AnnotationEditorController extends AbstractApolloController implements Ann

@RestApiMethod(description = "Get genes created or updated in the past, Returns JSON hash gene_name:organism", path = "/annotationEditor/getRecentAnnotations", verb = RestApiVerb.POST)
@RestApiParams(params = [
@RestApiParam(name = "username", type = "email", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "password", type = "password", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "days", type = "Integer", paramType = RestApiParamType.QUERY, description = "Number of past days to retrieve annotations from.")

@RestApiParam(name = "username", type = "email", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "password", type = "password", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "days", type = "Integer", paramType = RestApiParamType.QUERY, description = "(Required) Number of past days to retrieve annotations from.")
, @RestApiParam(name = "status", type = "String", paramType = RestApiParamType.QUERY, description = "(optional: default allow all) Pipe-separated list of filters (e.g., 'Finished|Published'). Use 'None' if you want annotations without a status. ")
])

def getRecentAnnotations() {
Expand All @@ -1236,7 +1236,8 @@ class AnnotationEditorController extends AbstractApolloController implements Ann
}

if (inputObject.get('days') instanceof Integer) {
JsonBuilder updatedGenes = annotationEditorService.recentAnnotations(inputObject.get('days'))
String filterString = inputObject.containsKey(FeatureStringEnum.STATUS.value) ? inputObject.getString(FeatureStringEnum.STATUS.value) : null
JsonBuilder updatedGenes = annotationEditorService.recentAnnotations(inputObject.getInt('days'),filterString)
render updatedGenes
} else {
def error = [error: inputObject.get('days') + ' Param days must be an Integer']
Expand Down
69 changes: 44 additions & 25 deletions grails-app/services/org/bbop/apollo/AnnotationEditorService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,56 @@ package org.bbop.apollo

import grails.transaction.NotTransactional
import grails.transaction.Transactional
import static java.util.Calendar.YEAR
import groovy.json.JsonBuilder

@Transactional
class AnnotationEditorService {


@NotTransactional
String cleanJSONString(String inputString){
String outputString = new String(inputString)
// remove leading string
outputString = outputString.indexOf("\"")==0 ? outputString.substring(1) : outputString
outputString = outputString.lastIndexOf("\"")==outputString.length()-1 ? outputString.substring(0,outputString.length()-1) : outputString
// outputString = outputString.replaceAll("/\\\\/","")
outputString = outputString.replaceAll("\\\\\"","\"")
outputString = outputString.replaceAll("\\\\\"","'")
return outputString
@NotTransactional
String cleanJSONString(String inputString) {
String outputString = new String(inputString)
// remove leading string
outputString = outputString.indexOf("\"") == 0 ? outputString.substring(1) : outputString
outputString = outputString.lastIndexOf("\"") == outputString.length() - 1 ? outputString.substring(0, outputString.length() - 1) : outputString
outputString = outputString.replaceAll("\\\\\"", "\"")
outputString = outputString.replaceAll("\\\\\"", "'")
return outputString
}

JsonBuilder recentAnnotations(Integer days, String statusFilter = null) {
Date today = new Date()
Date fromDate = today - days
List updatedGenes
if (statusFilter == null) {
updatedGenes = Gene.findAllByLastUpdatedGreaterThan(fromDate)
}
else
if (statusFilter.toLowerCase() == "none") {
updatedGenes = Gene.findAllByLastUpdatedGreaterThanAndStatusIsNull(fromDate)
} else {
List<String> statusFilterStringList = statusFilter.split("\\|")
List<Status> statusList = []
for(def statusString in statusFilterStringList){
Status status = Status.findByValue(statusString)
if(status) {
statusList.add(status)
}
else{
throw new RuntimeException("Status ${statusString} not found.")
}
}
updatedGenes = Gene.findAllByLastUpdatedGreaterThanAndStatusInList(fromDate, statusList)
}


Map geneToSpecies = [:]
updatedGenes.each { gene ->
geneToSpecies[gene.uniqueName] = gene.getFeatureLocation().sequence.organism.commonName
}

JsonBuilder recentAnnotations(Integer days=1){
Date today = new Date()
Date fromDate = today - days
List updatedGenes = Gene.findAllByLastUpdatedGreaterThan(fromDate)

Map geneToSpecies = [ : ]
updatedGenes.each { gene ->
geneToSpecies[gene.uniqueName] = gene.getFeatureLocation().sequence.organism.commonName
}

JsonBuilder toJson = new JsonBuilder()
toJson(geneToSpecies)
return toJson
}
JsonBuilder toJson = new JsonBuilder()
toJson(geneToSpecies)
return toJson
}
}
8 changes: 4 additions & 4 deletions src/gwt/org/bbop/apollo/gwt/client/GeneDetailPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ public void onResponseReceived(Request request, Response response) {
statusListBox.setSelectedIndex(i + 1);
}
}
statusLabelField.setVisible(true);
statusListBox.setVisible(true);
statusLabelField.setText("Status");
statusListBox.setEnabled(true);
} else {
statusLabelField.setVisible(false);
statusListBox.setVisible(false);
statusLabelField.setText("No status created");
statusListBox.setEnabled(false);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gwt/org/bbop/apollo/gwt/client/GeneDetailPanel.ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
.bolder {
font-size: larger;
font-weight: bolder;
width: 100px;
width: 50px;
}

.selectBox {
Expand Down Expand Up @@ -141,4 +141,4 @@
</b:Column>
</b:Row>
</b:Container>
</ui:UiBinder>
</ui:UiBinder>

0 comments on commit d0d5396

Please sign in to comment.