Skip to content

Commit

Permalink
Merge branch 'release-1.2.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbelmadani committed Mar 25, 2019
2 parents e2ec226 + 1dbb77a commit 099b89e
Show file tree
Hide file tree
Showing 14 changed files with 77,815 additions and 54,368 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>ubc.pavlab</groupId>
<artifactId>rdp</artifactId>
<version>1.2.6</version>
<version>1.2.7</version>

<parent>
<groupId>org.springframework.boot</groupId>
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/ubc/pavlab/rdp/controllers/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -17,6 +20,7 @@
import ubc.pavlab.rdp.settings.ApplicationSettings;

import javax.mail.MessagingException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
Expand Down Expand Up @@ -197,6 +201,41 @@ public ModelAndView supportPost( HttpServletRequest request, @RequestParam("name
return modelAndView;
}


@RequestMapping(value="/gettimeout", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ModelAndView getTimeout(HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
// public ResponseEntity<Object> getTimeout(HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
// Set cookie
addTimeoutCookies(servletRequest, servletResponse);

ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject( "message", "Session timeout refreshed." );

//return new ResponseEntity<Object>(HttpStatus.OK);
return modelAndView;
}

private void addTimeoutCookies(HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
User user = userService.findCurrentUser();
if ( user != null ) {
// Only set timeout cookie if the user is authenticated.
long currTime = System.currentTimeMillis();
int TIMEOUT_IN_SECONDS = servletRequest.getSession().getMaxInactiveInterval() - 60; // Subtracting by 60s to give an extra minute client-side.
long expiryTime = currTime + TIMEOUT_IN_SECONDS * 1000;

// Get cookie for server current time.
Cookie serverTimeCookie = new Cookie("serverTime", "" + currTime);
serverTimeCookie.setPath("/");
servletResponse.addCookie(serverTimeCookie);

// Get cookie for expiration time (consistent with serverTime cookie).
Cookie expiryCookie = new Cookie("sessionExpiry", "" + expiryTime);
expiryCookie.setPath("/");
servletResponse.addCookie(expiryCookie);
}
}

private boolean searchAuthorized(User user){
if(adminRole == null) {
adminRole = roleRepository.findByRole( "ROLE_ADMIN" );
Expand Down
78 changes: 70 additions & 8 deletions src/main/java/ubc/pavlab/rdp/controllers/SearchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
Expand All @@ -19,6 +22,14 @@
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Created by mjacobson on 05/02/18.
Expand Down Expand Up @@ -227,15 +238,61 @@ public ModelAndView searchUsersByGeneView( @RequestParam String symbol, @Request
modelAndView.setViewName( "fragments/error :: message" );
modelAndView.addObject( "errorMessage", String.format( ERR_NO_ORTHOLOGS, symbol ) );
} else {
modelAndView.addObject( "usergenes", handleGeneSearch( gene, tier, orthologs ) );
modelAndView.addObject( "usergenes", handleGeneSearch( gene, tier, orthologs ) );
modelAndView.setViewName( "fragments/user-table :: usergenes-table" );
}

return modelAndView;
}

@RequestMapping(value = "/search/view/international", method = RequestMethod.GET, params = { "symbol", "taxonId",
"tier" })
@RequestMapping(value = "/search/view/orthologs", method = RequestMethod.GET, params = { "symbol", "taxonId", "tier" })
public ModelAndView searchOrthologsForGene(@RequestParam String symbol, @RequestParam Integer taxonId,
@RequestParam TierType tier,
@RequestParam(name = "orthologTaxonId", required = false) Integer orthologTaxonId ) {
if(!searchAuthorized( userService.findCurrentUser(), false )){
return null;
}

// Only look for orthologs when taxon is human
if(taxonId != 9606){
orthologTaxonId = null;
}

Taxon taxon = taxonService.findById( taxonId );
Gene gene = geneService.findBySymbolAndTaxon( symbol, taxon );
Collection<Gene> orthologs = getOrthologsIfRequested( orthologTaxonId, gene );
Map<String, List<Gene>> orthologMap = null;

ModelAndView modelAndView = new ModelAndView();

if ( gene == null ) {
modelAndView.setViewName( "fragments/error :: message" );
modelAndView.addObject( "errorMessage", String.format( ERR_NO_GENE, symbol ) );
} else if (
// Check if there is a ortholog request for a different taxon than the original gene
( orthologTaxonId != null && !orthologTaxonId.equals( gene.getTaxon().getId() ) )
// Check if we got some ortholog results
&& ( orthologs == null || orthologs.isEmpty() ) ) {
modelAndView.setViewName( "fragments/error :: message" );
modelAndView.addObject( "errorMessage", String.format( ERR_NO_ORTHOLOGS, symbol ) );
} else {
orthologMap = new HashMap<>();
for (Gene o : orthologs){
String name = o.getTaxon().getCommonName();
if (!orthologMap.containsKey(name)) {
orthologMap.put(name, new ArrayList<Gene>());
}
orthologMap.get(name).add(o);
}
modelAndView.addObject( "orthologs", orthologMap );
modelAndView.setViewName( "fragments/ortholog-table :: ortholog-table" );
}
return modelAndView;
}



@RequestMapping(value = "/search/view/international", method = RequestMethod.GET, params = { "symbol", "taxonId", "tier" })
public ModelAndView searchItlUsersByGeneView( @RequestParam String symbol, @RequestParam Integer taxonId,
@RequestParam TierType tier,
@RequestParam(name = "orthologTaxonId", required = false) Integer orthologTaxonId ) {
Expand Down Expand Up @@ -321,16 +378,21 @@ Collection<Gene> getOrthologsIfRequested( Integer orthologTaxonId, Gene gene ) {
//noinspection unchecked
return Collections.EMPTY_LIST;
}

private boolean searchAuthorized( User user, boolean international ) {

if ( adminRole == null ) {
adminRole = roleRepository.findByRole( "ROLE_ADMIN" );
}

return ( applicationSettings.getPrivacy().isPublicSearch() // Search is public
|| ( applicationSettings.getPrivacy().isRegisteredSearch() && user != null ) // Search is registered and there is user logged
|| ( user != null && adminRole != null && user.getRoles().contains( adminRole ) ) ) // User is admin

if ( user == null ){
log.info( "User is null in searchAuthorized(); Non-public search will not be authorized." );
}


return ( applicationSettings.getPrivacy().isPublicSearch() // Search is public
|| ( user != null && applicationSettings.getPrivacy().isRegisteredSearch() ) // Search is registered and there is user logged
|| ( user != null && adminRole != null && user.getRoles().contains( adminRole ) ) ) // User is admin
&& ( !international || applicationSettings.getIsearch().isEnabled() ); // International search enabled
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ubc/pavlab/rdp/services/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,11 @@ public String getCurrentEmail() {

@Override
public User findCurrentUser() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if ( auth == null || auth.getPrincipal().equals( "anonymousUser" ) ) {
return null;
}

return findUserByIdNoAuth( ( ( UserPrinciple ) auth.getPrincipal() ).getId() );
}

Expand Down
Loading

0 comments on commit 099b89e

Please sign in to comment.