Search in sources :

Example 36 with Contributor

use of ai.elimu.model.contributor.Contributor in project webapp by elimu-ai.

the class EditNameController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @RequestParam String firstName, @RequestParam String lastName, Model model) {
    logger.info("handleSubmit");
    logger.info("firstName: " + firstName);
    logger.info("lastName: " + lastName);
    // TODO: validate firstName/lastName
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    contributor.setFirstName(firstName);
    contributor.setLastName(lastName);
    contributorDao.update(contributor);
    session.setAttribute("contributor", contributor);
    return "redirect:/content";
}
Also used : Contributor(ai.elimu.model.contributor.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with Contributor

use of ai.elimu.model.contributor.Contributor in project webapp by elimu-ai.

the class WordContributionEventDaoTest method testReadMostRecent.

@Test
public void testReadMostRecent() {
    List<WordContributionEvent> wordContributionEvents = wordContributionEventDao.readMostRecent(10);
    assertThat(wordContributionEvents.isEmpty(), is(true));
    Contributor contributor = new Contributor();
    contributorDao.create(contributor);
    Word word = new Word();
    wordDao.create(word);
    WordContributionEvent wordContributionEvent = new WordContributionEvent();
    wordContributionEvent.setContributor(contributor);
    wordContributionEvent.setWord(word);
    wordContributionEvent.setRevisionNumber(word.getRevisionNumber());
    wordContributionEvent.setTime(Calendar.getInstance());
    wordContributionEvent.setTimeSpentMs(10_000L);
    wordContributionEventDao.create(wordContributionEvent);
    wordContributionEvents = wordContributionEventDao.readMostRecent(10);
    assertThat(wordContributionEvents.isEmpty(), is(false));
    assertThat(wordContributionEvents.size(), is(1));
    // Clean up content stored in the database, so that it won't affect the other tests
    wordContributionEventDao.delete(wordContributionEvent);
}
Also used : Word(ai.elimu.model.content.Word) Contributor(ai.elimu.model.contributor.Contributor) WordContributionEvent(ai.elimu.model.contributor.WordContributionEvent) Test(org.junit.Test)

Example 38 with Contributor

use of ai.elimu.model.contributor.Contributor in project webapp by elimu-ai.

the class WordContributionEventDaoTest method testReadMostRecentPerWord.

@Test
public void testReadMostRecentPerWord() {
    List<WordContributionEvent> wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
    assertThat(wordContributionEvents.isEmpty(), is(true));
    Contributor contributor1 = new Contributor();
    contributorDao.create(contributor1);
    Word word1 = new Word();
    wordDao.create(word1);
    WordContributionEvent wordContributionEvent1 = new WordContributionEvent();
    wordContributionEvent1.setContributor(contributor1);
    wordContributionEvent1.setWord(word1);
    wordContributionEvent1.setRevisionNumber(word1.getRevisionNumber());
    wordContributionEvent1.setTime(Calendar.getInstance());
    wordContributionEvent1.setTimeSpentMs(10_000L);
    wordContributionEventDao.create(wordContributionEvent1);
    wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
    assertThat(wordContributionEvents.isEmpty(), is(false));
    assertThat(wordContributionEvents.size(), is(1));
    assertThat(wordContributionEvents.get(0).getWord().getId(), is(wordContributionEvent1.getWord().getId()));
    Word word2 = new Word();
    wordDao.create(word2);
    WordContributionEvent wordContributionEvent2 = new WordContributionEvent();
    wordContributionEvent2.setContributor(contributor1);
    wordContributionEvent2.setWord(word2);
    wordContributionEvent2.setRevisionNumber(word2.getRevisionNumber());
    wordContributionEvent2.setTime(Calendar.getInstance());
    wordContributionEvent2.setTimeSpentMs(10_000L);
    wordContributionEventDao.create(wordContributionEvent2);
    wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
    assertThat(wordContributionEvents.isEmpty(), is(false));
    assertThat(wordContributionEvents.size(), is(2));
    assertThat(wordContributionEvents.get(0).getWord().getId(), is(wordContributionEvent1.getWord().getId()));
    assertThat(wordContributionEvents.get(1).getWord().getId(), is(wordContributionEvent2.getWord().getId()));
    // Re-use a word (word2) that was used in a previous contribution event
    WordContributionEvent wordContributionEvent3 = new WordContributionEvent();
    wordContributionEvent3.setContributor(contributor1);
    wordContributionEvent3.setWord(word2);
    wordContributionEvent3.setRevisionNumber(word2.getRevisionNumber());
    wordContributionEvent3.setTime(Calendar.getInstance());
    wordContributionEvent3.setTimeSpentMs(10_000L);
    wordContributionEventDao.create(wordContributionEvent3);
    // The number of contribution events returned should not increase
    wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
    assertThat(wordContributionEvents.isEmpty(), is(false));
    assertThat(wordContributionEvents.size(), is(2));
    assertThat(wordContributionEvents.get(0).getWord().getId(), is(wordContributionEvent1.getWord().getId()));
    assertThat(wordContributionEvents.get(1).getWord().getId(), is(wordContributionEvent3.getWord().getId()));
    // Clean up content stored in the database, so that it won't affect the other tests
    wordContributionEventDao.delete(wordContributionEvent1);
    wordContributionEventDao.delete(wordContributionEvent2);
    wordContributionEventDao.delete(wordContributionEvent3);
}
Also used : Word(ai.elimu.model.content.Word) Contributor(ai.elimu.model.contributor.Contributor) WordContributionEvent(ai.elimu.model.contributor.WordContributionEvent) Test(org.junit.Test)

Aggregations

Contributor (ai.elimu.model.contributor.Contributor)38 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)32 StoryBookContributionEvent (ai.elimu.model.contributor.StoryBookContributionEvent)10 WordContributionEvent (ai.elimu.model.contributor.WordContributionEvent)8 ArrayList (java.util.ArrayList)8 JSONObject (org.json.JSONObject)8 StoryBook (ai.elimu.model.content.StoryBook)7 Word (ai.elimu.model.content.Word)7 Audio (ai.elimu.model.content.multimedia.Audio)6 AudioContributionEvent (ai.elimu.model.contributor.AudioContributionEvent)6 NumberContributionEvent (ai.elimu.model.contributor.NumberContributionEvent)5 HashMap (java.util.HashMap)5 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)4 Gson (com.google.gson.Gson)4 LetterSoundCorrespondence (ai.elimu.model.content.LetterSoundCorrespondence)3 AudioPeerReviewEvent (ai.elimu.model.contributor.AudioPeerReviewEvent)3 LetterSoundCorrespondenceContributionEvent (ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 Letter (ai.elimu.model.content.Letter)2