Skip to content

Commit 099b89e

Browse files
committed
Merge branch 'release-1.2.7'
2 parents e2ec226 + 1dbb77a commit 099b89e

File tree

14 files changed

+77815
-54368
lines changed

14 files changed

+77815
-54368
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>ubc.pavlab</groupId>
77
<artifactId>rdp</artifactId>
8-
<version>1.2.6</version>
8+
<version>1.2.7</version>
99

1010
<parent>
1111
<groupId>org.springframework.boot</groupId>

src/main/java/ubc/pavlab/rdp/controllers/MainController.java

+39
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import org.apache.commons.logging.Log;
44
import org.apache.commons.logging.LogFactory;
55
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.http.HttpStatus;
7+
import org.springframework.http.ResponseEntity;
68
import org.springframework.stereotype.Controller;
79
import org.springframework.web.bind.annotation.PathVariable;
10+
import org.springframework.web.bind.annotation.ResponseBody;
811
import org.springframework.web.bind.annotation.RequestMapping;
912
import org.springframework.web.bind.annotation.RequestMethod;
1013
import org.springframework.web.bind.annotation.RequestParam;
@@ -17,6 +20,7 @@
1720
import ubc.pavlab.rdp.settings.ApplicationSettings;
1821

1922
import javax.mail.MessagingException;
23+
import javax.servlet.http.Cookie;
2024
import javax.servlet.http.HttpServletRequest;
2125
import javax.servlet.http.HttpServletResponse;
2226
import java.io.IOException;
@@ -197,6 +201,41 @@ public ModelAndView supportPost( HttpServletRequest request, @RequestParam("name
197201
return modelAndView;
198202
}
199203

204+
205+
@RequestMapping(value="/gettimeout", method = RequestMethod.GET, produces = "application/json")
206+
@ResponseBody
207+
public ModelAndView getTimeout(HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
208+
// public ResponseEntity<Object> getTimeout(HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
209+
// Set cookie
210+
addTimeoutCookies(servletRequest, servletResponse);
211+
212+
ModelAndView modelAndView = new ModelAndView();
213+
modelAndView.addObject( "message", "Session timeout refreshed." );
214+
215+
//return new ResponseEntity<Object>(HttpStatus.OK);
216+
return modelAndView;
217+
}
218+
219+
private void addTimeoutCookies(HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
220+
User user = userService.findCurrentUser();
221+
if ( user != null ) {
222+
// Only set timeout cookie if the user is authenticated.
223+
long currTime = System.currentTimeMillis();
224+
int TIMEOUT_IN_SECONDS = servletRequest.getSession().getMaxInactiveInterval() - 60; // Subtracting by 60s to give an extra minute client-side.
225+
long expiryTime = currTime + TIMEOUT_IN_SECONDS * 1000;
226+
227+
// Get cookie for server current time.
228+
Cookie serverTimeCookie = new Cookie("serverTime", "" + currTime);
229+
serverTimeCookie.setPath("/");
230+
servletResponse.addCookie(serverTimeCookie);
231+
232+
// Get cookie for expiration time (consistent with serverTime cookie).
233+
Cookie expiryCookie = new Cookie("sessionExpiry", "" + expiryTime);
234+
expiryCookie.setPath("/");
235+
servletResponse.addCookie(expiryCookie);
236+
}
237+
}
238+
200239
private boolean searchAuthorized(User user){
201240
if(adminRole == null) {
202241
adminRole = roleRepository.findByRole( "ROLE_ADMIN" );

src/main/java/ubc/pavlab/rdp/controllers/SearchController.java

+70-8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import org.apache.commons.logging.Log;
44
import org.apache.commons.logging.LogFactory;
55
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.http.HttpStatus;
7+
import org.springframework.http.ResponseEntity;
68
import org.springframework.stereotype.Controller;
79
import org.springframework.web.bind.annotation.PathVariable;
810
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.ResponseBody;
912
import org.springframework.web.bind.annotation.RequestMethod;
1013
import org.springframework.web.bind.annotation.RequestParam;
1114
import org.springframework.web.servlet.ModelAndView;
@@ -19,6 +22,14 @@
1922
import java.util.Collection;
2023
import java.util.Collections;
2124
import java.util.LinkedList;
25+
import java.util.Map;
26+
import java.util.HashMap;
27+
import java.util.List;
28+
import java.util.ArrayList;
29+
30+
import javax.servlet.http.Cookie;
31+
import javax.servlet.http.HttpServletRequest;
32+
import javax.servlet.http.HttpServletResponse;
2233

2334
/**
2435
* Created by mjacobson on 05/02/18.
@@ -227,15 +238,61 @@ public ModelAndView searchUsersByGeneView( @RequestParam String symbol, @Request
227238
modelAndView.setViewName( "fragments/error :: message" );
228239
modelAndView.addObject( "errorMessage", String.format( ERR_NO_ORTHOLOGS, symbol ) );
229240
} else {
230-
modelAndView.addObject( "usergenes", handleGeneSearch( gene, tier, orthologs ) );
241+
modelAndView.addObject( "usergenes", handleGeneSearch( gene, tier, orthologs ) );
231242
modelAndView.setViewName( "fragments/user-table :: usergenes-table" );
232243
}
233244

234245
return modelAndView;
235246
}
236247

237-
@RequestMapping(value = "/search/view/international", method = RequestMethod.GET, params = { "symbol", "taxonId",
238-
"tier" })
248+
@RequestMapping(value = "/search/view/orthologs", method = RequestMethod.GET, params = { "symbol", "taxonId", "tier" })
249+
public ModelAndView searchOrthologsForGene(@RequestParam String symbol, @RequestParam Integer taxonId,
250+
@RequestParam TierType tier,
251+
@RequestParam(name = "orthologTaxonId", required = false) Integer orthologTaxonId ) {
252+
if(!searchAuthorized( userService.findCurrentUser(), false )){
253+
return null;
254+
}
255+
256+
// Only look for orthologs when taxon is human
257+
if(taxonId != 9606){
258+
orthologTaxonId = null;
259+
}
260+
261+
Taxon taxon = taxonService.findById( taxonId );
262+
Gene gene = geneService.findBySymbolAndTaxon( symbol, taxon );
263+
Collection<Gene> orthologs = getOrthologsIfRequested( orthologTaxonId, gene );
264+
Map<String, List<Gene>> orthologMap = null;
265+
266+
ModelAndView modelAndView = new ModelAndView();
267+
268+
if ( gene == null ) {
269+
modelAndView.setViewName( "fragments/error :: message" );
270+
modelAndView.addObject( "errorMessage", String.format( ERR_NO_GENE, symbol ) );
271+
} else if (
272+
// Check if there is a ortholog request for a different taxon than the original gene
273+
( orthologTaxonId != null && !orthologTaxonId.equals( gene.getTaxon().getId() ) )
274+
// Check if we got some ortholog results
275+
&& ( orthologs == null || orthologs.isEmpty() ) ) {
276+
modelAndView.setViewName( "fragments/error :: message" );
277+
modelAndView.addObject( "errorMessage", String.format( ERR_NO_ORTHOLOGS, symbol ) );
278+
} else {
279+
orthologMap = new HashMap<>();
280+
for (Gene o : orthologs){
281+
String name = o.getTaxon().getCommonName();
282+
if (!orthologMap.containsKey(name)) {
283+
orthologMap.put(name, new ArrayList<Gene>());
284+
}
285+
orthologMap.get(name).add(o);
286+
}
287+
modelAndView.addObject( "orthologs", orthologMap );
288+
modelAndView.setViewName( "fragments/ortholog-table :: ortholog-table" );
289+
}
290+
return modelAndView;
291+
}
292+
293+
294+
295+
@RequestMapping(value = "/search/view/international", method = RequestMethod.GET, params = { "symbol", "taxonId", "tier" })
239296
public ModelAndView searchItlUsersByGeneView( @RequestParam String symbol, @RequestParam Integer taxonId,
240297
@RequestParam TierType tier,
241298
@RequestParam(name = "orthologTaxonId", required = false) Integer orthologTaxonId ) {
@@ -321,16 +378,21 @@ Collection<Gene> getOrthologsIfRequested( Integer orthologTaxonId, Gene gene ) {
321378
//noinspection unchecked
322379
return Collections.EMPTY_LIST;
323380
}
324-
381+
325382
private boolean searchAuthorized( User user, boolean international ) {
383+
326384
if ( adminRole == null ) {
327385
adminRole = roleRepository.findByRole( "ROLE_ADMIN" );
328386
}
329387

330-
return ( applicationSettings.getPrivacy().isPublicSearch() // Search is public
331-
|| ( applicationSettings.getPrivacy().isRegisteredSearch() && user != null ) // Search is registered and there is user logged
332-
|| ( user != null && adminRole != null && user.getRoles().contains( adminRole ) ) ) // User is admin
333-
388+
if ( user == null ){
389+
log.info( "User is null in searchAuthorized(); Non-public search will not be authorized." );
390+
}
391+
392+
393+
return ( applicationSettings.getPrivacy().isPublicSearch() // Search is public
394+
|| ( user != null && applicationSettings.getPrivacy().isRegisteredSearch() ) // Search is registered and there is user logged
395+
|| ( user != null && adminRole != null && user.getRoles().contains( adminRole ) ) ) // User is admin
334396
&& ( !international || applicationSettings.getIsearch().isEnabled() ); // International search enabled
335397
}
336398

src/main/java/ubc/pavlab/rdp/services/UserServiceImpl.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@ public String getCurrentEmail() {
203203

204204
@Override
205205
public User findCurrentUser() {
206-
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
206+
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
207207
if ( auth == null || auth.getPrincipal().equals( "anonymousUser" ) ) {
208208
return null;
209209
}
210+
210211
return findUserByIdNoAuth( ( ( UserPrinciple ) auth.getPrincipal() ).getId() );
211212
}
212213

0 commit comments

Comments
 (0)