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

Handle large user set #1800

Merged
merged 10 commits into from
Nov 8, 2017
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
78 changes: 64 additions & 14 deletions grails-app/controllers/org/bbop/apollo/UserController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ class UserController {
@RestApiParam(name = "username", type = "email", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "password", type = "password", paramType = RestApiParamType.QUERY)
, @RestApiParam(name = "userId", type = "long / string", paramType = RestApiParamType.QUERY, description = "Optionally only user a specific userId as an integer database id or a username string")
, @RestApiParam(name = "start", type = "long / string", paramType = RestApiParamType.QUERY, description = "(optional) Result start / offset")
, @RestApiParam(name = "length", type = "long / string", paramType = RestApiParamType.QUERY, description = "(optional) Result length")
, @RestApiParam(name = "name", type = "string", paramType = RestApiParamType.QUERY, description = "(optional) Search name")
, @RestApiParam(name = "sortColumn", type = "string", paramType = RestApiParamType.QUERY, description = "(optional) Sort column, default 'name'")
, @RestApiParam(name = "sortAscending", type = "boolean", paramType = RestApiParamType.QUERY, description = "(optional) Sort column is ascending if true, default false")
])
def loadUsers() {
try {
JSONObject dataObject = permissionService.handleInput(request,params)
JSONObject dataObject = permissionService.handleInput(request, params)
JSONArray returnArray = new JSONArray()
if (!permissionService.hasGlobalPermissions(dataObject, PermissionEnum.ADMINISTRATE)) {
render status: HttpStatus.UNAUTHORIZED
Expand All @@ -55,16 +60,59 @@ class UserController {
}

def c = User.createCriteria()
def users = c.list() {
def offset = dataObject.start ?: 0
def maxResults = dataObject.length ?: Integer.MAX_VALUE
def searchName = dataObject.name ?: null
def sortName = dataObject.sortColumn ?: null
def sortAscending = dataObject.sortAscending ?: null

def users = c.list(max: maxResults, offset: offset) {
if (dataObject.userId && dataObject.userId in Integer) {
eq('id', (Long) dataObject.userId)
}
if (dataObject.userId && dataObject.userId in String) {
eq('username', dataObject.userId)
}
}.unique{ a, b ->
if (searchName) {
or {
ilike('firstName', '%' + searchName + '%')
ilike('lastName', '%' + searchName + '%')
ilike('username', '%' + searchName + '%')
}
}
if(sortName){
switch(sortName){
case "name":
order('firstName', sortAscending?"asc":"desc")
order('lastName', sortAscending?"asc":"desc")
break
case "email":
order('username', sortAscending?"asc":"desc")
break
}
}
}.unique { a, b ->
a.id <=> b.id
}

int userCount = User.withCriteria{
if (dataObject.userId && dataObject.userId in Integer) {
eq('id', (Long) dataObject.userId)
}
if (dataObject.userId && dataObject.userId in String) {
eq('username', dataObject.userId)
}
if (searchName) {
or {
ilike('firstName', '%' + searchName + '%')
ilike('lastName', '%' + searchName + '%')
ilike('username', '%' + searchName + '%')
}
}
}.unique { a, b ->
a.id <=> b.id
}.size()

users.each {
def userObject = new JSONObject()

Expand Down Expand Up @@ -131,6 +179,10 @@ class UserController {

userObject.organismPermissions = organismPermissionsArray

// could probably be done in a separate object
userObject.userCount = userCount
userObject.searchName = searchName

returnArray.put(userObject)
}

Expand All @@ -149,20 +201,18 @@ class UserController {
def currentUser = permissionService.currentUser
preferenceService.evaluateSaves(true)


// grab from session
if(!currentUser){
def authToken = null
if(request.getParameter("username")){
if (!currentUser) {
def authToken = null
if (request.getParameter("username")) {
String username = request.getParameter("username")
String password = request.getParameter("password")
authToken = new UsernamePasswordToken(username, password)
}

if(permissionService.authenticateWithToken(request)){
if (permissionService.authenticateWithToken(request)) {
currentUser = permissionService.currentUser
}
else{
} else {
log.error("Failed to authenticate")
}
}
Expand Down Expand Up @@ -303,7 +353,7 @@ class UserController {

String roleString = dataObject.role ?: UserService.USER
Role role = Role.findByName(roleString.toUpperCase())
if(!role){
if (!role) {
role = Role.findByName(UserService.USER)
}
log.debug "adding role: ${role}"
Expand Down Expand Up @@ -385,7 +435,7 @@ class UserController {
try {
log.info "Updating user"
JSONObject dataObject = permissionService.handleInput(request, params)
if (!permissionService.sameUser(dataObject,request) && !permissionService.hasGlobalPermissions(dataObject, PermissionEnum.ADMINISTRATE)) {
if (!permissionService.sameUser(dataObject, request) && !permissionService.hasGlobalPermissions(dataObject, PermissionEnum.ADMINISTRATE)) {
render status: HttpStatus.UNAUTHORIZED
return
}
Expand Down Expand Up @@ -473,7 +523,7 @@ class UserController {
render([(FeatureStringEnum.ERROR.value): "Failed to find organism with ${dataObject.organism}"] as JSON)
return
}
if(!user){
if (!user) {
log.error("Failed to find user with ${dataObject.userId} OR ${dataObject.user}")
render([(FeatureStringEnum.ERROR.value): "Failed to find user with ${dataObject.userId} OR ${dataObject.user}"] as JSON)
}
Expand Down Expand Up @@ -507,7 +557,7 @@ class UserController {
permissionsArray.add(PermissionEnum.READ.name())
}

if(permissionsArray.size()==0){
if (permissionsArray.size() == 0) {
userOrganismPermission.delete(flush: true)
render userOrganismPermission as JSON
return
Expand Down
3 changes: 0 additions & 3 deletions src/gwt/org/bbop/apollo/gwt/client/SequencePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.bbop.apollo.gwt.client.event.UserChangeEvent;
import org.bbop.apollo.gwt.client.event.UserChangeEventHandler;
import org.bbop.apollo.gwt.client.resources.TableResources;
import org.bbop.apollo.gwt.client.rest.OrganismRestService;
import org.bbop.apollo.gwt.client.rest.SequenceRestService;
import org.bbop.apollo.gwt.shared.PermissionEnum;
import org.gwtbootstrap3.client.ui.Button;
Expand All @@ -44,7 +43,6 @@
import java.util.List;
import java.util.Set;

import static org.bbop.apollo.gwt.client.MainPanel.sequenceSuggestBox;

/**
* Created by ndunn on 12/17/14.
Expand Down Expand Up @@ -386,7 +384,6 @@ private void exportValues(List<SequenceInfo> sequenceInfoList) {
} else if (exportChadoButton.getType().equals(ButtonType.DANGER.PRIMARY)) {
type = exportChadoButton.getText();
}
// GWT.log("Type selected is " + type);

ExportPanel exportPanel = new ExportPanel(organismInfo, type, exportAll, sequenceInfoList);
exportPanel.show();
Expand Down
Loading