Search in sources :

Example 6 with DynamicQuery

use of com.liferay.portal.kernel.dao.orm.DynamicQuery in project liferay-ide by liferay.

the class RosterPersistenceTest method testDynamicQueryByPrimaryKeyMissing.

@Test
public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Roster.class, _dynamicQueryClassLoader);
    dynamicQuery.add(RestrictionsFactoryUtil.eq("rosterId", RandomTestUtil.nextLong()));
    List<Roster> result = _persistence.findWithDynamicQuery(dynamicQuery);
    Assert.assertEquals(0, result.size());
}
Also used : Roster(com.liferay.roster.model.Roster) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) Test(org.junit.Test)

Example 7 with DynamicQuery

use of com.liferay.portal.kernel.dao.orm.DynamicQuery in project liferay-ide by liferay.

the class ArtistIndexer method reindexEntries.

protected void reindexEntries(long companyId) throws PortalException, SystemException {
    final Collection<Document> documents = new ArrayList<Document>();
    ActionableDynamicQuery actionableDynamicQuery = new ArtistActionableDynamicQuery() {

        @Override
        protected void addCriteria(DynamicQuery dynamicQuery) {
        }

        @Override
        protected void performAction(Object object) throws PortalException {
            Artist artist = (Artist) object;
            Document document = getDocument(artist);
            documents.add(document);
        }
    };
    actionableDynamicQuery.setCompanyId(companyId);
    actionableDynamicQuery.performActions();
    SearchEngineUtil.updateDocuments(getSearchEngineId(), companyId, documents);
}
Also used : Artist(org.liferay.jukebox.model.Artist) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) ArtistActionableDynamicQuery(org.liferay.jukebox.service.persistence.ArtistActionableDynamicQuery) ArrayList(java.util.ArrayList) ArtistActionableDynamicQuery(org.liferay.jukebox.service.persistence.ArtistActionableDynamicQuery) Document(com.liferay.portal.kernel.search.Document) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) ArtistActionableDynamicQuery(org.liferay.jukebox.service.persistence.ArtistActionableDynamicQuery)

Example 8 with DynamicQuery

use of com.liferay.portal.kernel.dao.orm.DynamicQuery in project liferay-ide by liferay.

the class KBArticleLocalServiceImpl method buildDynamicQuery.

protected DynamicQuery buildDynamicQuery(long groupId, String title, String content, int status, Date startDate, Date endDate, boolean andOperator) {
    Junction junction = null;
    if (andOperator) {
        junction = RestrictionsFactoryUtil.conjunction();
    } else {
        junction = RestrictionsFactoryUtil.disjunction();
    }
    Map<String, String> terms = new HashMap<String, String>();
    if (Validator.isNotNull(title)) {
        terms.put("title", title);
    }
    if (Validator.isNotNull(content)) {
        terms.put("content", content);
    }
    for (Map.Entry<String, String> entry : terms.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        Disjunction disjunction = RestrictionsFactoryUtil.disjunction();
        for (String keyword : KnowledgeBaseUtil.splitKeywords(value)) {
            Criterion criterion = RestrictionsFactoryUtil.ilike(key, StringUtil.quote(keyword, StringPool.PERCENT));
            disjunction.add(criterion);
        }
        junction.add(disjunction);
    }
    if (status != WorkflowConstants.STATUS_ANY) {
        Property property = PropertyFactoryUtil.forName("status");
        junction.add(property.eq(status));
    }
    if ((endDate != null) && (startDate != null)) {
        Disjunction disjunction = RestrictionsFactoryUtil.disjunction();
        String[] propertyNames = { "createDate", "modifiedDate" };
        for (String propertyName : propertyNames) {
            Property property = PropertyFactoryUtil.forName(propertyName);
            Conjunction conjunction = RestrictionsFactoryUtil.conjunction();
            conjunction.add(property.gt(startDate));
            conjunction.add(property.lt(endDate));
            disjunction.add(conjunction);
        }
        junction.add(disjunction);
    }
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(KBArticle.class, getClassLoader());
    if (status == WorkflowConstants.STATUS_ANY) {
        Property property = PropertyFactoryUtil.forName("latest");
        dynamicQuery.add(property.eq(Boolean.TRUE));
    } else if (status == WorkflowConstants.STATUS_APPROVED) {
        Property property = PropertyFactoryUtil.forName("main");
        dynamicQuery.add(property.eq(Boolean.TRUE));
    }
    if (groupId > 0) {
        Property property = PropertyFactoryUtil.forName("groupId");
        dynamicQuery.add(property.eq(groupId));
    }
    return dynamicQuery.add(junction);
}
Also used : Disjunction(com.liferay.portal.kernel.dao.orm.Disjunction) HashMap(java.util.HashMap) Criterion(com.liferay.portal.kernel.dao.orm.Criterion) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) Conjunction(com.liferay.portal.kernel.dao.orm.Conjunction) Junction(com.liferay.portal.kernel.dao.orm.Junction) Map(java.util.Map) HashMap(java.util.HashMap) Property(com.liferay.portal.kernel.dao.orm.Property)

Example 9 with DynamicQuery

