Skip to content

Commit

Permalink
refactor(dao) : LetterSoundContributionEvent #1677 (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
nya-elimu authored Jul 13, 2024
2 parents 99f378d + 97a4217 commit 9c95020
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 70 deletions.
12 changes: 6 additions & 6 deletions src/main/java/ai/elimu/dao/LetterSoundContributionEventDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundContributionEvent;
import java.util.List;
import org.springframework.dao.DataAccessException;

public interface LetterSoundContributionEventDao extends GenericDao<LetterSoundCorrespondenceContributionEvent> {
public interface LetterSoundContributionEventDao extends GenericDao<LetterSoundContributionEvent> {

List<LetterSoundCorrespondenceContributionEvent> readAllOrderedByTimeDesc() throws DataAccessException;
List<LetterSoundContributionEvent> readAllOrderedByTimeDesc() throws DataAccessException;

List<LetterSoundCorrespondenceContributionEvent> readAll(LetterSoundCorrespondence letterSound) throws DataAccessException;
List<LetterSoundContributionEvent> readAll(LetterSoundCorrespondence letterSound) throws DataAccessException;

List<LetterSoundCorrespondenceContributionEvent> readAll(Contributor contributor) throws DataAccessException;
List<LetterSoundContributionEvent> readAll(Contributor contributor) throws DataAccessException;

List<LetterSoundCorrespondenceContributionEvent> readMostRecentPerLetterSound() throws DataAccessException;
List<LetterSoundContributionEvent> readMostRecentPerLetterSound() throws DataAccessException;

Long readCount(Contributor contributor) throws DataAccessException;
}
6 changes: 3 additions & 3 deletions src/main/java/ai/elimu/dao/LetterSoundPeerReviewEventDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundContributionEvent;
import ai.elimu.model.contributor.LetterSoundPeerReviewEvent;
import java.util.List;
import org.springframework.dao.DataAccessException;

public interface LetterSoundPeerReviewEventDao extends GenericDao<LetterSoundPeerReviewEvent> {

List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent, Contributor contributor) throws DataAccessException;
List<LetterSoundPeerReviewEvent> readAll(LetterSoundContributionEvent letterSoundContributionEvent, Contributor contributor) throws DataAccessException;

List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondence letterSoundCorrespondence) throws DataAccessException;

List<LetterSoundPeerReviewEvent> readAll(Contributor contributor) throws DataAccessException;

List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent) throws DataAccessException;
List<LetterSoundPeerReviewEvent> readAll(LetterSoundContributionEvent letterSoundContributionEvent) throws DataAccessException;

Long readCount(Contributor contributor) throws DataAccessException;
}
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
package ai.elimu.dao.jpa;

import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.dao.LetterSoundContributionEventDao;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.contributor.Contributor;
import java.util.List;

import ai.elimu.model.contributor.LetterSoundContributionEvent;
import org.springframework.dao.DataAccessException;

