28
28
import ubc .pavlab .rdp .settings .SiteSettings ;
29
29
30
30
import javax .servlet .http .HttpServletRequest ;
31
- import java .text .MessageFormat ;
32
31
import java .util .*;
33
32
import java .util .stream .Collectors ;
34
33
@@ -116,12 +115,12 @@ public Object getUsers( @RequestHeader(value = HttpHeaders.AUTHORIZATION, requir
116
115
checkAuth ( authorizationHeader , auth );
117
116
if ( applicationSettings .getPrivacy ().isEnableAnonymizedSearchResults () ) {
118
117
final Authentication auth2 = SecurityContextHolder .getContext ().getAuthentication ();
119
- return userService .findAllByIsEnabledNoAuth ( pageable )
118
+ return userService .findByEnabledTrueNoAuth ( pageable )
120
119
.map ( user -> permissionEvaluator .hasPermission ( auth2 , user , "read" ) ? user : userService .anonymizeUser ( user ) )
121
120
.map ( user -> initUser ( user , locale ) );
122
121
123
122
} else {
124
- return userService .findAllByPrivacyLevel ( PrivacyLevelType .PUBLIC , pageable ).map ( user -> initUser ( user , locale ) );
123
+ return userService .findByEnabledTrueAndPrivacyLevelNoAuth ( PrivacyLevelType .PUBLIC , pageable ).map ( user -> initUser ( user , locale ) );
125
124
}
126
125
}
127
126
@@ -138,11 +137,11 @@ public Object getGenes( @RequestHeader(value = HttpHeaders.AUTHORIZATION, requir
138
137
checkAuth ( authorizationHeader , auth );
139
138
if ( applicationSettings .getPrivacy ().isEnableAnonymizedSearchResults () ) {
140
139
final Authentication auth2 = SecurityContextHolder .getContext ().getAuthentication ();
141
- return userGeneService .findAllNoAuth ( pageable )
140
+ return userGeneService .findByUserEnabledTrueNoAuth ( pageable )
142
141
.map ( userGene -> permissionEvaluator .hasPermission ( auth2 , userGene , "read" ) ? userGene : userService .anonymizeUserGene ( userGene ) )
143
142
.map ( userGene -> initUserGene ( userGene , locale ) );
144
143
} else {
145
- return userGeneService .findAllByPrivacyLevel ( PrivacyLevelType .PUBLIC , pageable ).map ( userGene -> initUserGene ( userGene , locale ) );
144
+ return userGeneService .findByUserEnabledTrueAndPrivacyLevelNoAuth ( PrivacyLevelType .PUBLIC , pageable ).map ( userGene -> initUserGene ( userGene , locale ) );
146
145
}
147
146
}
148
147
@@ -197,13 +196,13 @@ public Object searchUsersByGeneSymbol( @RequestParam String symbol,
197
196
Taxon taxon = taxonService .findById ( taxonId );
198
197
199
198
if ( taxon == null ) {
200
- return ResponseEntity . notFound (). build ( );
199
+ throw new ApiException ( HttpStatus . NOT_FOUND , String . format ( locale , "Unknown taxon ID: %s." , taxonId ) );
201
200
}
202
201
203
202
GeneInfo gene = geneService .findBySymbolAndTaxon ( symbol , taxon );
204
203
205
204
if ( gene == null ) {
206
- return ResponseEntity . notFound (). build ( );
205
+ throw new ApiException ( HttpStatus . NOT_FOUND , String . format ( locale , "Unknown gene with symbol: %s." , symbol ) );
207
206
}
208
207
209
208
if ( tiers == null ) {
@@ -217,7 +216,7 @@ public Object searchUsersByGeneSymbol( @RequestParam String symbol,
217
216
218
217
// Check if there is an ortholog request for a different taxon than the original gene
219
218
if ( orthologTaxon != null && !orthologTaxon .equals ( gene .getTaxon () ) && orthologs .isEmpty () ) {
220
- return new ResponseEntity <>( messageSource .getMessage ( "ApiController.noOrthologsWithGivenParameters" , null , locale ), null , HttpStatus . NOT_FOUND );
219
+ throw new ApiException ( HttpStatus . NOT_FOUND , messageSource .getMessage ( "ApiController.noOrthologsWithGivenParameters" , null , locale ) );
221
220
}
222
221
223
222
return initUserGenes ( userGeneService .handleGeneSearch ( gene , restrictTiers ( tiers ), orthologTaxon , researcherPositions , researcherCategories , organsFromUberonIds ( organUberonIds ) ), locale );
@@ -251,7 +250,7 @@ public Object searchUsersByGeneSymbol( @RequestParam String symbol,
251
250
tiers = EnumSet .of ( TierType .valueOf ( tier ) );
252
251
} catch ( IllegalArgumentException e ) {
253
252
log .error ( "Could not parse tier type." , e );
254
- return ResponseEntity . badRequest (). body ( MessageFormat .format ( "Unknown tier {0} ." , tier ) );
253
+ throw new ApiException ( HttpStatus . BAD_REQUEST , String .format ( locale , "Unknown tier: %s ." , tier ), e );
255
254
}
256
255
}
257
256
@@ -267,7 +266,7 @@ public Object getUserById( @PathVariable Integer userId,
267
266
checkAuth ( authorizationHeader , auth );
268
267
User user = userService .findUserById ( userId );
269
268
if ( user == null ) {
270
- return ResponseEntity . notFound (). build ( );
269
+ throw new ApiException ( HttpStatus . NOT_FOUND , String . format ( locale , "Unknown user with ID: %d." , userId ) );
271
270
}
272
271
return initUser ( user , locale );
273
272
}
@@ -282,7 +281,7 @@ public Object getUserByAnonymousId( @PathVariable UUID anonymousId,
282
281
checkAuth ( authorizationHeader , auth );
283
282
User user = userService .findUserByAnonymousIdNoAuth ( anonymousId );
284
283
if ( user == null ) {
285
- return ResponseEntity . notFound (). build ( );
284
+ throw new ApiException ( HttpStatus . NOT_FOUND , String . format ( "Unknown user with anonymous ID: %s." , anonymousId ) );
286
285
}
287
286
if ( permissionEvaluator .hasPermission ( SecurityContextHolder .getContext ().getAuthentication (), user , "read" ) ) {
288
287
return initUser ( user , locale );
0 commit comments