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.BlogIntegrationModel;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.query.AbstractCannedQueryFactory;
|
|
||||||
import org.alfresco.query.CannedQueryPageDetails;
|
|
||||||
import org.alfresco.query.CannedQuerySortDetails;
|
import org.alfresco.query.CannedQuerySortDetails;
|
||||||
import org.alfresco.query.PagingRequest;
|
|
||||||
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
||||||
import org.alfresco.repo.domain.node.NodeDAO;
|
import org.alfresco.repo.query.AbstractQNameAwareCannedQueryFactory;
|
||||||
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.service.cmr.blog.BlogService.BlogPostInfo;
|
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.service.namespace.QName;
|
||||||
import org.alfresco.util.Pair;
|
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
|
* @author Neil Mc Erlean, janv
|
||||||
* @since 4.0
|
* @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)
|
protected CannedQuerySortDetails createCQSortDetails(QName sortProp, SortOrder sortOrder)
|
||||||
{
|
{
|
||||||
List<Pair<? extends Object, SortOrder>> singlePair = new ArrayList<Pair<? extends Object, SortOrder>>(1);
|
List<Pair<? extends Object, SortOrder>> singlePair = new ArrayList<Pair<? extends Object, SortOrder>>(1);
|
||||||
singlePair.add(new Pair<QName, SortOrder>(sortProp, sortOrder));
|
singlePair.add(new Pair<QName, SortOrder>(sortProp, sortOrder));
|
||||||
|
|
||||||
return this.createCQSortDetails(singlePair);
|
return new CannedQuerySortDetails(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -18,8 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.blog.cannedqueries;
|
package org.alfresco.repo.blog.cannedqueries;
|
||||||
|
|
||||||
import org.alfresco.repo.domain.node.NodeEntity;
|
import org.alfresco.repo.query.NodeBackedEntity;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blog Entity - used by GetBlogs CQ
|
* Blog Entity - used by GetBlogs CQ
|
||||||
@@ -27,14 +26,8 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
|||||||
* @author janv
|
* @author janv
|
||||||
* @since 4.0
|
* @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 publishedDate;
|
||||||
private String postedDate;
|
private String postedDate;
|
||||||
|
|
||||||
@@ -52,10 +45,12 @@ public class BlogEntity
|
|||||||
*/
|
*/
|
||||||
public BlogEntity()
|
public BlogEntity()
|
||||||
{
|
{
|
||||||
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlogEntity(Long parentNodeId, Long nameQNameId, Long publishedQNameId, Long contentTypeQNameId, Long blogIntAspectQNameId, Long blogIntPostedQNameId)
|
public BlogEntity(Long parentNodeId, Long nameQNameId, Long publishedQNameId, Long contentTypeQNameId, Long blogIntAspectQNameId, Long blogIntPostedQNameId)
|
||||||
{
|
{
|
||||||
|
super();
|
||||||
this.parentNodeId = parentNodeId;
|
this.parentNodeId = parentNodeId;
|
||||||
this.nameQNameId = nameQNameId;
|
this.nameQNameId = nameQNameId;
|
||||||
this.publishedQNameId = publishedQNameId;
|
this.publishedQNameId = publishedQNameId;
|
||||||
@@ -65,54 +60,6 @@ public class BlogEntity
|
|||||||
this.blogIntPostedQNameId = blogIntPostedQNameId;
|
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)
|
// (ISO-8061)
|
||||||
public String getPublishedDate()
|
public String getPublishedDate()
|
||||||
{
|
{
|
||||||
|
@@ -29,7 +29,6 @@ import org.alfresco.query.CannedQueryPageDetails;
|
|||||||
import org.alfresco.query.CannedQueryParameters;
|
import org.alfresco.query.CannedQueryParameters;
|
||||||
import org.alfresco.query.CannedQuerySortDetails;
|
import org.alfresco.query.CannedQuerySortDetails;
|
||||||
import org.alfresco.query.PagingRequest;
|
import org.alfresco.query.PagingRequest;
|
||||||
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
|
||||||
import org.alfresco.service.cmr.blog.BlogService.BlogPostInfo;
|
import org.alfresco.service.cmr.blog.BlogService.BlogPostInfo;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
@@ -72,12 +71,12 @@ public class DraftsAndPublishedBlogPostsCannedQueryFactory extends AbstractBlogP
|
|||||||
|
|
||||||
CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
|
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),
|
// Sort by created then published. We want a list of all published (most recently published first),
|
||||||
// followed by all unpublished (most recently created 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, Boolean>(ContentModel.PROP_CREATED, Boolean.FALSE));
|
||||||
sortPairs.add(new Pair<QName, SortOrder>(ContentModel.PROP_PUBLISHED, SortOrder.DESCENDING));
|
sortPairs.add(new Pair<QName, Boolean>(ContentModel.PROP_PUBLISHED, Boolean.FALSE));
|
||||||
|
|
||||||
CannedQuerySortDetails cqsd = createCQSortDetails(sortPairs);
|
CannedQuerySortDetails cqsd = createCQSortDetails(sortPairs);
|
||||||
|
|
||||||
|
@@ -18,9 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.calendar.cannedqueries;
|
package org.alfresco.repo.calendar.cannedqueries;
|
||||||
|
|
||||||
import org.alfresco.repo.domain.node.NodeEntity;
|
import org.alfresco.repo.query.NodeBackedEntity;
|
||||||
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calendar Entity - low level representation of parts of a
|
* Calendar Entity - low level representation of parts of a
|
||||||
@@ -29,14 +28,8 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
|||||||
* @author Nick Burch
|
* @author Nick Burch
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public class CalendarEntity
|
public class CalendarEntity extends NodeBackedEntity
|
||||||
{
|
{
|
||||||
private Long id; // node id
|
|
||||||
|
|
||||||
private NodeEntity node;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String fromDate;
|
private String fromDate;
|
||||||
private String toDate;
|
private String toDate;
|
||||||
private String recurrenceRule;
|
private String recurrenceRule;
|
||||||
@@ -56,12 +49,14 @@ public class CalendarEntity
|
|||||||
*/
|
*/
|
||||||
public CalendarEntity()
|
public CalendarEntity()
|
||||||
{
|
{
|
||||||
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalendarEntity(Long parentNodeId, Long nameQNameId, Long contentTypeQNameId,
|
public CalendarEntity(Long parentNodeId, Long nameQNameId, Long contentTypeQNameId,
|
||||||
Long fromDateQNameId, Long toDateQNameId,
|
Long fromDateQNameId, Long toDateQNameId,
|
||||||
Long recurrenceRuleQNameId, Long recurrenceLastMeetingQNameId)
|
Long recurrenceRuleQNameId, Long recurrenceLastMeetingQNameId)
|
||||||
{
|
{
|
||||||
|
super();
|
||||||
this.parentNodeId = parentNodeId;
|
this.parentNodeId = parentNodeId;
|
||||||
this.nameQNameId = nameQNameId;
|
this.nameQNameId = nameQNameId;
|
||||||
this.contentTypeQNameId = contentTypeQNameId;
|
this.contentTypeQNameId = contentTypeQNameId;
|
||||||
@@ -71,54 +66,6 @@ public class CalendarEntity
|
|||||||
this.recurrenceLastMeetingQNameId = recurrenceLastMeetingQNameId;
|
this.recurrenceLastMeetingQNameId = recurrenceLastMeetingQNameId;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
// (ISO-8061)
|
||||||
public String getFromDate()
|
public String getFromDate()
|
||||||
{
|
{
|
||||||
|
@@ -23,7 +23,6 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.query.AbstractCannedQueryFactory;
|
|
||||||
import org.alfresco.query.CannedQuery;
|
import org.alfresco.query.CannedQuery;
|
||||||
import org.alfresco.query.CannedQueryFactory;
|
import org.alfresco.query.CannedQueryFactory;
|
||||||
import org.alfresco.query.CannedQueryPageDetails;
|
import org.alfresco.query.CannedQueryPageDetails;
|
||||||
@@ -32,14 +31,9 @@ import org.alfresco.query.CannedQuerySortDetails;
|
|||||||
import org.alfresco.query.PagingRequest;
|
import org.alfresco.query.PagingRequest;
|
||||||
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
||||||
import org.alfresco.repo.calendar.CalendarModel;
|
import org.alfresco.repo.calendar.CalendarModel;
|
||||||
import org.alfresco.repo.domain.node.NodeDAO;
|
import org.alfresco.repo.query.AbstractQNameAwareCannedQueryFactory;
|
||||||
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.service.cmr.calendar.CalendarEntry;
|
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||||
import org.alfresco.service.cmr.calendar.CalendarService;
|
import org.alfresco.service.cmr.calendar.CalendarService;
|
||||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||||
@@ -47,8 +41,6 @@ import org.alfresco.service.namespace.QName;
|
|||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
import org.alfresco.util.ParameterCheck;
|
import org.alfresco.util.ParameterCheck;
|
||||||
import org.alfresco.util.PropertyCheck;
|
import org.alfresco.util.PropertyCheck;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link CannedQueryFactory} for various queries relating to {@link CalendarEntry calendar entries}.
|
* A {@link CannedQueryFactory} for various queries relating to {@link CalendarEntry calendar entries}.
|
||||||
@@ -60,65 +52,28 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
* @see CalendarService#listCalendarEntries(String[], PagingRequest)
|
* @see CalendarService#listCalendarEntries(String[], PagingRequest)
|
||||||
* @see CalendarService#listCalendarEntries(String[], Date, Date, PagingRequest)
|
* @see CalendarService#listCalendarEntries(String[], Date, Date, PagingRequest)
|
||||||
*/
|
*/
|
||||||
public class GetCalendarEntriesCannedQueryFactory extends AbstractCannedQueryFactory<CalendarEntry>
|
public class GetCalendarEntriesCannedQueryFactory extends AbstractQNameAwareCannedQueryFactory<CalendarEntry>
|
||||||
{
|
{
|
||||||
private Log logger = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
protected MethodSecurityBean<CalendarEntry> methodSecurity;
|
|
||||||
protected NodeDAO nodeDAO;
|
|
||||||
protected QNameDAO qnameDAO;
|
|
||||||
protected NodeService nodeService;
|
protected NodeService nodeService;
|
||||||
protected TenantService tenantService;
|
|
||||||
protected TaggingService taggingService;
|
protected TaggingService taggingService;
|
||||||
protected CannedQueryDAO cannedQueryDAO;
|
|
||||||
|
|
||||||
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 setNodeService(NodeService nodeService)
|
public void setNodeService(NodeService nodeService)
|
||||||
{
|
{
|
||||||
this.nodeService = nodeService;
|
this.nodeService = nodeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTenantService(TenantService tenantService)
|
|
||||||
{
|
|
||||||
this.tenantService = tenantService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaggingService(TaggingService taggingService)
|
public void setTaggingService(TaggingService taggingService)
|
||||||
{
|
{
|
||||||
this.taggingService = taggingService;
|
this.taggingService = taggingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMethodSecurity(MethodSecurityBean<CalendarEntry> methodSecurity)
|
|
||||||
{
|
|
||||||
this.methodSecurity = methodSecurity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception
|
public void afterPropertiesSet() throws Exception
|
||||||
{
|
{
|
||||||
super.afterPropertiesSet();
|
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);
|
|
||||||
PropertyCheck.mandatory(this, "taggingService", taggingService);
|
|
||||||
PropertyCheck.mandatory(this, "nodeService", nodeService);
|
PropertyCheck.mandatory(this, "nodeService", nodeService);
|
||||||
|
PropertyCheck.mandatory(this, "taggingService", taggingService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -175,47 +130,4 @@ public class GetCalendarEntriesCannedQueryFactory extends AbstractCannedQueryFac
|
|||||||
|
|
||||||
return new CannedQuerySortDetails(sort);
|
return new CannedQuerySortDetails(sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.query;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An intermediate {@link AbstractCannedQueryFactory} layer, for various
|
||||||
|
* implementations that need to know about QName IDs and similar
|
||||||
|
*
|
||||||
|
* @author Nick Burch
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public abstract class AbstractQNameAwareCannedQueryFactory<R> extends AbstractCannedQueryFactory<R>
|
||||||
|
{
|
||||||
|
private Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
|
protected MethodSecurityBean<R> methodSecurity;
|
||||||
|
protected NodeDAO nodeDAO;
|
||||||
|
protected QNameDAO qnameDAO;
|
||||||
|
protected TenantService tenantService;
|
||||||
|
protected CannedQueryDAO cannedQueryDAO;
|
||||||
|
|
||||||
|
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<R> methodSecurity)
|
||||||
|
{
|
||||||
|
this.methodSecurity = methodSecurity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Canned Query sort details, for the given list of properties
|
||||||
|
* and if they should be Ascending or Descending
|
||||||
|
*/
|
||||||
|
protected CannedQuerySortDetails createCQSortDetails(List<Pair<QName,Boolean>> sort)
|
||||||
|
{
|
||||||
|
List<Pair<? extends Object,SortOrder>> details = new ArrayList<Pair<? extends Object, SortOrder>>();
|
||||||
|
for(Pair<QName,Boolean> sortProp : sort)
|
||||||
|
{
|
||||||
|
details.add(new Pair<QName, SortOrder>(
|
||||||
|
sortProp.getFirst(),
|
||||||
|
(sortProp.getSecond() ? SortOrder.ASCENDING : SortOrder.DESCENDING)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return new CannedQuerySortDetails(details);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
93
source/java/org/alfresco/repo/query/NodeBackedEntity.java
Normal file
93
source/java/org/alfresco/repo/query/NodeBackedEntity.java
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.query;
|
||||||
|
|
||||||
|
import org.alfresco.repo.domain.node.NodeEntity;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parent class of Canned Query Entities which are a
|
||||||
|
* {@link NodeEntity} with additional properties
|
||||||
|
*
|
||||||
|
* @author Nick Burch
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public abstract class NodeBackedEntity
|
||||||
|
{
|
||||||
|
private Long id; // node id
|
||||||
|
|
||||||
|
private NodeEntity node;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor
|
||||||
|
*/
|
||||||
|
public NodeBackedEntity()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user