Skip to content

Commit 10a9c6a

Browse files
author
Sakai Developer
committed
Coderabbit
1 parent 4d1c291 commit 10a9c6a

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

polls/api/src/java/org/sakaiproject/poll/repository/VoteRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface VoteRepository extends SpringCrudRepository<Vote, Long> {
99

1010
List<Vote> findByPollId(Long pollId);
1111

12-
List<Vote> findByPollIdAndPollOption(Long pollId, Long pollOption);
12+
List<Vote> findByPollIdAndPollOption(Long pollId, Long optionId);
1313

1414
List<Vote> findByUserId(String userId);
1515

polls/impl/src/java/org/sakaiproject/poll/repository/impl/VoteRepositoryImpl.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public List<Vote> findByPollId(Long pollId) {
3737
}
3838

3939
@Override
40-
public List<Vote> findByPollIdAndPollOption(Long pollId, Long pollOption) {
41-
if (pollId == null || pollOption == null) {
40+
public List<Vote> findByPollIdAndPollOption(Long pollId, Long optionId) {
41+
if (pollId == null || optionId == null) {
4242
return Collections.emptyList();
4343
}
4444
CriteriaBuilder cb = sessionFactory.getCriteriaBuilder();
@@ -48,7 +48,7 @@ public List<Vote> findByPollIdAndPollOption(Long pollId, Long pollOption) {
4848
Join<Vote, Option> optionJoin = root.join("option");
4949

5050
Predicate pollPredicate = cb.equal(pollJoin.get("pollId"), pollId);
51-
Predicate optionPredicate = cb.equal(optionJoin.get("optionId"), pollOption);
51+
Predicate optionPredicate = cb.equal(optionJoin.get("optionId"), optionId);
5252

5353
query.select(root)
5454
.where(cb.and(pollPredicate, optionPredicate));
@@ -60,7 +60,7 @@ public List<Vote> findByPollIdAndPollOption(Long pollId, Long pollOption) {
6060

6161
@Override
6262
public List<Vote> findByUserId(String userId) {
63-
if (userId == null) {
63+
if (userId == null || userId.trim().isEmpty()) {
6464
return Collections.emptyList();
6565
}
6666
CriteriaBuilder cb = sessionFactory.getCriteriaBuilder();
@@ -98,7 +98,7 @@ public List<Vote> findByUserIdAndPollIds(String userId, List<Long> pollIds) {
9898

9999
@Override
100100
public boolean existsByPollIdAndUserId(Long pollId, String userId) {
101-
if (pollId == null || userId == null) {
101+
if (pollId == null || userId == null || userId.trim().isEmpty()) {
102102
return false;
103103
}
104104
CriteriaBuilder cb = sessionFactory.getCriteriaBuilder();
@@ -114,9 +114,9 @@ public boolean existsByPollIdAndUserId(Long pollId, String userId) {
114114

115115
Long count = sessionFactory.getCurrentSession()
116116
.createQuery(query)
117-
.uniqueResult();
117+
.getSingleResult();
118118

119-
return count != null && count > 0;
119+
return count > 0;
120120
}
121121

122122
@Override
@@ -134,8 +134,8 @@ public int countDistinctSubmissionIds(Long pollId) {
134134

135135
Long count = sessionFactory.getCurrentSession()
136136
.createQuery(query)
137-
.uniqueResult();
137+
.getSingleResult();
138138

139-
return count == null ? 0 : count.intValue();
139+
return Math.toIntExact(count);
140140
}
141141
}

polls/tool/src/java/org/sakaiproject/poll/tool/entityproviders/PollsEntityProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ public Object getVoteEntity(EntityReference ref) {
794794

795795
// is this a new object?
796796
if (ref.getId() == null) {
797-
new Vote();
797+
return new Vote();
798798
}
799799

800800
Vote vote = getVoteById(id);

polls/tool/src/java/org/sakaiproject/poll/tool/service/PollsUiService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public Poll savePoll(Poll poll, Locale locale) {
105105

106106
if (poll.getPollId() != null) {
107107
Poll existing = pollListManager.getPollById(poll.getPollId(), false);
108+
if (existing == null) {
109+
throw new PollValidationException("poll_not_found");
110+
}
108111
if (poll.getCreationDate() == null) {
109112
poll.setCreationDate(existing.getCreationDate());
110113
}
@@ -181,6 +184,9 @@ public Poll deleteOption(Long optionId, String orphanVoteHandling) {
181184
}
182185

183186
Poll poll = pollListManager.getPollById(option.getPollId());
187+
if (poll == null) {
188+
throw new PollValidationException("poll_not_found");
189+
}
184190
List<Vote> votes = pollVoteManager.getAllVotesForOption(option);
185191

186192
if (votes != null && !votes.isEmpty()) {

0 commit comments

Comments
 (0)