Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(dao) : LetterSound #1677 #1725

Merged
merged 25 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
78be712
refactor(dao) : LetterSound #1677
Sneha65 Jul 13, 2024
0353b98
Merge branch 'main' of https://github.com/SnehaHS65/webapp into 1677-…
Sneha65 Jul 14, 2024
75c2435
Added DB Script #1677
Sneha65 Jul 14, 2024
a535306
Merge branch 'main' into 1677-LetterSound
jo-elimu Jul 15, 2024
db93ea3
Resolved Merge Conflicts-1677
Sneha65 Jul 16, 2024
2b14ce5
Merge branch '1677-LetterSound' of https://github.com/SnehaHS65/webap…
Sneha65 Jul 16, 2024
d7e8a57
Merge branch 'main' into 1677-LetterSound
jo-elimu Jul 16, 2024
40cf0e1
Apply suggestions from code review
jo-elimu Jul 16, 2024
ff74095
Rename 2004012.sql to 2004014.sql
jo-elimu Jul 16, 2024
82e5cab
Merge remote-tracking branch 'origin/main' into 1677-LetterSound
Sneha65 Jul 17, 2024
f8e3cf4
1677-Modified Front End changes
Sneha65 Jul 17, 2024
cb6b2fe
1677 resolving merge conflicts
Sneha65 Jul 21, 2024
b41df6b
1677 resolving merge conflicts
Sneha65 Jul 21, 2024
984c602
Merge branch 'main' into 1677-LetterSound
SnehaHS65 Jul 21, 2024
1e5373b
1677 matching files in main
Sneha65 Jul 22, 2024
789afbd
Merge branch '1677-LetterSound' of https://github.com/SnehaHS65/webap…
Sneha65 Jul 22, 2024
057ae48
1677 adding jpa-schema-export
Sneha65 Jul 23, 2024
4ea7475
Merge branch 'main' into pr/1725
jo-elimu Jul 24, 2024
bafe644
chore(db): update migration script filename to match version on `main…
jo-elimu Jul 24, 2024
c4b6e17
1677 renaming id
Sneha65 Jul 24, 2024
9130589
Merge branch '1677-LetterSound' of https://github.com/SnehaHS65/webap…
Sneha65 Jul 24, 2024
142d787
1677 to push version 21
Sneha65 Jul 24, 2024
72cc377
1677 to push version 21
Sneha65 Jul 24, 2024
755de06
Merge branch 'main' into pr/1725
jo-elimu Jul 24, 2024
cc010be
chore(db): rename migration script to 2.4.22
jo-elimu Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ai.elimu.dao;

import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.content.LetterSound;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundContributionEvent;
import java.util.List;
Expand All @@ -10,7 +10,7 @@ public interface LetterSoundContributionEventDao extends GenericDao<LetterSoundC

List<LetterSoundContributionEvent> readAllOrderedByTimeDesc() throws DataAccessException;

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

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

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ai/elimu/dao/LetterSoundDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import ai.elimu.model.content.Sound;
import ai.elimu.model.content.Letter;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.content.LetterSound;
import java.util.List;

import org.springframework.dao.DataAccessException;

public interface LetterSoundDao extends GenericDao<LetterSoundCorrespondence> {
public interface LetterSoundDao extends GenericDao<LetterSound> {

LetterSoundCorrespondence read(List<Letter> letters, List<Sound> sounds) throws DataAccessException;
LetterSound read(List<Letter> letters, List<Sound> sounds) throws DataAccessException;

List<LetterSoundCorrespondence> readAllOrderedByUsage() throws DataAccessException;
List<LetterSound> readAllOrderedByUsage() throws DataAccessException;

List<LetterSoundCorrespondence> readAllOrderedByLettersLength() throws DataAccessException;
List<LetterSound> readAllOrderedByLettersLength() throws DataAccessException;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ai.elimu.dao;

import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.LetterSound;
jo-elimu marked this conversation as resolved.
Show resolved Hide resolved
jo-elimu marked this conversation as resolved.
Show resolved Hide resolved
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundContributionEvent;
import ai.elimu.model.contributor.LetterSoundPeerReviewEvent;
Expand All @@ -11,7 +12,7 @@ public interface LetterSoundPeerReviewEventDao extends GenericDao<LetterSoundPee

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ai.elimu.dao.jpa;

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

Expand All @@ -20,7 +20,7 @@ public List<LetterSoundContributionEvent> readAllOrderedByTimeDesc() throws Data
}

@Override
public List<LetterSoundContributionEvent> readAll(LetterSoundCorrespondence letterSound) throws DataAccessException {
public List<LetterSoundContributionEvent> readAll(LetterSound letterSound) throws DataAccessException {
return em.createQuery(
"SELECT e " +
"FROM LetterSoundContributionEvent e " +
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/ai/elimu/dao/jpa/LetterSoundDaoJpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@

import ai.elimu.model.content.Sound;
import ai.elimu.model.content.Letter;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.content.LetterSound;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.dao.DataAccessException;
import ai.elimu.dao.LetterSoundDao;

public class LetterSoundDaoJpa extends GenericDaoJpa<LetterSoundCorrespondence> implements LetterSoundDao {
public class LetterSoundDaoJpa extends GenericDaoJpa<LetterSound> implements LetterSoundDao {

@Override
public LetterSoundCorrespondence read(List<Letter> letters, List<Sound> sounds) throws DataAccessException {
public LetterSound read(List<Letter> letters, List<Sound> sounds) throws DataAccessException {
// TODO: implement usage of CriteriaQuery/CriteriaQuery

String letterSoundCorrespondenceLetters = letters.stream().map(Letter::getText).collect(Collectors.joining());
String letterSoundCorrespondenceSounds = sounds.stream().map(Sound::getValueIpa).collect(Collectors.joining());
for (LetterSoundCorrespondence letterSoundCorrespondence : readAllOrderedByUsage()) {
String lettersAsString = letterSoundCorrespondence.getLetters().stream().map(Letter::getText).collect(Collectors.joining());
String soundsAsString = letterSoundCorrespondence.getSounds().stream().map(Sound::getValueIpa).collect(Collectors.joining());
if (lettersAsString.equals(letterSoundCorrespondenceLetters) && soundsAsString.equals(letterSoundCorrespondenceSounds)) {
return letterSoundCorrespondence;
String letterSoundLetters = letters.stream().map(Letter::getText).collect(Collectors.joining());
String letterSoundSounds = sounds.stream().map(Sound::getValueIpa).collect(Collectors.joining());
for (LetterSound letterSound : readAllOrderedByUsage()) {
String lettersAsString = letterSound.getLetters().stream().map(Letter::getText).collect(Collectors.joining());
String soundsAsString = letterSound.getSounds().stream().map(Sound::getValueIpa).collect(Collectors.joining());
if (lettersAsString.equals(letterSoundLetters) && soundsAsString.equals(letterSoundSounds)) {
return letterSound;
}
}

return null;
}

@Override
public List<LetterSoundCorrespondence> readAllOrderedByUsage() throws DataAccessException {
public List<LetterSound> readAllOrderedByUsage() throws DataAccessException {
return em.createQuery(
"SELECT lsc " +
"FROM LetterSoundCorrespondence lsc " +
"FROM LetterSound lsc " +
"ORDER BY lsc.usageCount DESC")
.getResultList();
}

@Override
public List<LetterSoundCorrespondence> readAllOrderedByLettersLength() throws DataAccessException {
public List<LetterSound> readAllOrderedByLettersLength() throws DataAccessException {
return em.createQuery(
"SELECT lsc " +
"FROM LetterSoundCorrespondence lsc " +
"FROM LetterSound lsc " +
"ORDER BY lsc.letters.size DESC, lsc.usageCount DESC")
.getResultList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ai.elimu.dao.jpa;

import ai.elimu.dao.LetterSoundPeerReviewEventDao;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.content.LetterSound;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterSoundContributionEvent;
import ai.elimu.model.contributor.LetterSoundPeerReviewEvent;
Expand All @@ -24,7 +24,7 @@ public List<LetterSoundPeerReviewEvent> readAll(LetterSoundContributionEvent let
}

@Override
public List<LetterSoundPeerReviewEvent> readAll(LetterSoundCorrespondence letterSound) throws DataAccessException {
public List<LetterSoundPeerReviewEvent> readAll(LetterSound letterSound) throws DataAccessException {
return em.createQuery(
"SELECT event " +
"FROM LetterSoundPeerReviewEvent event " +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ai.elimu.logic.converters;

import org.apache.commons.lang.StringUtils;
import ai.elimu.model.content.LetterSound;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import ai.elimu.dao.LetterSoundDao;

public class StringToLetterSoundConverter implements Converter<String, LetterSound> {

@Autowired
private LetterSoundDao letterSoundDao;

/**
* Convert LetterSound id to LetterSound entity
*/
public LetterSound convert(String id) {
if (StringUtils.isBlank(id)) {
return null;
} else {
Long letterSoundId = Long.parseLong(id);
LetterSound letterSound = letterSoundDao.read(letterSoundId);
return letterSound;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Contains information about the various sounds a letter (or letter combination) can represent.
*/
@Entity
public class LetterSoundCorrespondence extends Content {
public class LetterSound extends Content {

// @NotEmpty
@OrderColumn
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/ai/elimu/model/content/Word.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
@Entity
public class Word extends Content {

@Deprecated // TODO: replace with list of LetterSoundCorrespondences
@Deprecated // TODO: replace with list of letterSounds
@NotNull
private String text;

@NotEmpty
@OrderColumn
@ManyToMany(fetch = FetchType.EAGER)
private List<LetterSoundCorrespondence> letterSounds;
private List<LetterSound> letterSounds;

/**
* As an example, the verb "reading" will be linked to the root verb "read".
Expand All @@ -48,11 +48,11 @@ public void setText(String text) {
this.text = text;
}

public List<LetterSoundCorrespondence> getLetterSounds() {
public List<LetterSound> getLetterSounds() {
return letterSounds;
}

public void setLetterSounds(List<LetterSoundCorrespondence> letterSounds) {
public void setLetterSounds(List<LetterSound> letterSounds) {
this.letterSounds = letterSounds;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ai.elimu.model.contributor;

import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.content.LetterSound;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
Expand All @@ -10,13 +10,13 @@ public class LetterSoundContributionEvent extends ContributionEvent {

@NotNull
@ManyToOne
private LetterSoundCorrespondence letterSound;
private LetterSound letterSound;

public LetterSoundCorrespondence getLetterSound() {
public LetterSound getLetterSound() {
return letterSound;
}

public void setLetterSound(LetterSoundCorrespondence letterSound) {
public void setLetterSound(LetterSound letterSound) {
this.letterSound = letterSound;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import javax.validation.constraints.NotNull;

/**
* An event where a {@link Contributor} peer-reviews a {@link LetterSoundCorrespondence} which
* An event where a {@link Contributor} peer-reviews a {@link LetterSound} which
* was added/edited by another {@link Contributor}.
*/
@Entity
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ai/elimu/rest/v2/JpaToGsonConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ai.elimu.model.content.Sound;
import ai.elimu.model.content.Emoji;
import ai.elimu.model.content.Letter;
import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.content.LetterSound;
import ai.elimu.model.content.StoryBook;
import ai.elimu.model.content.StoryBookChapter;
import ai.elimu.model.content.StoryBookParagraph;
Expand Down Expand Up @@ -82,7 +82,7 @@ public static SoundGson getSoundGson(Sound sound) {
}
}

public static LetterSoundGson getLetterSoundGson(LetterSoundCorrespondence letterSound) {
public static LetterSoundGson getLetterSoundGson(LetterSound letterSound) {
if (letterSound == null) {
return null;
} else {
Expand Down Expand Up @@ -129,7 +129,7 @@ public static WordGson getWordGson(Word word) {
// Word
wordGson.setText(word.getText());
List<LetterSoundGson> letterSounds = new ArrayList<>();
for (LetterSoundCorrespondence letterSound : word.getLetterSounds()) {
for (LetterSound letterSound : word.getLetterSounds()) {
LetterSoundGson letterSoundGson = getLetterSoundGson(letterSound);
letterSounds.add(letterSoundGson);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ai.elimu.rest.v2.content;

import ai.elimu.model.content.LetterSoundCorrespondence;
import ai.elimu.model.content.LetterSound;
import ai.elimu.model.v2.gson.content.LetterSoundGson;
import ai.elimu.rest.v2.JpaToGsonConverter;
import com.google.gson.Gson;
Expand Down Expand Up @@ -29,7 +29,7 @@ public String handleGetRequest() {
logger.info("handleGetRequest");

JSONArray letterSoundsJsonArray = new JSONArray();
for (LetterSoundCorrespondence letterSound : letterSoundDao.readAllOrderedByUsage()) {
for (LetterSound letterSound : letterSoundDao.readAllOrderedByUsage()) {
LetterSoundGson letterSoundGson = JpaToGsonConverter.getLetterSoundGson(letterSound);
String json = new Gson().toJson(letterSoundGson);
letterSoundsJsonArray.put(new JSONObject(json));
Expand Down

This file was deleted.

Loading