use of ai.elimu.model.v2.gson.content.WordGson in project webapp by elimu-ai.
the class WordsRestController method handleGetRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleGetRequest() {
logger.info("handleGetRequest");
JSONArray wordsJsonArray = new JSONArray();
for (Word word : wordDao.readAllOrdered()) {
WordGson wordGson = JpaToGsonConverter.getWordGson(word);
String json = new Gson().toJson(wordGson);
wordsJsonArray.put(new JSONObject(json));
}
String jsonResponse = wordsJsonArray.toString();
logger.info("jsonResponse: " + jsonResponse);
return jsonResponse;
}
use of ai.elimu.model.v2.gson.content.WordGson in project webapp by elimu-ai.
the class JpaToGsonConverter method getStoryBookParagraphGson.
public static StoryBookParagraphGson getStoryBookParagraphGson(StoryBookParagraph storyBookParagraph) {
if (storyBookParagraph == null) {
return null;
} else {
StoryBookParagraphGson storyBookParagraphGson = new StoryBookParagraphGson();
// BaseEntity
storyBookParagraphGson.setId(storyBookParagraph.getId());
// StoryBookParagraph
storyBookParagraphGson.setSortOrder(storyBookParagraph.getSortOrder());
storyBookParagraphGson.setOriginalText(storyBookParagraph.getOriginalText());
List<WordGson> wordGsons = new ArrayList<>();
for (Word word : storyBookParagraph.getWords()) {
WordGson wordGson = null;
if (word != null) {
wordGson = new WordGson();
wordGson.setId(word.getId());
}
wordGsons.add(wordGson);
}
storyBookParagraphGson.setWords(wordGsons);
return storyBookParagraphGson;
}
}
use of ai.elimu.model.v2.gson.content.WordGson in project webapp by elimu-ai.
the class JpaToGsonConverter method getEmojiGson.
public static EmojiGson getEmojiGson(Emoji emoji) {
if (emoji == null) {
return null;
} else {
EmojiGson emojiGson = new EmojiGson();
// BaseEntity
emojiGson.setId(emoji.getId());
// Content
emojiGson.setRevisionNumber(emoji.getRevisionNumber());
emojiGson.setUsageCount(emoji.getUsageCount());
// Emoji
emojiGson.setGlyph(emoji.getGlyph());
emojiGson.setUnicodeVersion(emoji.getUnicodeVersion());
emojiGson.setUnicodeEmojiVersion(emoji.getUnicodeEmojiVersion());
Set<WordGson> wordGsons = new HashSet<>();
for (Word word : emoji.getWords()) {
WordGson wordGson = new WordGson();
wordGson.setId(word.getId());
wordGsons.add(wordGson);
}
emojiGson.setWords(wordGsons);
return emojiGson;
}
}
use of ai.elimu.model.v2.gson.content.WordGson in project webapp by elimu-ai.
the class JpaToGsonConverter method getWordGson.
public static WordGson getWordGson(Word word) {
if (word == null) {
return null;
} else {
WordGson wordGson = new WordGson();
// BaseEntity
wordGson.setId(word.getId());
// Content
wordGson.setRevisionNumber(word.getRevisionNumber());
wordGson.setUsageCount(word.getUsageCount());
// Word
wordGson.setText(word.getText());
List<LetterSoundCorrespondenceGson> letterSoundCorrespondences = new ArrayList<>();
for (LetterSoundCorrespondence letterSoundCorrespondence : word.getLetterSoundCorrespondences()) {
LetterSoundCorrespondenceGson letterSoundCorrespondenceGson = getLetterSoundCorrespondenceGson(letterSoundCorrespondence);
letterSoundCorrespondences.add(letterSoundCorrespondenceGson);
}
wordGson.setLetterSoundCorrespondences(letterSoundCorrespondences);
wordGson.setWordType(word.getWordType());
return wordGson;
}
}
use of ai.elimu.model.v2.gson.content.WordGson in project webapp by elimu-ai.
the class AudioContributionsRestController method getWordsPendingRecording.
/**
* Get {@link Word}s pending {@link Audio} recording for the current {@link Contributor}.
*/
@RequestMapping(value = "/words", method = RequestMethod.GET)
public String getWordsPendingRecording(HttpServletRequest request, HttpServletResponse response) {
logger.info("getWordsPendingRecording");
JSONObject jsonObject = new JSONObject();
// Lookup the Contributor by ID
String providerIdGoogle = request.getHeader("providerIdGoogle");
logger.info("providerIdGoogle: " + providerIdGoogle);
if (StringUtils.isBlank(providerIdGoogle)) {
jsonObject.put("result", "error");
jsonObject.put("errorMessage", "Missing providerIdGoogle");
response.setStatus(HttpStatus.BAD_REQUEST.value());
String jsonResponse = jsonObject.toString();
logger.info("jsonResponse: " + jsonResponse);
return jsonResponse;
}
Contributor contributor = contributorDao.readByProviderIdGoogle(providerIdGoogle);
logger.info("contributor: " + contributor);
if (contributor == null) {
jsonObject.put("result", "error");
jsonObject.put("errorMessage", "The Contributor was not found.");
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
String jsonResponse = jsonObject.toString();
logger.info("jsonResponse: " + jsonResponse);
return jsonResponse;
}
// Get the IDs of Words that have already been recorded by the Contributor
List<AudioContributionEvent> audioContributionEvents = audioContributionEventDao.readAll(contributor);
logger.info("audioContributionEvents.size(): " + audioContributionEvents.size());
HashMap<Long, Void> idsOfRecordedWordsHashMap = new HashMap<>();
for (AudioContributionEvent audioContributionEvent : audioContributionEvents) {
Audio audio = audioContributionEvent.getAudio();
Word word = audio.getWord();
if (word != null) {
idsOfRecordedWordsHashMap.put(word.getId(), null);
}
}
logger.info("idsOfRecordedWordsHashMap.size(): " + idsOfRecordedWordsHashMap.size());
// For each Word, check if the Contributor has already contributed a
// corresponding Audio recording. If not, add it to the list of pending recordings.
List<Word> wordsPendingAudioRecording = new ArrayList<>();
for (Word word : wordDao.readAllOrderedByUsage()) {
if (!idsOfRecordedWordsHashMap.containsKey(word.getId())) {
wordsPendingAudioRecording.add(word);
}
}
logger.info("wordsPendingAudioRecording.size(): " + wordsPendingAudioRecording.size());
// Convert to JSON
JSONArray wordsJsonArray = new JSONArray();
for (Word word : wordsPendingAudioRecording) {
WordGson wordGson = JpaToGsonConverter.getWordGson(word);
String json = new Gson().toJson(wordGson);
wordsJsonArray.put(new JSONObject(json));
}
String jsonResponse = wordsJsonArray.toString();
logger.info("jsonResponse: " + jsonResponse);
return jsonResponse;
}
Aggregations