Skip to content

Commit 11a99e2

Browse files
committed
Merge branch 'release-1.1.0'
2 parents 33379de + 4bed98a commit 11a99e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4196
-286
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
target/
2-
application.properties
3-
application-prod.properties
2+
/application.properties
3+
/application-prod.properties
44
!.mvn/wrapper/maven-wrapper.jar
55

66
### STS ###

pom.xml

+38-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.0.0</version>
8+
<version>1.1.0</version>
99

1010
<parent>
1111
<groupId>org.springframework.boot</groupId>
@@ -111,6 +111,21 @@
111111
<groupId>org.springframework.boot</groupId>
112112
<artifactId>spring-boot-starter-test</artifactId>
113113
<scope>test</scope>
114+
<exclusions>
115+
<exclusion>
116+
<groupId>com.vaadin.external.google</groupId>
117+
<artifactId>android-json</artifactId>
118+
</exclusion>
119+
</exclusions>
120+
</dependency>
121+
<dependency>
122+
<groupId>org.springframework.security</groupId>
123+
<artifactId>spring-security-test</artifactId>
124+
</dependency>
125+
<dependency>
126+
<groupId>com.h2database</groupId>
127+
<artifactId>h2</artifactId>
128+
<scope>test</scope>
114129
</dependency>
115130
</dependencies>
116131

@@ -124,6 +139,28 @@
124139
<groupId>org.springframework.boot</groupId>
125140
<artifactId>spring-boot-maven-plugin</artifactId>
126141
</plugin>
142+
<plugin>
143+
<groupId>com.amashchenko.maven.plugin</groupId>
144+
<artifactId>gitflow-maven-plugin</artifactId>
145+
<version>1.9.0</version>
146+
<configuration>
147+
<!-- Do not push to remote -->
148+
<pushRemote>false</pushRemote>
149+
<verbose>true</verbose>
150+
<!-- Branch naming schemes -->
151+
<gitFlowConfig>
152+
<productionBranch>master</productionBranch>
153+
<developmentBranch>development</developmentBranch>
154+
<releaseBranchPrefix>release-</releaseBranchPrefix>
155+
<versionTagPrefix></versionTagPrefix>
156+
<origin>origin</origin>
157+
<!-- Unused for releasing -->
158+
<featureBranchPrefix>feature-</featureBranchPrefix>
159+
<hotfixBranchPrefix>hotfix-</hotfixBranchPrefix>
160+
<supportBranchPrefix>support-</supportBranchPrefix>
161+
</gitFlowConfig>
162+
</configuration>
163+
</plugin>
127164
</plugins>
128165
</build>
129166

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ubc.pavlab.rdp.controllers;
2+
3+
import lombok.extern.java.Log;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.security.access.prepost.PreAuthorize;
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RequestMethod;
9+
import org.springframework.web.bind.annotation.RestController;
10+
import ubc.pavlab.rdp.model.User;
11+
import ubc.pavlab.rdp.services.UserService;
12+
13+
@RestController
14+
@Log
15+
public class AdminController {
16+
17+
@Autowired
18+
private UserService userService;
19+
20+
@PreAuthorize("hasRole('ADMIN')")
21+
@RequestMapping(value = "/admin/user/{id}/delete", method = RequestMethod.GET)
22+
public String deleteUser( @PathVariable int id ) {
23+
User user = userService.findUserById( id );
24+
if ( user != null ) {
25+
userService.delete( user );
26+
}
27+
return "Deleted.";
28+
}
29+
30+
}

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

-12
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,6 @@ public ModelAndView model( @PathVariable Integer taxonId ) {
8080
return modelAndView;
8181
}
8282