use of com.liferay.portal.kernel.dao.orm.DynamicQuery in project liferay-ide by liferay.

the class KBTemplateLocalServiceImpl method buildDynamicQuery.

protected DynamicQuery buildDynamicQuery(long groupId, String title, String content, Date startDate, Date endDate, boolean andOperator) {
    Junction junction = null;
    if (andOperator) {
        junction = RestrictionsFactoryUtil.conjunction();
    } else {
        junction = RestrictionsFactoryUtil.disjunction();
    }
    Map<String, String> terms = new HashMap<String, String>();
    if (Validator.isNotNull(title)) {
        terms.put("title", title);
    }
    if (Validator.isNotNull(content)) {
        terms.put("content", content);
    }
    for (Map.Entry<String, String> entry : terms.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        Disjunction disjunction = RestrictionsFactoryUtil.disjunction();
        for (String keyword : KnowledgeBaseUtil.splitKeywords(value)) {
            Criterion criterion = RestrictionsFactoryUtil.ilike(key, StringUtil.quote(keyword, StringPool.PERCENT));
            disjunction.add(criterion);
        }
        junction.add(disjunction);
    }
    if ((endDate != null) && (startDate != null)) {
        Disjunction disjunction = RestrictionsFactoryUtil.disjunction();
        String[] propertyNames = { "createDate", "modifiedDate" };
        for (String propertyName : propertyNames) {
            Property property = PropertyFactoryUtil.forName(propertyName);
            Conjunction conjunction = RestrictionsFactoryUtil.conjunction();
            conjunction.add(property.gt(startDate));
            conjunction.add(property.lt(endDate));
            disjunction.add(conjunction);
        }
        junction.add(disjunction);
    }
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(KBTemplate.class, getClassLoader());
    if (groupId > 0) {
        Property property = PropertyFactoryUtil.forName("groupId");
        dynamicQuery.add(property.eq(groupId));
    }
    return dynamicQuery.add(junction);
}
Also used : Disjunction(com.liferay.portal.kernel.dao.orm.Disjunction) HashMap(java.util.HashMap) Criterion(com.liferay.portal.kernel.dao.orm.Criterion) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) Conjunction(com.liferay.portal.kernel.dao.orm.Conjunction) Junction(com.liferay.portal.kernel.dao.orm.Junction) HashMap(java.util.HashMap) Map(java.util.Map) Property(com.liferay.portal.kernel.dao.orm.Property)

Example 10 with DynamicQuery

use of com.liferay.portal.kernel.dao.orm.DynamicQuery in project liferay-ide by liferay.

the class AdminIndexer method reindexKBArticles.

protected void reindexKBArticles(long companyId) throws Exception {
    ActionableDynamicQuery actionableDynamicQuery = new KBArticleActionableDynamicQuery() {

        @Override
        protected void addCriteria(DynamicQuery dynamicQuery) {
            Property property = PropertyFactoryUtil.forName("status");
            dynamicQuery.add(property.eq(WorkflowConstants.STATUS_APPROVED));
        }

        @Override
        protected void performAction(Object object) throws PortalException {
            KBArticle kbArticle = (KBArticle) object;
            Document document = getDocument(kbArticle);
            addDocument(document);
        }
    };
    actionableDynamicQuery.setCompanyId(companyId);
    actionableDynamicQuery.setSearchEngineId(getSearchEngineId());
    actionableDynamicQuery.performActions();
}
Also used : KBArticle(com.liferay.knowledgebase.model.KBArticle) KBArticleActionableDynamicQuery(com.liferay.knowledgebase.service.persistence.KBArticleActionableDynamicQuery) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) KBArticleActionableDynamicQuery(com.liferay.knowledgebase.service.persistence.KBArticleActionableDynamicQuery) Document(com.liferay.portal.kernel.search.Document) Property(com.liferay.portal.kernel.dao.orm.Property) KBArticleActionableDynamicQuery(com.liferay.knowledgebase.service.persistence.KBArticleActionableDynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)

Aggregations

DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)23 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)21 Test (org.junit.Test)16 Foo (com.liferay.blade.samples.servicebuilder.model.Foo)4 Property (com.liferay.portal.kernel.dao.orm.Property)3 Document (com.liferay.portal.kernel.search.Document)3 Club (com.liferay.roster.model.Club)3 Roster (com.liferay.roster.model.Roster)3 RosterMember (com.liferay.roster.model.RosterMember)3 Conjunction (com.liferay.portal.kernel.dao.orm.Conjunction)2 Criterion (com.liferay.portal.kernel.dao.orm.Criterion)2 Disjunction (com.liferay.portal.kernel.dao.orm.Disjunction)2 Junction (com.liferay.portal.kernel.dao.orm.Junction)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ManifestSummary (com.liferay.exportimport.kernel.lar.ManifestSummary)1 StagedModelType (com.liferay.exportimport.kernel.lar.StagedModelType)1 KBArticle (com.liferay.knowledgebase.model.KBArticle)1 KBArticleActionableDynamicQuery (com.liferay.knowledgebase.service.persistence.KBArticleActionableDynamicQuery)1