public class LetterSoundContributionEventDaoJpa extends GenericDaoJpa<LetterSoundCorrespondenceContributionEvent> implements LetterSoundContributionEventDao {
public class LetterSoundContributionEventDaoJpa extends GenericDaoJpa<LetterSoundContributionEvent> implements LetterSoundContributionEventDao {

@Override
public List<LetterSoundCorrespondenceContributionEvent> readAllOrderedByTimeDesc() throws DataAccessException {
public List<LetterSoundContributionEvent> readAllOrderedByTimeDesc() throws DataAccessException {
return em.createQuery(
"SELECT e " +
"FROM LetterSoundCorrespondenceContributionEvent e " +
"FROM LetterSoundContributionEvent e " +
"ORDER BY e.time DESC")
.getResultList();
}

@Override
public List<LetterSoundCorrespondenceContributionEvent> readAll(LetterSoundCorrespondence letterSound) throws DataAccessException {
public List<LetterSoundContributionEvent> readAll(LetterSoundCorrespondence letterSound) throws DataAccessException {
return em.createQuery(
"SELECT e " +
"FROM LetterSoundCorrespondenceContributionEvent e " +
"FROM LetterSoundContributionEvent e " +
"WHERE e.letterSound = :letterSound " +
"ORDER BY e.time DESC")
.setParameter("letterSound", letterSound)
.getResultList();
}

@Override
public List<LetterSoundCorrespondenceContributionEvent> readAll(Contributor contributor) throws DataAccessException {
public List<LetterSoundContributionEvent> readAll(Contributor contributor) throws DataAccessException {
return em.createQuery(
"SELECT e " +
"FROM LetterSoundCorrespondenceContributionEvent e " +
"FROM LetterSoundContributionEvent e " +
"WHERE e.contributor = :contributor " +
"ORDER BY e.time DESC")
.setParameter("contributor", contributor)
.getResultList();
}

@Override
public List<LetterSoundCorrespondenceContributionEvent> readMostRecentPerLetterSound() throws DataAccessException {
public List<LetterSoundContributionEvent> readMostRecentPerLetterSound() throws DataAccessException {
return em.createQuery(
"SELECT e " +
"FROM LetterSoundCorrespondenceContributionEvent e " +
"WHERE e.time IN (SELECT MAX(time) FROM LetterSoundCorrespondenceContributionEvent GROUP BY letterSound_id) " + // TODO: replace with "NOT EXISTS"? - https://stackoverflow.com/a/25694562
"FROM LetterSoundContributionEvent e " +
"WHERE e.time IN (SELECT MAX(time) FROM LetterSoundContributionEvent GROUP BY letterSound_id) " + // TODO: replace with "NOT EXISTS"? - https://stackoverflow.com/a/25694562
"ORDER BY e.time ASC")
.getResultList();
}

@Override
public Long readCount(Contributor contributor) throws DataAccessException {
return (Long) em.createQuery("SELECT COUNT(e) " +
"FROM LetterSoundCorrespondenceContributionEvent e " +
"FROM LetterSoundContributionEvent e " +
"WHERE e.contributor = :contributor")
.setParameter("contributor", contributor)
.getSingleResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import ai.elimu.dao.LetterSoundPeerReviewEventDao;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundContributionEvent;
import ai.elimu.model.contributor.LetterSoundPeerReviewEvent;
import java.util.List;
import org.springframework.dao.DataAccessException;

public class LetterSoundPeerReviewEventDaoJpa extends GenericDaoJpa<LetterSoundPeerReviewEvent> implements LetterSoundPeerReviewEventDao {

@Override
public List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent, Contributor contributor) throws DataAccessException {
public List<LetterSoundPeerReviewEvent> readAll(LetterSoundContributionEvent letterSoundContributionEvent, Contributor contributor) throws DataAccessException {
return em.createQuery(
"SELECT event " +
"FROM LetterSoundPeerReviewEvent event " +
Expand Down Expand Up @@ -46,7 +46,7 @@ public List<LetterSoundPeerReviewEvent> readAll(Contributor contributor) throws
}

@Override
public List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent) throws DataAccessException {
public List<LetterSoundPeerReviewEvent> readAll(LetterSoundContributionEvent letterSoundContributionEvent) throws DataAccessException {
return em.createQuery(
"SELECT event " +
"FROM LetterSoundPeerReviewEvent event " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import javax.validation.constraints.NotNull;

@Entity
public class LetterSoundCorrespondenceContributionEvent extends ContributionEvent {
public class LetterSoundContributionEvent extends ContributionEvent {

@NotNull
@ManyToOne
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class LetterSoundPeerReviewEvent extends PeerReviewEvent {
*/
@NotNull
@ManyToOne
private LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent;
private LetterSoundContributionEvent letterSoundContributionEvent;

public LetterSoundCorrespondenceContributionEvent getLetterSoundContributionEvent() {
public LetterSoundContributionEvent getLetterSoundContributionEvent() {
return letterSoundContributionEvent;
}

public void setLetterSoundContributionEvent(LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent) {
public void setLetterSoundContributionEvent(LetterSoundContributionEvent letterSoundContributionEvent) {
this.letterSoundContributionEvent = letterSoundContributionEvent;
}
}
6 changes: 3 additions & 3 deletions src/main/java/ai/elimu/util/db/DbContentImportHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import ai.elimu.model.content.multimedia.Image;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterContributionEvent;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundContributionEvent;
import ai.elimu.model.contributor.WordContributionEvent;
import ai.elimu.model.contributor.NumberContributionEvent;
import ai.elimu.model.contributor.StoryBookContributionEvent;
import ai.elimu.model.contributor.WordContributionEvent;
import ai.elimu.model.enums.Role;
import ai.elimu.model.v2.enums.Environment;
import ai.elimu.model.v2.enums.Language;
Expand Down Expand Up @@ -171,7 +171,7 @@ public synchronized void performDatabaseContentImport(Environment environment, L
for (LetterSoundCorrespondence letterSound : letterSounds) {
letterSoundDao.create(letterSound);

LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent = new LetterSoundCorrespondenceContributionEvent();
LetterSoundContributionEvent letterSoundContributionEvent = new LetterSoundContributionEvent();
letterSoundContributionEvent.setContributor(contributor);
letterSoundContributionEvent.setLetterSound(letterSound);
letterSoundContributionEvent.setRevisionNumber(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import javax.validation.Valid;

import ai.elimu.model.contributor.LetterSoundContributionEvent;
import org.apache.logging.log4j.Logger;
import ai.elimu.dao.LetterDao;
import ai.elimu.dao.LetterSoundContributionEventDao;
Expand All @@ -18,7 +19,6 @@
import org.springframework.web.bind.annotation.RequestMethod;
import ai.elimu.dao.LetterSoundDao;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.util.DiscordHelper;
import ai.elimu.web.context.EnvironmentContextLoaderListener;
import java.util.Calendar;
Expand Down Expand Up @@ -96,7 +96,7 @@ public String handleSubmit(
letterSound.setTimeLastUpdate(Calendar.getInstance());
letterSoundDao.create(letterSound);

LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent = new LetterSoundCorrespondenceContributionEvent();
LetterSoundContributionEvent letterSoundContributionEvent = new LetterSoundContributionEvent();
letterSoundContributionEvent.setContributor((Contributor) session.getAttribute("contributor"));
letterSoundContributionEvent.setTime(Calendar.getInstance());
letterSoundContributionEvent.setLetterSound(letterSound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import javax.validation.Valid;

import ai.elimu.model.contributor.LetterSoundContributionEvent;
import org.apache.logging.log4j.Logger;
import ai.elimu.dao.LetterDao;
import ai.elimu.dao.LetterSoundContributionEventDao;
Expand All @@ -22,7 +23,6 @@
import ai.elimu.dao.WordDao;
import ai.elimu.model.content.Word;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.util.DiscordHelper;
import java.util.Calendar;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -116,7 +116,7 @@ public String handleSubmit(
letterSound.setRevisionNumber(letterSound.getRevisionNumber() + 1);
letterSoundDao.update(letterSound);

LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent = new LetterSoundCorrespondenceContributionEvent();
LetterSoundContributionEvent letterSoundContributionEvent = new LetterSoundContributionEvent();
letterSoundContributionEvent.setContributor((Contributor) session.getAttribute("contributor"));
letterSoundContributionEvent.setTime(Calendar.getInstance());
letterSoundContributionEvent.setLetterSound(letterSound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ai.elimu.dao.LetterSoundDao;
import ai.elimu.dao.LetterSoundPeerReviewEventDao;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundContributionEvent;
import ai.elimu.model.contributor.LetterSoundPeerReviewEvent;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -37,7 +37,7 @@ public class LetterSoundPeerReviewsController {
private EmojiDao emojiDao;

/**
* Get {@link LetterSoundCorrespondenceContributionEvent}s pending a {@link LetterSoundPeerReviewEvent} for the current {@link Contributor}.
* Get {@link LetterSoundContributionEvent}s pending a {@link LetterSoundPeerReviewEvent} for the current {@link Contributor}.
*/
@RequestMapping(method = RequestMethod.GET)
public String handleGetRequest(HttpSession session, Model model) {
Expand All @@ -46,15 +46,15 @@ public String handleGetRequest(HttpSession session, Model model) {
Contributor contributor = (Contributor) session.getAttribute("contributor");
logger.info("contributor: " + contributor);

// Get the most recent LetterSoundCorrespondenceContributionEvent for each LetterSound, including those made by the current Contributor
List<LetterSoundCorrespondenceContributionEvent> mostRecentLetterSoundContributionEvents = letterSoundContributionEventDao.readMostRecentPerLetterSound();
// Get the most recent LetterSoundContributionEvent for each LetterSound, including those made by the current Contributor
List<LetterSoundContributionEvent> mostRecentLetterSoundContributionEvents = letterSoundContributionEventDao.readMostRecentPerLetterSound();
logger.info("mostRecentLetterSoundContributionEvents.size(): " + mostRecentLetterSoundContributionEvents.size());

// For each LetterSoundCorrespondenceContributionEvent, check if the Contributor has already performed a peer-review.
// For each LetterSoundContributionEvent, check if the Contributor has already performed a peer-review.
// If not, add it to the list of pending peer reviews.
List<LetterSoundCorrespondenceContributionEvent> letterSoundContributionEventsPendingPeerReview = new ArrayList<>();
for (LetterSoundCorrespondenceContributionEvent mostRecentLetterSoundContributionEvent : mostRecentLetterSoundContributionEvents) {
// Ignore LetterSoundCorrespondenceContributionEvents made by the current Contributor
List<LetterSoundContributionEvent> letterSoundContributionEventsPendingPeerReview = new ArrayList<>();
for (LetterSoundContributionEvent mostRecentLetterSoundContributionEvent : mostRecentLetterSoundContributionEvents) {
// Ignore LetterSoundContributionEvents made by the current Contributor
if (mostRecentLetterSoundContributionEvent.getContributor().getId().equals(contributor.getId())) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import ai.elimu.model.content.Letter;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundContributionEvent;
import org.apache.logging.log4j.Logger;
import ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent;
import ai.elimu.model.contributor.LetterSoundPeerReviewEvent;
import ai.elimu.model.enums.PeerReviewStatus;
import ai.elimu.util.DiscordHelper;
Expand Down Expand Up @@ -50,7 +50,7 @@ public String handleSubmit(
Contributor contributor = (Contributor) session.getAttribute("contributor");

logger.info("letterSoundContributionEventId: " + letterSoundContributionEventId);
LetterSoundCorrespondenceContributionEvent letterSoundContributionEvent = letterSoundContributionEventDao.read(letterSoundContributionEventId);
LetterSoundContributionEvent letterSoundContributionEvent = letterSoundContributionEventDao.read(letterSoundContributionEventId);
logger.info("letterSoundContributionEvent: " + letterSoundContributionEvent);

// Store the peer review event
Expand Down
Loading

0 comments on commit 9c95020

Please sign in to comment.