My use case is create a custom portlet to show the latest web content and filter by journal article type. It will require to join 2 tables with journalarticle and journalcontentsearch for filter the content. I will show my partial code to join 2 table by uysing liferay dynamic query.
-
{
-
-
-
try {
-
-
DynamicQuery dquery = DynamicQueryFactoryUtil.forClass(
-
JournalContentSearch.class, "journalcontentsearch")
-
.setProjection(ProjectionFactoryUtil.property("articleId"));
-
-
DynamicQuery query = DynamicQueryFactoryUtil.forClass(
-
JournalArticle.class, "journalarticle")
-
-
.add(PropertyFactoryUtil.forName("journalarticle.articleId").in(dquery))
-
.add(PropertyFactoryUtil.forName("journalarticle.companyId")
-
.eq(themeDisplay.getCompanyId()))
-
.add(PropertyFactoryUtil.forName("journalarticle.groupId")
-
.eq(themeDisplay.getScopeGroupId()))
-
.add(PropertyFactoryUtil.forName("journalarticle.type")
-
.eq(config.getType()))
-
.add(PropertyFactoryUtil.forName("journalarticle.approved")
-
.addOrder(OrderFactoryUtil.desc("createDate"));
-
-
if(articles.size() > 0) {
-
JournalArticle article = null;
-
ArticleContent content= null;
-
-
-
article = (JournalArticle)obj;
-
-
content= parseArticle(article, "en_US");
-
-
if(content!= null) {
-
list.add(contentItem);
-
}
-
}
-
}
-
-
if(log.isErrorEnabled()){
-
log.error(e.getMessage());
-
}
-
}
-
-
return list;
-
-
ArticleContent
Parse method
-
-
public ArticleContent parseArticle(JournalArticle journalArticle, String locale) throws PortalException, SystemException {
-
-
ArticleContent item = null;
-
try
-
-
item.setDisplayDate(sdf.format(journalArticle.getDisplayDate()));
-
item.setPublishDate(journalArticle.getDisplayDate());
-
-
}
-
catch (DocumentException e) {
-
log.error("Error parsing the structure. ",e);
-
}
-
catch (InvalidArticleTypeException e)
-
{
-
log.error("Error parsing the structure. ",e);
-
}
-
return item;
-
}
-

Posted in 


