Search in sources :

Example 1 with ConceptStopWord

use of org.openmrs.ConceptStopWord in project openmrs-core by openmrs.

the class HibernateConceptDAO method saveConceptStopWord.

/**
 * @see org.openmrs.api.db.ConceptDAO#saveConceptStopWord(org.openmrs.ConceptStopWord)
 */
@Override
public ConceptStopWord saveConceptStopWord(ConceptStopWord conceptStopWord) throws DAOException {
    if (conceptStopWord != null) {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptStopWord.class);
        criteria.add(Restrictions.eq("value", conceptStopWord.getValue()));
        criteria.add(Restrictions.eq("locale", conceptStopWord.getLocale()));
        List<ConceptStopWord> stopWordList = criteria.list();
        if (!stopWordList.isEmpty()) {
            throw new DAOException("Duplicate ConceptStopWord Entry");
        }
        sessionFactory.getCurrentSession().saveOrUpdate(conceptStopWord);
    }
    return conceptStopWord;
}
Also used : DAOException(org.openmrs.api.db.DAOException) ConceptStopWord(org.openmrs.ConceptStopWord) Criteria(org.hibernate.Criteria)

Example 2 with ConceptStopWord

use of org.openmrs.ConceptStopWord in project openmrs-core by openmrs.

the class ConceptServiceTest method saveConceptStopWord_shouldSaveConceptStopWordAssignDefaultLocaleIsItNull.

/**
 * @see ConceptService#saveConceptStopWord(ConceptStopWord)
 */
@Test
public void saveConceptStopWord_shouldSaveConceptStopWordAssignDefaultLocaleIsItNull() {
    ConceptStopWord conceptStopWord = new ConceptStopWord("The");
    conceptService.saveConceptStopWord(conceptStopWord);
    List<String> conceptStopWords = conceptService.getConceptStopWords(Context.getLocale());
    assertThat(conceptStopWords, hasItem("THE"));
}
Also used : ConceptStopWord(org.openmrs.ConceptStopWord) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 3 with ConceptStopWord

use of org.openmrs.ConceptStopWord in project openmrs-core by openmrs.

the class ConceptServiceTest method saveConceptStopWord_shouldSaveConceptStopWordIntoDatabase.

/**
 * @see ConceptService#saveConceptStopWord(org.openmrs.ConceptStopWord)
 */
@Test
public void saveConceptStopWord_shouldSaveConceptStopWordIntoDatabase() {
    ConceptStopWord conceptStopWord = new ConceptStopWord("AND", Locale.FRANCE);
    conceptService.saveConceptStopWord(conceptStopWord);
    List<String> conceptStopWords = conceptService.getConceptStopWords(Locale.FRANCE);
    assertEquals(1, conceptStopWords.size());
    assertEquals("AND", conceptStopWords.get(0));
}
Also used : ConceptStopWord(org.openmrs.ConceptStopWord) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 4 with ConceptStopWord

use of org.openmrs.ConceptStopWord in project openmrs-core by openmrs.

the class ConceptServiceTest method saveConceptStopWord_shouldSaveReturnConceptStopWordWithId.

/**
 * @see ConceptService#saveConceptStopWord(ConceptStopWord)
 */
@Test
public void saveConceptStopWord_shouldSaveReturnConceptStopWordWithId() {
    ConceptStopWord conceptStopWord = new ConceptStopWord("A", Locale.UK);
    ConceptStopWord savedConceptStopWord = conceptService.saveConceptStopWord(conceptStopWord);
    assertNotNull(savedConceptStopWord.getId());
}
Also used : ConceptStopWord(org.openmrs.ConceptStopWord) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 5 with ConceptStopWord

use of org.openmrs.ConceptStopWord in project openmrs-core by openmrs.

the class ConceptServiceTest method saveConceptStopWord_shouldSaveConceptStopWordInUppercase.

/**
 * @see ConceptService#saveConceptStopWord(ConceptStopWord)
 */
@Test
public void saveConceptStopWord_shouldSaveConceptStopWordInUppercase() {
    ConceptStopWord conceptStopWord = new ConceptStopWord("lowertoupper");
    ConceptStopWord savedConceptStopWord = conceptService.saveConceptStopWord(conceptStopWord);
    assertEquals("LOWERTOUPPER", savedConceptStopWord.getValue());
}
Also used : ConceptStopWord(org.openmrs.ConceptStopWord) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

ConceptStopWord (org.openmrs.ConceptStopWord)7 Test (org.junit.Test)6 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)6 Locale (java.util.Locale)1 Criteria (org.hibernate.Criteria)1 ConceptSearchResult (org.openmrs.ConceptSearchResult)1 DAOException (org.openmrs.api.db.DAOException)1