Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributions #2591

Merged
merged 10 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@


## 2.6.4
## 2.6.4

Features

- Added getAttributions method [2591](https://github.com/GMOD/Apollo/pull/2591) via @mbc32.

Infrastructure Changes

- Upgrade to [JBrowse 1.16.11](https://github.com/GMOD/jbrowse/releases/tag/1.16.11-release)


## 2.6.3

Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,25 @@ class AnnotationEditorController extends AbstractApolloController implements Ann
}
}

@RestApiMethod(description = "Gets edits made by the annotator, Returns JSON hash user:[edit_type]", path = "/annotationEditor/getAttributions", verb = RestApiVerb.POST)
@RestApiParams(params = [
@RestApiParam(name = "username", type = "email", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "password", type = "password", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "max", type = "integer", paramType = RestApiParamType.QUERY,description ="(optional) Max number of attributions to return (default 1000)")
])
def getAttributions() {
JSONObject inputObject = permissionService.handleInput(request, params)
if (!permissionService.hasPermissions(inputObject, PermissionEnum.EXPORT)) {
render status: HttpStatus.UNAUTHORIZED
return
}
int max = inputObject.max ?: 1000
JSONObject attributions = featureEventService.generateAttributions( max )
render attributions
}




@MessageMapping("/AnnotationNotification")
@SendTo("/topic/AnnotationNotification")
Expand Down
26 changes: 26 additions & 0 deletions grails-app/services/org/bbop/apollo/FeatureEventService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.bbop.apollo.gwt.shared.FeatureStringEnum
import org.bbop.apollo.history.FeatureOperation
import org.codehaus.groovy.grails.web.json.JSONArray
import org.codehaus.groovy.grails.web.json.JSONObject
import groovy.json.JsonBuilder
import org.grails.plugins.metrics.groovy.Timed

import java.text.DateFormat
Expand Down Expand Up @@ -893,4 +894,29 @@ class FeatureEventService {
}
return historyContainer
}

/**
* Create Annotator (user) attributions by getting all Feature Events
* @param None
* @return json of all edits by user
*/
JSONObject generateAttributions(int max = 1000) {
List<FeatureEvent> featureEvents = FeatureEvent.listOrderByLastUpdated([order: 'desc', max:max])
log.debug("Generating attrubtions: "+ featureEvents.size())
def attributions = new HashMap<String,List<FeatureOperation>>()
featureEvents.each {
log.debug("Generating operation: "+ it.operation)
if(attributions.containsKey(it.getEditor()?.username)){
List<FeatureOperation> operations = attributions.get(it.getEditor()?.username) as List<FeatureOperation>
operations.add(it.operation)
attributions.put(it.getEditor()?.username, operations)
}else {
List<FeatureOperation> operations = []
operations.add(it.operation)
attributions.put(it.getEditor()?.username, operations)
}
}

return new JSONObject(attributions)
}
}
18 changes: 17 additions & 1 deletion test/unit/org/bbop/apollo/FeatureEventServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.bbop.apollo
import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import org.bbop.apollo.history.FeatureOperation
import groovy.json.JsonBuilder
import org.codehaus.groovy.grails.web.json.JSONArray
import org.codehaus.groovy.grails.web.json.JSONObject
import spock.lang.Ignore
Expand All @@ -12,7 +13,7 @@ import spock.lang.Specification
* See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
*/
@TestFor(FeatureEventService)
@Mock([FeatureEvent])
@Mock([FeatureEvent,User])
class FeatureEventServiceSpec extends Specification {

Date today = new Date()
Expand Down Expand Up @@ -1198,4 +1199,19 @@ class FeatureEventServiceSpec extends Specification {

}

void "test generateAttributions"(){
given:
User editor = new User(username:"someRandomUser",passwordHash: "supersecret",firstName: "User",lastName: "Editor").save()
new FeatureEvent(operation: FeatureOperation.ADD_FEATURE, editor: editor, name: "Gene123", uniqueName: "someUniqueName", dateCreated: today - 7, current: true).save(failOnError: true,flush: true)

when:
def attributions = service.generateAttributions()

then:
assert attributions.containsKey("someRandomUser")
def attributionArray = attributions.get("someRandomUser")
assert attributionArray.size()==1
def attributionsObject = attributionArray[0]
assert attributionsObject == FeatureOperation.ADD_FEATURE
}
}
Loading