Search in sources :

Example 1 with PropertyFilter

use of org.b3log.latke.repository.PropertyFilter in project solo by b3log.

the class PageRepositoryImpl method getByPermalink.

@Override
public JSONObject getByPermalink(final String permalink) throws RepositoryException {
    final Query query = new Query().setFilter(new PropertyFilter(Page.PAGE_PERMALINK, FilterOperator.EQUAL, permalink)).setPageCount(1);
    final JSONObject result = get(query);
    final JSONArray array = result.optJSONArray(Keys.RESULTS);
    if (0 == array.length()) {
        return null;
    }
    return array.optJSONObject(0);
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter)

Example 2 with PropertyFilter

use of org.b3log.latke.repository.PropertyFilter in project solo by b3log.

the class UserRepositoryImpl method getByEmail.

@Override
public JSONObject getByEmail(final String email) throws RepositoryException {
    final Query query = new Query().setPageCount(1);
    query.setFilter(new PropertyFilter(User.USER_EMAIL, FilterOperator.EQUAL, email.toLowerCase().trim()));
    final JSONObject result = get(query);
    final JSONArray array = result.optJSONArray(Keys.RESULTS);
    if (0 == array.length()) {
        return null;
    }
    return array.optJSONObject(0);
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter)

Example 3 with PropertyFilter

use of org.b3log.latke.repository.PropertyFilter in project solo by b3log.

the class UserRepositoryImplTestCase method test.

/**
     * Tests.
     * 
     * @throws Exception exception
     */
@Test
public void test() throws Exception {
    final UserRepository userRepository = getUserRepository();
    final JSONObject another = new JSONObject();
    another.put(User.USER_NAME, "test1");
    another.put(User.USER_EMAIL, "test1@gmail.com");
    another.put(User.USER_PASSWORD, "pass1");
    another.put(User.USER_URL, "http://b3log.org");
    another.put(User.USER_ROLE, Role.DEFAULT_ROLE);
    another.put(UserExt.USER_ARTICLE_COUNT, 0);
    another.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
    another.put(UserExt.USER_AVATAR, "");
    Transaction transaction = userRepository.beginTransaction();
    userRepository.add(another);
    transaction.commit();
    Assert.assertNull(userRepository.getAdmin());
    JSONObject admin = new JSONObject();
    admin.put(User.USER_NAME, "test");
    admin.put(User.USER_EMAIL, "test@gmail.com");
    admin.put(User.USER_PASSWORD, "pass");
    admin.put(User.USER_URL, "http://b3log.org");
    admin.put(User.USER_ROLE, Role.ADMIN_ROLE);
    admin.put(UserExt.USER_ARTICLE_COUNT, 0);
    admin.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
    admin.put(UserExt.USER_AVATAR, "");
    transaction = userRepository.beginTransaction();
    userRepository.add(admin);
    transaction.commit();
    Assert.assertTrue(userRepository.isAdminEmail("test@gmail.com"));
    Assert.assertFalse(userRepository.isAdminEmail("notFound@gmail.com"));
    admin = userRepository.getAdmin();
    Assert.assertNotNull(admin);
    Assert.assertEquals("test", admin.optString(User.USER_NAME));
    final JSONObject result = userRepository.get(new Query().setFilter(new PropertyFilter(User.USER_NAME, FilterOperator.EQUAL, "test1")));
    final JSONArray users = result.getJSONArray(Keys.RESULTS);
    Assert.assertEquals(users.length(), 1);
    Assert.assertEquals(users.getJSONObject(0).getString(User.USER_EMAIL), "test1@gmail.com");
    final JSONObject notFound = userRepository.getByEmail("not.found@gmail.com");
    Assert.assertNull(notFound);
    final JSONObject found = userRepository.getByEmail("test1@gmail.com");
    Assert.assertNotNull(found);
    Assert.assertEquals(found.getString(User.USER_PASSWORD), "pass1");
}
Also used : UserRepository(org.b3log.solo.repository.UserRepository) JSONObject(org.json.JSONObject) Transaction(org.b3log.latke.repository.Transaction) Query(org.b3log.latke.repository.Query) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter) Test(org.testng.annotations.Test)

Example 4 with PropertyFilter

use of org.b3log.latke.repository.PropertyFilter in project solo by b3log.

the class ArchiveDateArticleRepositoryImpl method getByArticleId.

@Override
public JSONObject getByArticleId(final String articleId) throws RepositoryException {
    final Query query = new Query();
    query.setFilter(new PropertyFilter(Article.ARTICLE + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, articleId));
    final JSONObject result = get(query);
    final JSONArray array = result.optJSONArray(Keys.RESULTS);
    if (0 == array.length()) {
        return null;
    }
    return array.optJSONObject(0);
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter)

Example 5 with PropertyFilter

use of org.b3log.latke.repository.PropertyFilter in project solo by b3log.

the class ArchiveDateRepositoryImpl method getByArchiveDate.

@Override
public JSONObject getByArchiveDate(final String archiveDate) throws RepositoryException {
    long time = 0L;
    try {
        time = DateUtils.parseDate(archiveDate, new String[] { "yyyy/MM" }).getTime();
    } catch (final ParseException e) {
        LOGGER.log(Level.ERROR, "Can not parse archive date [" + archiveDate + "]", e);
        throw new RepositoryException("Can not parse archive date [" + archiveDate + "]");
    }
    LOGGER.log(Level.TRACE, "Archive date [{0}] parsed to time [{1}]", new Object[] { archiveDate, time });
    final Query query = new Query();
    query.setFilter(new PropertyFilter(ArchiveDate.ARCHIVE_TIME, FilterOperator.EQUAL, time)).setPageCount(1);
    final JSONObject result = get(query);
    final JSONArray array = result.optJSONArray(Keys.RESULTS);
    if (0 == array.length()) {
        return null;
    }
    return array.optJSONObject(0);
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) RepositoryException(org.b3log.latke.repository.RepositoryException) PropertyFilter(org.b3log.latke.repository.PropertyFilter) ParseException(java.text.ParseException)

Aggregations

PropertyFilter (org.b3log.latke.repository.PropertyFilter)28 Query (org.b3log.latke.repository.Query)28 JSONArray (org.json.JSONArray)28 JSONObject (org.json.JSONObject)28 Date (java.util.Date)5 RepositoryException (org.b3log.latke.repository.RepositoryException)5 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 CompositeFilter (org.b3log.latke.repository.CompositeFilter)2 Filter (org.b3log.latke.repository.Filter)2 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)2 JSONException (org.json.JSONException)2 ParseException (java.text.ParseException)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Transaction (org.b3log.latke.repository.Transaction)1 ServiceException (org.b3log.latke.service.ServiceException)1 AtomRenderer (org.b3log.latke.servlet.renderer.AtomRenderer)1 RssRenderer (org.b3log.latke.servlet.renderer.RssRenderer)1 ArchiveDate (org.b3log.solo.model.ArchiveDate)1 Entry (org.b3log.solo.model.feed.atom.Entry)1