83-
@RequestMapping(value = "/user/taxon/{taxonId}/term/recommend/view", method = RequestMethod.GET)
84-
public ModelAndView getRecommendedTermsForTaxon( @PathVariable Integer taxonId ) {
85-
ModelAndView modelAndView = new ModelAndView();
86-
User user = userService.findCurrentUser();
87-
Taxon taxon = taxonService.findById( taxonId );
88-
89-
modelAndView.addObject( "userTerms", userService.recommendTerms(user, taxon) );
90-
modelAndView.addObject( "viewOnly", true);
91-
modelAndView.setViewName( "fragments/term-table :: term-table" );
92-
return modelAndView;
93-
}
94-
9583
@RequestMapping(value = "/user/taxon/{taxonId}/term/{goId}/gene/view", method = RequestMethod.GET)
9684
public ModelAndView getTermsGenesForTaxon( @PathVariable Integer taxonId, @PathVariable String goId ) {
9785
ModelAndView modelAndView = new ModelAndView();

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public Map<String, Object> getAggregateStats(HttpServletResponse response) {
3939
stats.put( "success", true );
4040
stats.put( "message", "Statistics successfully loaded" );
4141

42-
stats.put( "researchers_registered", (int) userService.countResearchers() );
43-
stats.put( "researchers_registered_with_genes", userService.countResearchersWithGenes() );
42+
stats.put( "researchers_registered", userService.countResearchers() );
43+
stats.put( "researchers_registered_with_genes", userGeneService.countUsersWithGenes() );
4444
stats.put( "genes_added", userGeneService.countAssociations() );
4545
stats.put( "genes_added_unique", userGeneService.countUniqueAssociations() );
4646
stats.put( "researcher_counts_by_taxon", userGeneService.researcherCountByTaxon() );

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

+1-48
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
import javax.validation.Valid;
1919
import java.util.*;
20-
import java.util.stream.Collector;
2120
import java.util.stream.Collectors;
2221

23-
import static java.util.Comparator.comparing;
24-
2522
@RestController
2623
public class UserController {
2724

@@ -51,15 +48,6 @@ static class Model {
5148

5249
}
5350

54-
@RequestMapping(value = "/user/{id}/delete", method = RequestMethod.GET)
55-
public String deleteUser( @PathVariable int id ) {
56-
User user = userService.findUserById( id );
57-
if ( user != null ) {
58-
userService.delete( user );
59-
}
60-
return "Deleted.";
61-
}
62-
6351
@RequestMapping(value = "/user/profile", method = RequestMethod.POST)
6452
public String saveProfile( @RequestBody @Valid Profile profile ) {
6553
User user = userService.findCurrentUser();
@@ -133,50 +121,15 @@ public Map<String, UserTerm> getTermsForTaxon( @PathVariable Integer taxonId, @R
133121
}
134122

135123
@RequestMapping(value = "/user/taxon/{taxonId}/term/recommend", method = RequestMethod.GET)
136-
public Collection<UserTerm> getRecommendedTermsForTaxon( @PathVariable Integer taxonId, @RequestParam(value = "top", required = false, defaultValue = "false") boolean top ) {
124+
public Collection<UserTerm> getRecommendedTermsForTaxon( @PathVariable Integer taxonId ) {
137125
User user = userService.findCurrentUser();
138126
Taxon taxon = taxonService.findById( taxonId );
139127
Collection<UserTerm> terms = userService.recommendTerms( user, taxon );
140128

141129
// Remove terms already added
142130
terms.removeAll( user.getTermsByTaxon( taxon ) );
143-
;
144-
if ( top ) {
145-
return terms.stream().collect(maxList(comparing(UserTerm::getFrequency)));
146-
}
147131

148132
return terms;
149133
}
150134

151-
static <T> Collector<T,?,List<T>> maxList( Comparator<? super T> comp) {
152-
return Collector.of(
153-
ArrayList::new,
154-
(list, t) -> {
155-
int c;
156-
if (list.isEmpty() || (c = comp.compare(t, list.get(0))) == 0) {
157-
list.add(t);
158-
} else if (c > 0) {
159-
list.clear();
160-
list.add(t);
161-
}
162-
},
163-
(list1, list2) -> {
164-
if (list1.isEmpty()) {
165-
return list2;
166-
}
167-
if (list2.isEmpty()) {
168-
return list1;
169-
}
170-
int r = comp.compare(list1.get(0), list2.get(0));
171-
if (r < 0) {
172-
return list2;
173-
} else if (r > 0) {
174-
return list1;
175-
} else {
176-
list1.addAll(list2);
177-
return list1;
178-
}
179-
});
180-
}
181-
182135
}

src/main/java/ubc/pavlab/rdp/model/PasswordResetToken.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class PasswordResetToken {
2222

2323
@Id
2424
@GeneratedValue(strategy = GenerationType.AUTO)
25-
private int id;
25+
private Integer id;
2626

2727
private String token;
2828

src/main/java/ubc/pavlab/rdp/model/Publication.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Publication {
2222
@Id
2323
@GeneratedValue(strategy = GenerationType.AUTO)
2424
@Column(name = "publication_id")
25-
private int id;
25+
private Integer id;
2626

2727
@Column(name = "pmid")
2828
private int pmid;

src/main/java/ubc/pavlab/rdp/model/Role.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Role {
2424
@Id
2525
@GeneratedValue(strategy = GenerationType.AUTO)
2626
@Column(name = "role_id")
27-
private int id;
27+
private Integer id;
2828

2929
@Column(name = "role")
3030
private String role;

src/main/java/ubc/pavlab/rdp/model/Taxon.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Taxon {
2424

2525
@Id
2626
@Column(name = "taxon_id")
27-
private int id;
27+
private Integer id;
2828

2929
private String scientificName;
3030

src/main/java/ubc/pavlab/rdp/model/User.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class User {
3535
@GeneratedValue(strategy = GenerationType.AUTO)
3636
@Column(name = "user_id")
3737
@JsonIgnore
38-
private int id;
38+
private Integer id;
3939

4040
@Column(name = "email")
4141
@Email(message = "*Please provide a valid Email")
@@ -53,7 +53,7 @@ public class User {
5353
@JsonIgnore
5454
private boolean enabled;
5555

56-
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
56+
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
5757
@ManyToMany(fetch = FetchType.EAGER)
5858
@JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
5959
@JsonIgnore

src/main/java/ubc/pavlab/rdp/model/UserGene.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class UserGene extends Gene {
3131
@GeneratedValue(strategy = GenerationType.AUTO)
3232
@Column
3333
@JsonIgnore
34-
private int id;
34+
private Integer id;
3535

3636
@Enumerated(EnumType.STRING)
3737
@Column(length = 5)

src/main/java/ubc/pavlab/rdp/model/UserPrinciple.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public UserPrinciple(User user) {
1919
this.authorities = user.getRoles().stream().map( r -> new SimpleGrantedAuthority( r.getRole() ) ).collect( Collectors.toSet() );
2020
}
2121

22-
public int getId() {
22+
public Integer getId() {
2323
return user.getId();
2424
}
2525

src/main/java/ubc/pavlab/rdp/model/UserTerm.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class UserTerm extends GeneOntologyTerm {
2929
@GeneratedValue(strategy = GenerationType.AUTO)
3030
@Column
3131
@JsonIgnore
32-
private int id;
32+
private Integer id;
3333

3434
@ManyToOne
3535
@JoinColumn(name = "taxon_id")

src/main/java/ubc/pavlab/rdp/model/VerificationToken.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class VerificationToken {
2222

2323
@Id
2424
@GeneratedValue(strategy = GenerationType.AUTO)
25-
private int id;
25+
private Integer id;
2626

2727
private String token;
2828

src/main/java/ubc/pavlab/rdp/repositories/PasswordResetTokenRepository.java

-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
import ubc.pavlab.rdp.model.User;
99

1010
import java.util.Date;
11-
import java.util.stream.Stream;
1211

1312
@Repository
1413
public interface PasswordResetTokenRepository extends JpaRepository<PasswordResetToken, Integer> {
1514
PasswordResetToken findByToken(String token);
1615
PasswordResetToken findByUser(User user);
17-
Stream<PasswordResetToken> findAllByExpiryDateLessThan( Date now);
18-
void deleteByExpiryDateLessThan(Date now);
1916

2017
@Modifying
2118
@Query("delete from PasswordResetToken t where t.expiryDate <= ?1")

src/main/java/ubc/pavlab/rdp/repositories/UserGeneRepository.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package ubc.pavlab.rdp.repositories;
22

33
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.Query;
45
import org.springframework.data.jpa.repository.QueryHints;
6+
import org.springframework.data.repository.query.Param;
57
import org.springframework.stereotype.Repository;
68
import ubc.pavlab.rdp.model.Taxon;
79
import ubc.pavlab.rdp.model.UserGene;
@@ -14,8 +16,15 @@
1416
@Repository
1517
public interface UserGeneRepository extends JpaRepository<UserGene, Integer> {
1618
Integer countByTierIn( Collection<TierType> tiers );
17-
Integer countDistinctGeneByTierIn( Collection<TierType> tiers );
18-
Integer countDistinctUserByTaxon( Taxon taxon );
19+
20+
@Query("select count(distinct geneId) FROM UserGene WHERE tier IN (:tiers)")
21+
Integer countDistinctGeneByTierIn( @Param("tiers") Collection<TierType> tiers );
22+
23+
@Query("select count(distinct user) FROM UserGene WHERE taxon = :taxon")
24+
Integer countDistinctUserByTaxon( @Param("taxon") Taxon taxon );
25+
26+
@Query("select count(distinct user) FROM UserGene")
27+
Integer countDistinctUser();
1928

2029
@QueryHints(@QueryHint(name = "org.hibernate.cacheable", value = "true"))
2130
Collection<UserGene> findByGeneId(int geneId);
@@ -24,10 +33,10 @@ public interface UserGeneRepository extends JpaRepository<UserGene, Integer> {
2433
@QueryHints(@QueryHint(name = "org.hibernate.cacheable", value = "true"))
2534
Collection<UserGene> findByGeneIdAndTierIn(int geneId, Set<TierType> tiers);
2635
@QueryHints(@QueryHint(name = "org.hibernate.cacheable", value = "true"))
27-
Collection<UserGene> findBySymbolContainingAndTaxon(String symbolContaining, Taxon taxon);
36+
Collection<UserGene> findBySymbolContainingIgnoreCaseAndTaxon(String symbolContaining, Taxon taxon);
2837
@QueryHints(@QueryHint(name = "org.hibernate.cacheable", value = "true"))
29-
Collection<UserGene> findBySymbolContainingAndTaxonAndTier(String symbolContaining, Taxon taxon, TierType tier);
38+
Collection<UserGene> findBySymbolContainingIgnoreCaseAndTaxonAndTier(String symbolContaining, Taxon taxon, TierType tier);
3039
@QueryHints(@QueryHint(name = "org.hibernate.cacheable", value = "true"))
31-
Collection<UserGene> findBySymbolContainingAndTaxonAndTierIn(String symbolContaining, Taxon taxon, Set<TierType> tiers);
40+
Collection<UserGene> findBySymbolContainingIgnoreCaseAndTaxonAndTierIn(String symbolContaining, Taxon taxon, Set<TierType> tiers);
3241

3342
}
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,26 @@
11
package ubc.pavlab.rdp.repositories;
22

3-
import org.springframework.cache.annotation.CacheEvict;
43
import org.springframework.cache.annotation.Cacheable;
54
import org.springframework.data.jpa.repository.JpaRepository;
6-
import org.springframework.data.jpa.repository.Query;
75
import org.springframework.data.jpa.repository.QueryHints;
8-
import org.springframework.data.repository.query.Param;
96
import org.springframework.stereotype.Repository;
10-
import ubc.pavlab.rdp.model.Gene;
11-
import ubc.pavlab.rdp.model.Taxon;
127
import ubc.pavlab.rdp.model.User;
13-
import ubc.pavlab.rdp.model.enums.TierType;
148

159
import javax.persistence.QueryHint;
1610
import java.util.Collection;
17-
import java.util.Set;
1811

1912
@Repository
2013
public interface UserRepository extends JpaRepository<User, Integer> {
2114

2215
@Cacheable(cacheNames="stats", key = "#root.methodName")
2316
long count();
2417

25-
User findByEmail(String email);
18+
User findByEmailIgnoreCase(String email);
2619

2720
@QueryHints(@QueryHint(name = "org.hibernate.cacheable", value = "true"))
28-
Collection<User> findByProfileNameContainingOrProfileLastNameContaining( String nameLike, String lastNameLike );
21+
Collection<User> findByProfileNameContainingIgnoreCaseOrProfileLastNameContainingIgnoreCase( String nameLike, String lastNameLike );
2922

3023
@QueryHints(@QueryHint(name = "org.hibernate.cacheable", value = "true"))
31-
@Query("select distinct u from User u inner join u.taxonDescriptions td where u.profile.description like %:descriptionLike% or td like %:descriptionLike%")
32-
Collection<User> findByDescription( @Param("descriptionLike") String descriptionLike );
33-
34-
@Cacheable(cacheNames="stats", key = "#root.methodName")
35-
@Query("select count(distinct user_id) FROM UserGene")
36-
Integer countWithGenes();
24+
Collection<User> findByProfileDescriptionContainingIgnoreCaseOrTaxonDescriptionsContainingIgnoreCase( String descriptionLike, String taxonDescriptionLike );
3725

3826
}

0 commit comments

Comments
 (0)