mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Refactor out the common entity and factory parts of the Calendar and Blog canned queries
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29436 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -24,132 +24,26 @@ import java.util.List;
|
||||
|
||||
import org.alfresco.model.BlogIntegrationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.AbstractCannedQueryFactory;
|
||||
import org.alfresco.query.CannedQueryPageDetails;
|
||||
import org.alfresco.query.CannedQuerySortDetails;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
||||
import org.alfresco.repo.domain.node.NodeDAO;
|
||||
import org.alfresco.repo.domain.qname.QNameDAO;
|
||||
import org.alfresco.repo.domain.query.CannedQueryDAO;
|
||||
import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityBean;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.repo.query.AbstractQNameAwareCannedQueryFactory;
|
||||
import org.alfresco.service.cmr.blog.BlogService.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Neil Mc Erlean, janv
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class AbstractBlogPostsCannedQueryFactory extends AbstractCannedQueryFactory<BlogPostInfo>
|
||||
public abstract class AbstractBlogPostsCannedQueryFactory extends AbstractQNameAwareCannedQueryFactory<BlogPostInfo>
|
||||
{
|
||||
private Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
protected MethodSecurityBean<BlogPostInfo> methodSecurity;
|
||||
protected NodeDAO nodeDAO;
|
||||
protected QNameDAO qnameDAO;
|
||||
protected CannedQueryDAO cannedQueryDAO;
|
||||
protected TenantService tenantService;
|
||||
|
||||
public void setNodeDAO(NodeDAO nodeDAO)
|
||||
{
|
||||
this.nodeDAO = nodeDAO;
|
||||
}
|
||||
|
||||
public void setQnameDAO(QNameDAO qnameDAO)
|
||||
{
|
||||
this.qnameDAO = qnameDAO;
|
||||
}
|
||||
|
||||
public void setCannedQueryDAO(CannedQueryDAO cannedQueryDAO)
|
||||
{
|
||||
this.cannedQueryDAO = cannedQueryDAO;
|
||||
}
|
||||
|
||||
public void setTenantService(TenantService tenantService)
|
||||
{
|
||||
this.tenantService = tenantService;
|
||||
}
|
||||
|
||||
public void setMethodSecurity(MethodSecurityBean<BlogPostInfo> methodSecurity)
|
||||
{
|
||||
this.methodSecurity = methodSecurity;
|
||||
}
|
||||
|
||||
protected CannedQuerySortDetails createCQSortDetails(QName sortProp, SortOrder sortOrder)
|
||||
{
|
||||
List<Pair<? extends Object, SortOrder>> singlePair = new ArrayList<Pair<? extends Object, SortOrder>>(1);
|
||||
singlePair.add(new Pair<QName, SortOrder>(sortProp, sortOrder));
|
||||
|
||||
return this.createCQSortDetails(singlePair);
|
||||
}
|
||||
|
||||
protected CannedQuerySortDetails createCQSortDetails(List<Pair<? extends Object, SortOrder>> sortPairs)
|
||||
{
|
||||
CannedQuerySortDetails cqsd = new CannedQuerySortDetails(sortPairs);
|
||||
return cqsd;
|
||||
}
|
||||
|
||||
protected CannedQueryPageDetails createCQPageDetails(PagingRequest pagingReq)
|
||||
{
|
||||
int skipCount = pagingReq.getSkipCount();
|
||||
if (skipCount == -1)
|
||||
{
|
||||
skipCount = CannedQueryPageDetails.DEFAULT_SKIP_RESULTS;
|
||||
}
|
||||
|
||||
int maxItems = pagingReq.getMaxItems();
|
||||
if (maxItems == -1)
|
||||
{
|
||||
maxItems = CannedQueryPageDetails.DEFAULT_PAGE_SIZE;
|
||||
}
|
||||
|
||||
// page details
|
||||
CannedQueryPageDetails cqpd = new CannedQueryPageDetails(skipCount, maxItems);
|
||||
return cqpd;
|
||||
}
|
||||
|
||||
protected Long getQNameId(QName qname)
|
||||
{
|
||||
Pair<Long, QName> qnamePair = qnameDAO.getQName(qname);
|
||||
if (qnamePair == null)
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("QName does not exist: " + qname); // possible ... eg. blg:blogPost if a blog has never been posted externally
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return qnamePair.getFirst();
|
||||
}
|
||||
|
||||
protected Long getNodeId(NodeRef nodeRef)
|
||||
{
|
||||
Pair<Long, NodeRef> nodePair = nodeDAO.getNodePair(tenantService.getName(nodeRef));
|
||||
if (nodePair == null)
|
||||
{
|
||||
throw new InvalidNodeRefException("Node ref does not exist: " + nodeRef, nodeRef);
|
||||
}
|
||||
return nodePair.getFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
super.afterPropertiesSet();
|
||||
|
||||
PropertyCheck.mandatory(this, "methodSecurity", methodSecurity);
|
||||
PropertyCheck.mandatory(this, "nodeDAO", nodeDAO);
|
||||
PropertyCheck.mandatory(this, "qnameDAO", qnameDAO);
|
||||
PropertyCheck.mandatory(this, "cannedQueryDAO", cannedQueryDAO);
|
||||
PropertyCheck.mandatory(this, "tenantService", tenantService);
|
||||
return new CannedQuerySortDetails(singlePair);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -18,8 +18,7 @@
|
||||
*/
|
||||
package org.alfresco.repo.blog.cannedqueries;
|
||||
|
||||
import org.alfresco.repo.domain.node.NodeEntity;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.repo.query.NodeBackedEntity;
|
||||
|
||||
/**
|
||||
* Blog Entity - used by GetBlogs CQ
|
||||
@@ -27,14 +26,8 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
* @author janv
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogEntity
|
||||
public class BlogEntity extends NodeBackedEntity
|
||||
{
|
||||
private Long id; // node id
|
||||
|
||||
private NodeEntity node;
|
||||
|
||||
private String name;
|
||||
|
||||
private String publishedDate;
|
||||
private String postedDate;
|
||||
|
||||
@@ -52,10 +45,12 @@ public class BlogEntity
|
||||
*/
|
||||
public BlogEntity()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public BlogEntity(Long parentNodeId, Long nameQNameId, Long publishedQNameId, Long contentTypeQNameId, Long blogIntAspectQNameId, Long blogIntPostedQNameId)
|
||||
{
|
||||
super();
|
||||
this.parentNodeId = parentNodeId;
|
||||
this.nameQNameId = nameQNameId;
|
||||
this.publishedQNameId = publishedQNameId;
|
||||
@@ -65,54 +60,6 @@ public class BlogEntity
|
||||
this.blogIntPostedQNameId = blogIntPostedQNameId;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
// helper
|
||||
public NodeRef getNodeRef()
|
||||
{
|
||||
return (node != null ? node.getNodeRef() : null);
|
||||
}
|
||||
|
||||
// helper (ISO 8061)
|
||||
public String getCreatedDate()
|
||||
{
|
||||
return ((node != null && node.getAuditableProperties() != null) ? node.getAuditableProperties().getAuditCreated() : null);
|
||||
}
|
||||
|
||||
// helper
|
||||
public String getCreator()
|
||||
{
|
||||
return ((node != null && node.getAuditableProperties() != null) ? node.getAuditableProperties().getAuditCreator() : null);
|
||||
}
|
||||
|
||||
public NodeEntity getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
public void setNode(NodeEntity childNode)
|
||||
{
|
||||
this.node = childNode;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// (ISO-8061)
|
||||
public String getPublishedDate()
|
||||
{
|
||||
|
@@ -29,7 +29,6 @@ import org.alfresco.query.CannedQueryPageDetails;
|
||||
import org.alfresco.query.CannedQueryParameters;
|
||||
import org.alfresco.query.CannedQuerySortDetails;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
||||
import org.alfresco.service.cmr.blog.BlogService.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -72,12 +71,12 @@ public class DraftsAndPublishedBlogPostsCannedQueryFactory extends AbstractBlogP
|
||||
|
||||
CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
|
||||
|
||||
List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<Pair<? extends Object, SortOrder>>(2);
|
||||
List<Pair<QName, Boolean>> sortPairs = new ArrayList<Pair<QName, Boolean>>(2);
|
||||
|
||||
// Sort by created then published. We want a list of all published (most recently published first),
|
||||
// followed by all unpublished (most recently created first)
|
||||
sortPairs.add(new Pair<QName, SortOrder>(ContentModel.PROP_CREATED, SortOrder.DESCENDING));
|
||||
sortPairs.add(new Pair<QName, SortOrder>(ContentModel.PROP_PUBLISHED, SortOrder.DESCENDING));
|
||||
sortPairs.add(new Pair<QName, Boolean>(ContentModel.PROP_CREATED, Boolean.FALSE));
|
||||
sortPairs.add(new Pair<QName, Boolean>(ContentModel.PROP_PUBLISHED, Boolean.FALSE));
|
||||
|
||||
CannedQuerySortDetails cqsd = createCQSortDetails(sortPairs);
|
||||
|
||||
|
Reference in New Issue
Block a user